1
Fork 0

Rollup merge of #91111 - cjgillot:hir-no-lower-attrs, r=michaelwoerister

Do not visit attributes in `ItemLowerer`.

By default, AST visitors visit expressions that appear in key-value attributes.
Those expressions should not be lowered to HIR, as they do not correspond to actually compiled code.

Since an attribute cannot produce meaningful HIR, just skip them altogether.

Fixes https://github.com/rust-lang/rust/issues/81886
Fixes https://github.com/rust-lang/rust/issues/90873
r? `@michaelwoerister`
This commit is contained in:
Matthias Krüger 2021-11-25 15:05:38 +01:00 committed by GitHub
commit 5f6cb2c552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 19 deletions

View file

@ -431,6 +431,10 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
fn visit_attribute(&mut self, _: &'ast Attribute) {
// We do not want to resolve expressions that appear in attributes,
// as they do not correspond to actual code.
}
fn visit_item(&mut self, item: &'ast Item) {
let prev = replace(&mut self.diagnostic_metadata.current_item, Some(item));
// Always report errors in items we just entered.