Skip to content

Commit

Permalink
Do not visit attributes in LateResolutionVisitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Nov 24, 2021
1 parent ae126ad commit 7f5d3ff
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/attributes/issue-90873.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
//~| cannot find attribute `u` in this scope
//~| `main` function not found in crate `issue_90873`
//~| missing type for `static` item

#![a={impl std::ops::Neg for i8 {}}]
//~^ ERROR unexpected token
//~| ERROR cannot find attribute `a` in this scope
26 changes: 23 additions & 3 deletions src/test/ui/attributes/issue-90873.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@ error: unexpected token: `||
LL | #![u=||{static d=||1;}]
| ^^^^^^^^^^^^^^^^^

error: unexpected token: `{
impl std::ops::Neg for i8 { }
}`
--> $DIR/issue-90873.rs:7:6
|
LL | #![a={impl std::ops::Neg for i8 {}}]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: cannot find attribute `u` in this scope
--> $DIR/issue-90873.rs:1:4
|
LL | #![u=||{static d=||1;}]
| ^

error: cannot find attribute `a` in this scope
--> $DIR/issue-90873.rs:7:4
|
LL | #![a={impl std::ops::Neg for i8 {}}]
| ^

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`
LL | / #![u=||{static d=||1;}]
LL | |
LL | |
LL | |
LL | |
LL | |
LL | | #![a={impl std::ops::Neg for i8 {}}]
| |____________________________________^ 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
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0601`.
2 changes: 0 additions & 2 deletions src/test/ui/consts/issue-90878-2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![l=|x|[b;x ]] //~ ERROR unexpected token: `|x| [b; x]`
//~^ ERROR cannot find attribute `l` in this scope
//~^^ ERROR attempt to use a non-constant value in a constant [E0435]
//~^^^ ERROR cannot find value `b` in this scope [E0425]

// notice the space at the start,
// we can't attach any attributes to this file because it needs to be at the start
Expand Down
18 changes: 1 addition & 17 deletions src/test/ui/consts/issue-90878-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,5 @@ error: cannot find attribute `l` in this scope
LL | #![l=|x|[b;x ]]
| ^

error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-90878-2.rs:1:13
|
LL | #![l=|x|[b;x ]]
| - ^
| |
| this would need to be a `const`

error[E0425]: cannot find value `b` in this scope
--> $DIR/issue-90878-2.rs:1:11
|
LL | #![l=|x|[b;x ]]
| ^ help: a local variable with a similar name exists: `x`

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0425, E0435.
For more information about an error, try `rustc --explain E0425`.

0 comments on commit 7f5d3ff

Please sign in to comment.