mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
don't parse attributes in pre-expansion lints
also buffer any lints coming from pre-expansion, so that they are emitted with proper lint level
This commit is contained in:
committed by
Jonathan Brouwer
parent
bd864efa70
commit
bcebd2c909
@@ -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<Item>],
|
||||
name: Symbol,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -119,11 +119,10 @@ fn pre_expansion_lint(
|
||||
features: &Features,
|
||||
registered_tools: &RegisteredTools,
|
||||
node_id: ast::NodeId,
|
||||
attrs: &[ast::Attribute],
|
||||
items: &[Box<ast::Item>],
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<ast::Item>]) {
|
||||
impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [Box<ast::Item>]) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
// <https://github.com/rust-lang/rust/issues/132218>
|
||||
|
||||
#[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() {}
|
||||
|
||||
@@ -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 <https://doc.rust-lang.org/edition-guide/rust-2018/new-keywords.html>
|
||||
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 <https://doc.rust-lang.org/edition-guide/rust-2018/new-keywords.html>
|
||||
|
||||
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 <https://doc.rust-lang.org/edition-guide/rust-2018/new-keywords.html>
|
||||
|
||||
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 <https://doc.rust-lang.org/edition-guide/rust-2018/new-keywords.html>
|
||||
|
||||
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 <https://doc.rust-lang.org/edition-guide/rust-2024/gen-keyword.html>
|
||||
= note: `#[deny(keyword_idents_2024)]` implied by `#[deny(keyword_idents)]`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Reference in New Issue
Block a user