Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/incorrect_case.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/incorrect_case.rs128
1 files changed, 109 insertions, 19 deletions
diff --git a/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
index a0fad7c850..18a95f0963 100644
--- a/crates/ide-diagnostics/src/handlers/incorrect_case.rs
+++ b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
@@ -332,6 +332,7 @@ impl someStruct {
check_diagnostics(
r#"
enum Option { Some, None }
+use Option::{Some, None};
#[allow(unused)]
fn main() {
@@ -345,24 +346,6 @@ fn main() {
}
#[test]
- fn non_let_bind() {
- check_diagnostics(
- r#"
-enum Option { Some, None }
-
-#[allow(unused)]
-fn main() {
- match Option::None {
- SOME_VAR @ None => (),
- // ^^^^^^^^ 💡 warn: Variable `SOME_VAR` should have snake_case name, e.g. `some_var`
- Some => (),
- }
-}
-"#,
- );
- }
-
- #[test]
fn allow_attributes_crate_attr() {
check_diagnostics(
r#"
@@ -427,7 +410,12 @@ fn qualify() {
#[test] // Issue #8809.
fn parenthesized_parameter() {
- check_diagnostics(r#"fn f((O): _) { _ = O; }"#)
+ check_diagnostics(
+ r#"
+fn f((_O): u8) {}
+ // ^^ 💡 warn: Variable `_O` should have snake_case name, e.g. `_o`
+"#,
+ )
}
#[test]
@@ -766,4 +754,106 @@ mod Foo;
"#,
)
}
+
+ #[test]
+ fn test_field_shorthand() {
+ check_diagnostics(
+ r#"
+struct Foo { _nonSnake: u8 }
+ // ^^^^^^^^^ 💡 warn: Field `_nonSnake` should have snake_case name, e.g. `_non_snake`
+fn func(Foo { _nonSnake }: Foo) {}
+"#,
+ );
+ }
+
+ #[test]
+ fn test_match() {
+ check_diagnostics(
+ r#"
+enum Foo { Variant { nonSnake1: u8 } }
+ // ^^^^^^^^^ 💡 warn: Field `nonSnake1` should have snake_case name, e.g. `non_snake1`
+fn func() {
+ match (Foo::Variant { nonSnake1: 1 }) {
+ Foo::Variant { nonSnake1: _nonSnake2 } => {},
+ // ^^^^^^^^^^ 💡 warn: Variable `_nonSnake2` should have snake_case name, e.g. `_non_snake2`
+ }
+}
+"#,
+ );
+
+ check_diagnostics(
+ r#"
+struct Foo(u8);
+
+fn func() {
+ match Foo(1) {
+ Foo(_nonSnake) => {},
+ // ^^^^^^^^^ 💡 warn: Variable `_nonSnake` should have snake_case name, e.g. `_non_snake`
+ }
+}
+"#,
+ );
+
+ check_diagnostics(
+ r#"
+fn main() {
+ match 1 {
+ _Bad1 @ _Bad2 => {}
+ // ^^^^^ 💡 warn: Variable `_Bad1` should have snake_case name, e.g. `_bad1`
+ // ^^^^^ 💡 warn: Variable `_Bad2` should have snake_case name, e.g. `_bad2`
+ }
+}
+"#,
+ );
+ check_diagnostics(
+ r#"
+fn main() {
+ match 1 { _Bad1 => () }
+ // ^^^^^ 💡 warn: Variable `_Bad1` should have snake_case name, e.g. `_bad1`
+}
+"#,
+ );
+
+ check_diagnostics(
+ r#"
+enum Foo { V1, V2 }
+use Foo::V1;
+
+fn main() {
+ match V1 {
+ _Bad1 @ V1 => {},
+ // ^^^^^ 💡 warn: Variable `_Bad1` should have snake_case name, e.g. `_bad1`
+ Foo::V2 => {}
+ }
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn test_for_loop() {
+ check_diagnostics(
+ r#"
+//- minicore: iterators
+fn func() {
+ for _nonSnake in [] {}
+ // ^^^^^^^^^ 💡 warn: Variable `_nonSnake` should have snake_case name, e.g. `_non_snake`
+}
+"#,
+ );
+
+ check_fix(
+ r#"
+//- minicore: iterators
+fn func() {
+ for nonSnake$0 in [] { nonSnake; }
+}
+"#,
+ r#"
+fn func() {
+ for non_snake in [] { non_snake; }
+}
+"#,
+ );
+ }
}