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:
parent
7b3cd075bb
commit
ae126ad282
3 changed files with 40 additions and 0 deletions
|
@ -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));
|
||||
|
|
5
src/test/ui/attributes/issue-90873.rs
Normal file
5
src/test/ui/attributes/issue-90873.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#![u=||{static d=||1;}]
|
||||
//~^ unexpected token
|
||||
//~| cannot find attribute `u` in this scope
|
||||
//~| `main` function not found in crate `issue_90873`
|
||||
//~| missing type for `static` item
|
30
src/test/ui/attributes/issue-90873.stderr
Normal file
30
src/test/ui/attributes/issue-90873.stderr
Normal file
|
@ -0,0 +1,30 @@
|
|||
error: unexpected token: `||
|
||||
{
|
||||
static d: _ = || 1;
|
||||
}`
|
||||
--> $DIR/issue-90873.rs:1:6
|
||||
|
|
||||
LL | #![u=||{static d=||1;}]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: cannot find attribute `u` in this scope
|
||||
--> $DIR/issue-90873.rs:1:4
|
||||
|
|
||||
LL | #![u=||{static d=||1;}]
|
||||
| ^
|
||||
|
||||
error[E0601]: `main` function not found in crate `issue_90873`
|
||||
--> $DIR/issue-90873.rs:1:1
|
||||
|
|
||||
LL | #![u=||{static d=||1;}]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `$DIR/issue-90873.rs`
|
||||
|
||||
error: missing type for `static` item
|
||||
--> $DIR/issue-90873.rs:1:16
|
||||
|
|
||||
LL | #![u=||{static d=||1;}]
|
||||
| ^ help: provide a type for the item: `d: <type>`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0601`.
|
Loading…
Add table
Add a link
Reference in a new issue