diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index b49a6e261d73d..af590d98c301c 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1901,10 +1901,9 @@ impl KeywordIdents { return; } - cx.sess().psess.buffer_lint( + cx.emit_span_lint( lint, ident.span, - CRATE_NODE_ID, BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix }, ); } diff --git a/tests/ui/lint/keyword-idents/multi-file.rs b/tests/ui/lint/keyword-idents/multi-file.rs index 44ff887cdf64d..703e13f9ef6b7 100644 --- a/tests/ui/lint/keyword-idents/multi-file.rs +++ b/tests/ui/lint/keyword-idents/multi-file.rs @@ -1,17 +1,14 @@ -#![deny(keyword_idents)] +#![deny(keyword_idents)] // Should affect the submodule, but doesn't. //@ edition: 2015 +//@ known-bug: #132218 +//@ check-pass (known bug; should be check-fail) + +// Because `keyword_idents_2018` and `keyword_idents_2024` are pre-expansion +// lints, configuring them via lint attributes doesn't propagate to submodules +// in other files. +// #[path = "./auxiliary/multi_file_submod.rs"] mod multi_file_submod; -//~? ERROR `async` is a keyword -//~? WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! -//~? ERROR `await` is a keyword -//~? WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! -//~? ERROR `try` is a keyword -//~? WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! -//~? ERROR `dyn` is a keyword -//~? WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! -//~? ERROR `gen` is a keyword -//~? WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! fn main() {} diff --git a/tests/ui/lint/keyword-idents/multi-file.stderr b/tests/ui/lint/keyword-idents/multi-file.stderr deleted file mode 100644 index 726ee8f28b13f..0000000000000 --- a/tests/ui/lint/keyword-idents/multi-file.stderr +++ /dev/null @@ -1,54 +0,0 @@ -error: `async` is a keyword in the 2018 edition - --> $DIR/./auxiliary/multi_file_submod.rs:4:4 - | -LL | fn async() {} - | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! - = note: for more information, see -note: the lint level is defined here - --> $DIR/multi-file.rs:1:9 - | -LL | #![deny(keyword_idents)] - | ^^^^^^^^^^^^^^ - = note: `#[deny(keyword_idents_2018)]` implied by `#[deny(keyword_idents)]` - -error: `await` is a keyword in the 2018 edition - --> $DIR/./auxiliary/multi_file_submod.rs:5:4 - | -LL | fn await() {} - | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! - = note: for more information, see - -error: `try` is a keyword in the 2018 edition - --> $DIR/./auxiliary/multi_file_submod.rs:6:4 - | -LL | fn try() {} - | ^^^ help: you can use a raw identifier to stay compatible: `r#try` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! - = note: for more information, see - -error: `dyn` is a keyword in the 2018 edition - --> $DIR/./auxiliary/multi_file_submod.rs:7:4 - | -LL | fn dyn() {} - | ^^^ help: you can use a raw identifier to stay compatible: `r#dyn` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! - = note: for more information, see - -error: `gen` is a keyword in the 2024 edition - --> $DIR/./auxiliary/multi_file_submod.rs:10:4 - | -LL | fn gen() {} - | ^^^ help: you can use a raw identifier to stay compatible: `r#gen` - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024! - = note: for more information, see - = note: `#[deny(keyword_idents_2024)]` implied by `#[deny(keyword_idents)]` - -error: aborting due to 5 previous errors - diff --git a/tests/ui/lint/pre-expansion-expect.rs b/tests/ui/lint/pre-expansion-expect.rs new file mode 100644 index 0000000000000..64343d69aa55a --- /dev/null +++ b/tests/ui/lint/pre-expansion-expect.rs @@ -0,0 +1,7 @@ +// Regression test #155008 +//@ edition: 2015 +//@ check-pass +#[expect(keyword_idents_2024)] +fn main() { + let gen = 5; +}