1
Fork 0

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.
This commit is contained in:
Camille GILLOT 2021-11-21 16:16:02 +01:00
parent 7b3cd075bb
commit ae126ad282
3 changed files with 40 additions and 0 deletions

View file

@ -40,6 +40,11 @@ impl ItemLowerer<'_, '_, '_> {
}
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
fn visit_attribute(&mut self, _: &'a Attribute) {
// We do not want to lower expressions that appear in attributes,
// as they are not accessible to the rest of the HIR.
}
fn visit_item(&mut self, item: &'a Item) {
let hir_id = self.lctx.with_hir_id_owner(item.id, |lctx| {
let node = lctx.without_in_scope_lifetime_defs(|lctx| lctx.lower_item(item));