Skip to content

Commit 9beb5c3

Browse files
committed
Add checks for expected macro output in restricted shadowing tests
1 parent ae2e5aa commit 9beb5c3

File tree

5 files changed

+134
-116
lines changed

5 files changed

+134
-116
lines changed

src/librustc_resolve/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ impl<'a> NameBinding<'a> {
12741274
// expansion round `max(invoc_id, binding)` when they both emerged from macros.
12751275
// Then this function returns `true` if `self` may emerge from a macro *after* that
12761276
// in some later round and screw up our previously found resolution.
1277+
// See more detailed explanation in
1278+
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
12771279
fn may_appear_after(&self, invoc_id: Mark, binding: &NameBinding) -> bool {
12781280
// self > max(invoc_id, binding) => !(self <= invoc_id || self <= binding)
12791281
// Expansions are partially ordered, so "may appear after" is an inversion of

src/test/ui/macros/restricted-shadowing-legacy.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// Legend:
2+
// `N` - number of combination, from 0 to 4*4*4=64
3+
// `Outer < Invoc` means that expansion that produced macro definition `Outer`
4+
// is a strict ancestor of expansion that produced macro definition `Inner`.
5+
// `>`, `=` and `Unordered` mean "strict descendant", "same" and
6+
// "not in ordering relation" for parent expansions.
27
// `+` - possible configuration
38
// `-` - configuration impossible due to properties of partial ordering
49
// `-?` - configuration impossible due to block/scope syntax
@@ -72,12 +77,15 @@
7277

7378
#![feature(decl_macro, rustc_attrs)]
7479

80+
struct Right;
81+
// struct Wrong; // not defined
82+
7583
macro_rules! include { () => {
7684
macro_rules! gen_outer { () => {
77-
macro_rules! m { () => {} }
85+
macro_rules! m { () => { Wrong } }
7886
}}
7987
macro_rules! gen_inner { () => {
80-
macro_rules! m { () => {} }
88+
macro_rules! m { () => { Right } }
8189
}}
8290
macro_rules! gen_invoc { () => {
8391
m!()
@@ -96,29 +104,29 @@ macro_rules! include { () => {
96104
}
97105

98106
fn check5() {
99-
macro_rules! m { () => {} }
107+
macro_rules! m { () => { Wrong } }
100108

101109
macro_rules! gen_inner_invoc { () => {
102-
macro_rules! m { () => {} }
110+
macro_rules! m { () => { Right } }
103111
m!(); // OK
104112
}}
105113
gen_inner_invoc!();
106114
}
107115

108116
fn check9() {
109-
macro_rules! m { () => {} }
117+
macro_rules! m { () => { Wrong } }
110118

111119
macro_rules! gen_inner_gen_invoc { () => {
112-
macro_rules! m { () => {} }
120+
macro_rules! m { () => { Right } }
113121
gen_invoc!(); // OK
114122
}}
115123
gen_inner_gen_invoc!();
116124
}
117125

118126
fn check10() {
119-
macro_rules! m { () => {} }
127+
macro_rules! m { () => { Wrong } }
120128

121-
macro_rules! m { () => {} }
129+
macro_rules! m { () => { Right } }
122130

123131
gen_invoc!(); // OK
124132
}
@@ -141,9 +149,9 @@ macro_rules! include { () => {
141149
}
142150

143151
fn check22() {
144-
macro_rules! m { () => {} }
152+
macro_rules! m { () => { Wrong } }
145153

146-
macro_rules! m { () => {} }
154+
macro_rules! m { () => { Right } }
147155

148156
m!(); // OK
149157
}
@@ -159,7 +167,7 @@ macro_rules! include { () => {
159167
fn check39() {
160168
gen_outer!();
161169

162-
macro_rules! m { () => {} }
170+
macro_rules! m { () => { Right } }
163171

164172
m!(); // OK
165173
}
@@ -178,7 +186,7 @@ macro_rules! include { () => {
178186
gen_outer!();
179187

180188
macro_rules! gen_inner_invoc { () => {
181-
macro_rules! m { () => {} }
189+
macro_rules! m { () => { Right } }
182190
m!(); // OK
183191
}}
184192
gen_inner_invoc!();
@@ -187,7 +195,7 @@ macro_rules! include { () => {
187195
fn check59() {
188196
gen_outer!();
189197

190-
macro_rules! m { () => {} }
198+
macro_rules! m { () => { Right } }
191199

192200
gen_invoc!(); // OK
193201
}
@@ -196,7 +204,7 @@ macro_rules! include { () => {
196204
gen_outer!();
197205

198206
macro_rules! gen_inner_gen_invoc { () => {
199-
macro_rules! m { () => {} }
207+
macro_rules! m { () => { Right } }
200208
gen_invoc!(); // OK
201209
}}
202210
gen_inner_gen_invoc!();
@@ -226,8 +234,8 @@ macro_rules! include { () => {
226234

227235
fn check34() {
228236
macro_rules! gen_outer_inner { () => {
229-
macro_rules! m { () => {} }
230-
macro_rules! m { () => {} }
237+
macro_rules! m { () => { Wrong } }
238+
macro_rules! m { () => { Right } }
231239
}}
232240
gen_outer_inner!();
233241

@@ -237,7 +245,7 @@ macro_rules! include { () => {
237245
fn check35() {
238246
macro_rules! gen_gen_outer_inner { () => {
239247
gen_outer!();
240-
macro_rules! m { () => {} }
248+
macro_rules! m { () => { Right } }
241249
}}
242250
gen_gen_outer_inner!();
243251

@@ -257,8 +265,8 @@ macro_rules! include { () => {
257265

258266
fn check62() {
259267
macro_rules! gen_outer_inner { () => {
260-
macro_rules! m { () => {} }
261-
macro_rules! m { () => {} }
268+
macro_rules! m { () => { Wrong } }
269+
macro_rules! m { () => { Right } }
262270
}}
263271
gen_outer_inner!();
264272

@@ -268,7 +276,7 @@ macro_rules! include { () => {
268276
fn check63() {
269277
macro_rules! gen_gen_outer_inner { () => {
270278
gen_outer!();
271-
macro_rules! m { () => {} }
279+
macro_rules! m { () => { Right } }
272280
}}
273281
gen_gen_outer_inner!();
274282

src/test/ui/macros/restricted-shadowing-legacy.stderr

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error[E0659]: `m` is ambiguous
2-
--> $DIR/restricted-shadowing-legacy.rs:93:13
2+
--> $DIR/restricted-shadowing-legacy.rs:101:13
33
|
44
LL | m!(); //~ ERROR `m` is ambiguous
55
| ^
66
|
77
note: `m` could refer to the name defined here
8-
--> $DIR/restricted-shadowing-legacy.rs:80:9
8+
--> $DIR/restricted-shadowing-legacy.rs:88:9
99
|
10-
LL | macro_rules! m { () => {} }
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | macro_rules! m { () => { Right } }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
...
1313
LL | include!();
1414
| ----------- in this macro invocation
1515
note: `m` could also refer to the name defined here
16-
--> $DIR/restricted-shadowing-legacy.rs:89:9
16+
--> $DIR/restricted-shadowing-legacy.rs:97:9
1717
|
1818
LL | macro_rules! m { () => {} }
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,21 +23,21 @@ LL | include!();
2323
= note: macro-expanded macros do not shadow
2424

2525
error[E0659]: `m` is ambiguous
26-
--> $DIR/restricted-shadowing-legacy.rs:131:42
26+
--> $DIR/restricted-shadowing-legacy.rs:139:42
2727
|
2828
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
2929
| ^
3030
|
3131
note: `m` could refer to the name defined here
32-
--> $DIR/restricted-shadowing-legacy.rs:80:9
32+
--> $DIR/restricted-shadowing-legacy.rs:88:9
3333
|
34-
LL | macro_rules! m { () => {} }
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
LL | macro_rules! m { () => { Right } }
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636
...
3737
LL | include!();
3838
| ----------- in this macro invocation
3939
note: `m` could also refer to the name defined here
40-
--> $DIR/restricted-shadowing-legacy.rs:127:9
40+
--> $DIR/restricted-shadowing-legacy.rs:135:9
4141
|
4242
LL | macro_rules! m { () => {} }
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -47,21 +47,21 @@ LL | include!();
4747
= note: macro-expanded macros do not shadow
4848

4949
error[E0659]: `m` is ambiguous
50-
--> $DIR/restricted-shadowing-legacy.rs:140:9
50+
--> $DIR/restricted-shadowing-legacy.rs:148:9
5151
|
5252
LL | m!(); //~ ERROR `m` is ambiguous
5353
| ^
5454
|
5555
note: `m` could refer to the name defined here
56-
--> $DIR/restricted-shadowing-legacy.rs:80:9
56+
--> $DIR/restricted-shadowing-legacy.rs:88:9
5757
|
58-
LL | macro_rules! m { () => {} }
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
58+
LL | macro_rules! m { () => { Right } }
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060
...
6161
LL | include!();
6262
| ----------- in this macro invocation
6363
note: `m` could also refer to the name defined here
64-
--> $DIR/restricted-shadowing-legacy.rs:136:9
64+
--> $DIR/restricted-shadowing-legacy.rs:144:9
6565
|
6666
LL | macro_rules! m { () => {} }
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,93 +71,93 @@ LL | include!();
7171
= note: macro-expanded macros do not shadow
7272

7373
error[E0659]: `m` is ambiguous
74-
--> $DIR/restricted-shadowing-legacy.rs:156:9
74+
--> $DIR/restricted-shadowing-legacy.rs:164:9
7575
|
7676
LL | m!(); //~ ERROR `m` is ambiguous
7777
| ^
7878
|
7979
note: `m` could refer to the name defined here
80-
--> $DIR/restricted-shadowing-legacy.rs:80:9
80+
--> $DIR/restricted-shadowing-legacy.rs:88:9
8181
|
82-
LL | macro_rules! m { () => {} }
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
LL | macro_rules! m { () => { Right } }
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484
...
8585
LL | include!();
8686
| ----------- in this macro invocation
8787
note: `m` could also refer to the name defined here
88-
--> $DIR/restricted-shadowing-legacy.rs:77:9
88+
--> $DIR/restricted-shadowing-legacy.rs:85:9
8989
|
90-
LL | macro_rules! m { () => {} }
91-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
90+
LL | macro_rules! m { () => { Wrong } }
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9292
...
9393
LL | include!();
9494
| ----------- in this macro invocation
9595
= note: macro-expanded macros do not shadow
9696

9797
error[E0659]: `m` is ambiguous
98-
--> $DIR/restricted-shadowing-legacy.rs:172:13
98+
--> $DIR/restricted-shadowing-legacy.rs:180:13
9999
|
100100
LL | m!(); //~ ERROR `m` is ambiguous
101101
| ^
102102
|
103103
note: `m` could refer to the name defined here
104-
--> $DIR/restricted-shadowing-legacy.rs:80:9
104+
--> $DIR/restricted-shadowing-legacy.rs:88:9
105105
|
106-
LL | macro_rules! m { () => {} }
107-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
106+
LL | macro_rules! m { () => { Right } }
107+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108108
...
109109
LL | include!();
110110
| ----------- in this macro invocation
111111
note: `m` could also refer to the name defined here
112-
--> $DIR/restricted-shadowing-legacy.rs:77:9
112+
--> $DIR/restricted-shadowing-legacy.rs:85:9
113113
|
114-
LL | macro_rules! m { () => {} }
115-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
LL | macro_rules! m { () => { Wrong } }
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116116
...
117117
LL | include!();
118118
| ----------- in this macro invocation
119119
= note: macro-expanded macros do not shadow
120120

121121
error[E0659]: `m` is ambiguous
122-
--> $DIR/restricted-shadowing-legacy.rs:210:42
122+
--> $DIR/restricted-shadowing-legacy.rs:218:42
123123
|
124124
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
125125
| ^
126126
|
127127
note: `m` could refer to the name defined here
128-
--> $DIR/restricted-shadowing-legacy.rs:80:9
128+
--> $DIR/restricted-shadowing-legacy.rs:88:9
129129
|
130-
LL | macro_rules! m { () => {} }
131-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
130+
LL | macro_rules! m { () => { Right } }
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132132
...
133133
LL | include!();
134134
| ----------- in this macro invocation
135135
note: `m` could also refer to the name defined here
136-
--> $DIR/restricted-shadowing-legacy.rs:77:9
136+
--> $DIR/restricted-shadowing-legacy.rs:85:9
137137
|
138-
LL | macro_rules! m { () => {} }
139-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
138+
LL | macro_rules! m { () => { Wrong } }
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140140
...
141141
LL | include!();
142142
| ----------- in this macro invocation
143143
= note: macro-expanded macros do not shadow
144144

145145
error[E0659]: `m` is ambiguous
146-
--> $DIR/restricted-shadowing-legacy.rs:224:9
146+
--> $DIR/restricted-shadowing-legacy.rs:232:9
147147
|
148148
LL | m!(); //~ ERROR `m` is ambiguous
149149
| ^
150150
|
151151
note: `m` could refer to the name defined here
152-
--> $DIR/restricted-shadowing-legacy.rs:80:9
152+
--> $DIR/restricted-shadowing-legacy.rs:88:9
153153
|
154-
LL | macro_rules! m { () => {} }
155-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
154+
LL | macro_rules! m { () => { Right } }
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156156
...
157157
LL | include!();
158158
| ----------- in this macro invocation
159159
note: `m` could also refer to the name defined here
160-
--> $DIR/restricted-shadowing-legacy.rs:219:13
160+
--> $DIR/restricted-shadowing-legacy.rs:227:13
161161
|
162162
LL | macro_rules! m { () => {} }
163163
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -167,21 +167,21 @@ LL | include!();
167167
= note: macro-expanded macros do not shadow
168168

169169
error[E0659]: `m` is ambiguous
170-
--> $DIR/restricted-shadowing-legacy.rs:254:42
170+
--> $DIR/restricted-shadowing-legacy.rs:262:42
171171
|
172172
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
173173
| ^
174174
|
175175
note: `m` could refer to the name defined here
176-
--> $DIR/restricted-shadowing-legacy.rs:80:9
176+
--> $DIR/restricted-shadowing-legacy.rs:88:9
177177
|
178-
LL | macro_rules! m { () => {} }
179-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
178+
LL | macro_rules! m { () => { Right } }
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180180
...
181181
LL | include!();
182182
| ----------- in this macro invocation
183183
note: `m` could also refer to the name defined here
184-
--> $DIR/restricted-shadowing-legacy.rs:249:13
184+
--> $DIR/restricted-shadowing-legacy.rs:257:13
185185
|
186186
LL | macro_rules! m { () => {} }
187187
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)