Skip to content

Commit 7f5d3ff

Browse files
committed
Do not visit attributes in LateResolutionVisitor.
1 parent ae126ad commit 7f5d3ff

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

compiler/rustc_resolve/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
431431

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

src/test/ui/attributes/issue-90873.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
//~| cannot find attribute `u` in this scope
44
//~| `main` function not found in crate `issue_90873`
55
//~| missing type for `static` item
6+
7+
#![a={impl std::ops::Neg for i8 {}}]
8+
//~^ ERROR unexpected token
9+
//~| ERROR cannot find attribute `a` in this scope

src/test/ui/attributes/issue-90873.stderr

+23-3
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,44 @@ error: unexpected token: `||
77
LL | #![u=||{static d=||1;}]
88
| ^^^^^^^^^^^^^^^^^
99

10+
error: unexpected token: `{
11+
impl std::ops::Neg for i8 { }
12+
}`
13+
--> $DIR/issue-90873.rs:7:6
14+
|
15+
LL | #![a={impl std::ops::Neg for i8 {}}]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
1018
error: cannot find attribute `u` in this scope
1119
--> $DIR/issue-90873.rs:1:4
1220
|
1321
LL | #![u=||{static d=||1;}]
1422
| ^
1523

24+
error: cannot find attribute `a` in this scope
25+
--> $DIR/issue-90873.rs:7:4
26+
|
27+
LL | #![a={impl std::ops::Neg for i8 {}}]
28+
| ^
29+
1630
error[E0601]: `main` function not found in crate `issue_90873`
1731
--> $DIR/issue-90873.rs:1:1
1832
|
19-
LL | #![u=||{static d=||1;}]
20-
| ^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `$DIR/issue-90873.rs`
33+
LL | / #![u=||{static d=||1;}]
34+
LL | |
35+
LL | |
36+
LL | |
37+
LL | |
38+
LL | |
39+
LL | | #![a={impl std::ops::Neg for i8 {}}]
40+
| |____________________________________^ consider adding a `main` function to `$DIR/issue-90873.rs`
2141

2242
error: missing type for `static` item
2343
--> $DIR/issue-90873.rs:1:16
2444
|
2545
LL | #![u=||{static d=||1;}]
2646
| ^ help: provide a type for the item: `d: <type>`
2747

28-
error: aborting due to 4 previous errors
48+
error: aborting due to 6 previous errors
2949

3050
For more information about this error, try `rustc --explain E0601`.

src/test/ui/consts/issue-90878-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![l=|x|[b;x ]] //~ ERROR unexpected token: `|x| [b; x]`
22
//~^ ERROR cannot find attribute `l` in this scope
3-
//~^^ ERROR attempt to use a non-constant value in a constant [E0435]
4-
//~^^^ ERROR cannot find value `b` in this scope [E0425]
53

64
// notice the space at the start,
75
// we can't attach any attributes to this file because it needs to be at the start

src/test/ui/consts/issue-90878-2.stderr

+1-17
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,5 @@ error: cannot find attribute `l` in this scope
1010
LL | #![l=|x|[b;x ]]
1111
| ^
1212

13-
error[E0435]: attempt to use a non-constant value in a constant
14-
--> $DIR/issue-90878-2.rs:1:13
15-
|
16-
LL | #![l=|x|[b;x ]]
17-
| - ^
18-
| |
19-
| this would need to be a `const`
20-
21-
error[E0425]: cannot find value `b` in this scope
22-
--> $DIR/issue-90878-2.rs:1:11
23-
|
24-
LL | #![l=|x|[b;x ]]
25-
| ^ help: a local variable with a similar name exists: `x`
26-
27-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
2814

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

0 commit comments

Comments
 (0)