diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a92ed9cd3ae8..cbec647bdc95 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1281,6 +1281,11 @@ pub(crate) fn add_scope_set_candidates( suggestions.extend( BUILTIN_ATTRIBUTES .iter() + // These trace attributes are compiler-generated and have + // deliberately invalid names. + .filter(|attr| { + !matches!(attr.name, sym::cfg_trace | sym::cfg_attr_trace) + }) .map(|attr| TypoSuggestion::typo_from_name(attr.name, res)), ); } diff --git a/tests/ui/suggestions/attribute-typos.rs b/tests/ui/suggestions/attribute-typos.rs index 4c2336e105e2..6dbfb1df5876 100644 --- a/tests/ui/suggestions/attribute-typos.rs +++ b/tests/ui/suggestions/attribute-typos.rs @@ -8,4 +8,11 @@ fn bar() {} //~^ ERROR cannot find attribute `rustc_dumm` in this scope //~| ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler +// Regression test for https://github.com/rust-lang/rust/issues/150566. +#[cfg_trace] //~ ERROR cannot find attribute `cfg_trace` in this scope +fn cfg_trace_attr() {} + +#[cfg_attr_trace] //~ ERROR cannot find attribute `cfg_attr_trace` in this scope +fn cfg_attr_trace_attr() {} + fn main() {} diff --git a/tests/ui/suggestions/attribute-typos.stderr b/tests/ui/suggestions/attribute-typos.stderr index 960e0b0f620f..7ca425fa9bd6 100644 --- a/tests/ui/suggestions/attribute-typos.stderr +++ b/tests/ui/suggestions/attribute-typos.stderr @@ -4,6 +4,12 @@ error: attributes starting with `rustc` are reserved for use by the `rustc` comp LL | #[rustc_dumm] | ^^^^^^^^^^ +error: cannot find attribute `cfg_attr_trace` in this scope + --> $DIR/attribute-typos.rs:15:3 + | +LL | #[cfg_attr_trace] + | ^^^^^^^^^^^^^^ + error: cannot find attribute `rustc_dumm` in this scope --> $DIR/attribute-typos.rs:7:3 | @@ -15,6 +21,12 @@ help: a built-in attribute with a similar name exists LL | #[rustc_dummy] | + +error: cannot find attribute `cfg_trace` in this scope + --> $DIR/attribute-typos.rs:12:3 + | +LL | #[cfg_trace] + | ^^^^^^^^^ + error: cannot find attribute `tests` in this scope --> $DIR/attribute-typos.rs:4:3 | @@ -41,5 +53,5 @@ help: a built-in attribute with a similar name exists LL | #[deprecated] | + -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors