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.rs72
1 files changed, 67 insertions, 5 deletions
diff --git a/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
index 235062bf53..85dbb7e6f2 100644
--- a/crates/ide-diagnostics/src/handlers/incorrect_case.rs
+++ b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
@@ -113,6 +113,31 @@ fn some_fn() {
}
"#,
);
+
+ check_fix(
+ r#"
+static S: i32 = M::A;
+
+mod $0M {
+ pub const A: i32 = 10;
+}
+
+mod other {
+ use crate::M::A;
+}
+"#,
+ r#"
+static S: i32 = m::A;
+
+mod m {
+ pub const A: i32 = 10;
+}
+
+mod other {
+ use crate::m::A;
+}
+"#,
+ );
}
#[test]
@@ -175,10 +200,10 @@ fn NonSnakeCaseName() {}
fn incorrect_function_params() {
check_diagnostics(
r#"
-fn foo(SomeParam: u8) {}
+fn foo(SomeParam: u8) { _ = SomeParam; }
// ^^^^^^^^^ 💡 warn: Parameter `SomeParam` should have snake_case name, e.g. `some_param`
-fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
+fn foo2(ok_param: &str, CAPS_PARAM: u8) { _ = (ok_param, CAPS_PARAM); }
// ^^^^^^^^^^ 💡 warn: Parameter `CAPS_PARAM` should have snake_case name, e.g. `caps_param`
"#,
);
@@ -188,6 +213,7 @@ fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
fn incorrect_variable_names() {
check_diagnostics(
r#"
+#[allow(unused)]
fn foo() {
let SOME_VALUE = 10;
// ^^^^^^^^^^ 💡 warn: Variable `SOME_VALUE` should have snake_case name, e.g. `some_value`
@@ -294,6 +320,7 @@ impl someStruct {
// ^^^^^^^^ 💡 warn: Function `SomeFunc` should have snake_case name, e.g. `some_func`
let WHY_VAR_IS_CAPS = 10;
// ^^^^^^^^^^^^^^^ 💡 warn: Variable `WHY_VAR_IS_CAPS` should have snake_case name, e.g. `why_var_is_caps`
+ _ = WHY_VAR_IS_CAPS;
}
}
"#,
@@ -306,6 +333,7 @@ impl someStruct {
r#"
enum Option { Some, None }
+#[allow(unused)]
fn main() {
match Option::None {
None => (),
@@ -322,6 +350,7 @@ fn main() {
r#"
enum Option { Some, None }
+#[allow(unused)]
fn main() {
match Option::None {
SOME_VAR @ None => (),
@@ -349,7 +378,9 @@ enum E {
}
mod F {
- fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {}
+ fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {
+ _ = BAD_NAME_HI;
+ }
}
"#,
);
@@ -395,7 +426,7 @@ fn qualify() {
#[test] // Issue #8809.
fn parenthesized_parameter() {
- check_diagnostics(r#"fn f((O): _) {}"#)
+ check_diagnostics(r#"fn f((O): _) { _ = O; }"#)
}
#[test]
@@ -472,7 +503,9 @@ mod CheckBadStyle {
mod F {
#![allow(non_snake_case)]
- fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {}
+ fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {
+ _ = BAD_NAME_HI;
+ }
}
#[allow(non_snake_case, non_camel_case_types)]
@@ -510,17 +543,20 @@ fn NonSnakeCaseName(some_var: u8) -> u8 {
#[deny(nonstandard_style)]
mod CheckNonstandardStyle {
+ //^^^^^^^^^^^^^^^^^^^^^ 💡 error: Module `CheckNonstandardStyle` should have snake_case name, e.g. `check_nonstandard_style`
fn HiImABadFnName() {}
//^^^^^^^^^^^^^^ 💡 error: Function `HiImABadFnName` should have snake_case name, e.g. `hi_im_abad_fn_name`
}
#[deny(warnings)]
mod CheckBadStyle {
+ //^^^^^^^^^^^^^ 💡 error: Module `CheckBadStyle` should have snake_case name, e.g. `check_bad_style`
struct fooo;
//^^^^ 💡 error: Structure `fooo` should have CamelCase name, e.g. `Fooo`
}
mod F {
+ //^ 💡 warn: Module `F` should have snake_case name, e.g. `f`
#![deny(non_snake_case)]
fn CheckItWorksWithModAttr() {}
//^^^^^^^^^^^^^^^^^^^^^^^ 💡 error: Function `CheckItWorksWithModAttr` should have snake_case name, e.g. `check_it_works_with_mod_attr`
@@ -641,4 +677,30 @@ enum E {
"#,
);
}
+
+ #[test]
+ fn module_name_inline() {
+ check_diagnostics(
+ r#"
+mod M {
+ //^ 💡 warn: Module `M` should have snake_case name, e.g. `m`
+ mod IncorrectCase {}
+ //^^^^^^^^^^^^^ 💡 warn: Module `IncorrectCase` should have snake_case name, e.g. `incorrect_case`
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn module_name_decl() {
+ check_diagnostics(
+ r#"
+//- /Foo.rs
+
+//- /main.rs
+mod Foo;
+ //^^^ 💡 warn: Module `Foo` should have snake_case name, e.g. `foo`
+"#,
+ )
+ }
}