mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
incorrect case diagnostics for trait assoc functions and consts
This commit is contained in:
parent
5fe3b75677
commit
6d2d6323ac
@ -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) => {
|
||||
|
@ -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`
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,16 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
|
||||
check_diagnostics_with_config(config, ra_fixture)
|
||||
}
|
||||
|
||||
#[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);
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user