Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/lib.rs11
-rw-r--r--crates/ide-diagnostics/src/handlers/incorrect_case.rs11
-rw-r--r--crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs5
-rw-r--r--crates/ide-diagnostics/src/tests.rs11
4 files changed, 32 insertions, 6 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 1e21045e98..a741da78d9 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -563,6 +563,17 @@ impl Module {
for diag in db.trait_data_with_diagnostics(t.id).1.iter() {
emit_def_diagnostic(db, acc, diag);
}
+
+ for item in t.items(db) {
+ let def: DefWithBody = match item {
+ AssocItem::Function(it) => it.into(),
+ AssocItem::Const(it) => it.into(),
+ AssocItem::TypeAlias(_) => continue,
+ };
+
+ def.diagnostics(db, acc);
+ }
+
acc.extend(def.diagnostics(db))
}
ModuleDef::Adt(adt) => {
diff --git a/crates/ide-diagnostics/src/handlers/incorrect_case.rs b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
index 02f93ca9b8..8b247c4558 100644
--- a/crates/ide-diagnostics/src/handlers/incorrect_case.rs
+++ b/crates/ide-diagnostics/src/handlers/incorrect_case.rs
@@ -388,14 +388,13 @@ mod F {
#[test]
fn complex_ignore() {
- // FIXME: this should trigger errors for the second case.
check_diagnostics(
r#"
trait T { fn a(); }
struct U {}
impl T for U {
fn a() {
- #[allow(non_snake_case)]
+ #[allow(non_snake_case, non_upper_case_globals)]
trait __BitFlagsOk {
const HiImAlsoBad: u8 = 2;
fn Dirty(&self) -> bool { false }
@@ -403,7 +402,9 @@ impl T for U {
trait __BitFlagsBad {
const HiImAlsoBad: u8 = 2;
+ // ^^^^^^^^^^^ 💡 warn: Constant `HiImAlsoBad` should have UPPER_SNAKE_CASE name, e.g. `HI_IM_ALSO_BAD`
fn Dirty(&self) -> bool { false }
+ // ^^^^^💡 warn: Function `Dirty` should have snake_case name, e.g. `dirty`
}
}
}
@@ -463,14 +464,16 @@ extern {
#[test]
fn incorrect_trait_and_assoc_item_names() {
- // FIXME: Traits and functions in traits aren't currently checked by
- // r-a, even though rustc will complain about them.
check_diagnostics(
r#"
trait BAD_TRAIT {
// ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait`
+ const bad_const: u8;
+ // ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST`
fn BAD_FUNCTION();
+ // ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
fn BadFunction();
+ // ^^^^^^^^^^^ 💡 warn: Function `BadFunction` should have snake_case name, e.g. `bad_function`
}
"#,
);
diff --git a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
index 66ebf59350..9e9822818e 100644
--- a/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
+++ b/crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
@@ -103,7 +103,7 @@ fn invalid_args_range(
#[cfg(test)]
mod tests {
- use crate::tests::check_diagnostics;
+ use crate::tests::{check_diagnostics, check_diagnostics_with_disabled};
#[test]
fn simple_free_fn_zero() {
@@ -197,7 +197,7 @@ fn f() {
fn method_unknown_receiver() {
// note: this is incorrect code, so there might be errors on this in the
// future, but we shouldn't emit an argument count diagnostic here
- check_diagnostics(
+ check_diagnostics_with_disabled(
r#"
trait Foo { fn method(&self, arg: usize) {} }
@@ -206,6 +206,7 @@ fn f() {
x.method();
}
"#,
+ std::iter::once("unused_variables".to_string()),
);
}
diff --git a/crates/ide-diagnostics/src/tests.rs b/crates/ide-diagnostics/src/tests.rs
index f394a491b5..610d047cd6 100644
--- a/crates/ide-diagnostics/src/tests.rs
+++ b/crates/ide-diagnostics/src/tests.rs
@@ -90,6 +90,16 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
}
#[track_caller]
+pub(crate) fn check_diagnostics_with_disabled(
+ ra_fixture: &str,
+ disabled: impl Iterator<Item = String>,
+) {
+ let mut config = DiagnosticsConfig::test_sample();
+ config.disabled.extend(disabled);
+ check_diagnostics_with_config(config, ra_fixture)
+}
+
+#[track_caller]
pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixture: &str) {
let (db, files) = RootDatabase::with_many_files(ra_fixture);
let mut annotations = files
@@ -175,6 +185,7 @@ fn minicore_smoke_test() {
let mut config = DiagnosticsConfig::test_sample();
// This should be ignored since we conditionally remove code which creates single item use with braces
config.disabled.insert("unused_braces".to_string());
+ config.disabled.insert("unused_variables".to_string());
check_diagnostics_with_config(config, &source);
}