diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 7fd891395fa0..4f60ba2e9725 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -9,7 +9,7 @@ use rustc_ast::attr::MarkedAttrs; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; -use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind, Safety}; +use rustc_ast::{self as ast, AttrVec, HasAttrs, Item, NodeId, PatKind, Safety}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::sync; use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed, PResult}; @@ -1188,7 +1188,6 @@ fn pre_expansion_lint( features: &Features, registered_tools: &RegisteredTools, node_id: NodeId, - attrs: &[Attribute], items: &[Box], name: Symbol, ); diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 9e7d43bdb484..e3a15f193e58 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1403,7 +1403,6 @@ fn wrap_flat_map_node_walk_flat_map( ecx.ecfg.features, ecx.resolver.registered_tools(), ecx.current_expansion.lint_node_id, - &attrs, &items, ident.name, ); diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index d7d4f00578d1..7ba7fd58081a 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -119,11 +119,10 @@ fn pre_expansion_lint( features: &Features, registered_tools: &RegisteredTools, node_id: ast::NodeId, - attrs: &[ast::Attribute], items: &[Box], name: Symbol, ) { - pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, attrs, items), name); + pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, items), name); } } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index af590d98c301..b49a6e261d73 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1901,9 +1901,10 @@ fn check_ident_token( return; } - cx.emit_span_lint( + cx.sess().psess.buffer_lint( lint, ident.span, + CRATE_NODE_ID, BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix }, ); } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index ee0979ec8542..7d9c2e8327b9 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -379,16 +379,15 @@ fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, } } -impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box]) { +impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [Box]) { fn id(self) -> ast::NodeId { self.0 } fn attrs(self) -> &'a [ast::Attribute] { - self.1 + &[] } fn check<'ecx, 'tcx, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'ecx, 'tcx, T>) { - walk_list!(cx, visit_attribute, self.1); - walk_list!(cx, visit_item, self.2); + walk_list!(cx, visit_item, self.1); } } diff --git a/tests/ui/lint/keyword-idents/multi-file.rs b/tests/ui/lint/keyword-idents/multi-file.rs index 703e13f9ef6b..44ff887cdf64 100644 --- a/tests/ui/lint/keyword-idents/multi-file.rs +++ b/tests/ui/lint/keyword-idents/multi-file.rs @@ -1,14 +1,17 @@ -#![deny(keyword_idents)] // Should affect the submodule, but doesn't. +#![deny(keyword_idents)] //@ 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 new file mode 100644 index 000000000000..726ee8f28b13 --- /dev/null +++ b/tests/ui/lint/keyword-idents/multi-file.stderr @@ -0,0 +1,54 @@ +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 +