Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
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)),
);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/suggestions/attribute-typos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
14 changes: 13 additions & 1 deletion tests/ui/suggestions/attribute-typos.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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
|
Expand All @@ -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

Loading