Skip to content

Commit 92fd27c

Browse files
diannejoshtriplett
andcommitted
additional tests for is expressions' lexical scope
Co-authored-by: Josh Triplett <[email protected]>
1 parent d9cfd3e commit 92fd27c

File tree

2 files changed

+208
-15
lines changed

2 files changed

+208
-15
lines changed

tests/ui/rfcs/rfc-3573-is/name-resolution-errors.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,63 @@ fn main() {
1111
&& x
1212
{
1313
x;
14+
} else {
15+
x; //~ ERROR cannot find value `x` in this scope
1416
}
1517
x; //~ ERROR cannot find value `x` in this scope
1618

1719
// Elsewhere, `is`'s bindings only extend to the end of its `&&`-chain.
1820
if x //~ ERROR cannot find value `x` in this scope
19-
&& (is!(true is x) && x)
21+
&& (is!(true is x) && x && { x })
2022
&& x //~ ERROR cannot find value `x` in this scope
2123
&& (is!(true is x) || x) //~ ERROR cannot find value `x` in this scope
24+
&& (!is!(true is x) || x) //~ ERROR cannot find value `x` in this scope
25+
&& (is!(true is x) & x) //~ ERROR cannot find value `x` in this scope
2226
{
2327
x; //~ ERROR cannot find value `x` in this scope
2428
}
29+
30+
match is!(true is x) {
31+
_ => { x; } //~ ERROR cannot find value `x` in this scope
32+
}
33+
34+
match () {
35+
() if is!(true is x) && x => { x; }
36+
() if x => {} //~ ERROR cannot find value `x` in this scope
37+
}
38+
39+
match () {
40+
() if is!(true is x) && x => { x; }
41+
() => { x; } //~ ERROR cannot find value `x` in this scope
42+
}
43+
44+
fn f(_a: bool, _b: bool) {}
45+
f(is!(true is x) && x, true);
46+
f(is!(true is x), x); //~ ERROR cannot find value `x` in this scope
47+
f(is!(true is x) && x, x); //~ ERROR cannot find value `x` in this scope
48+
49+
if !is!(true is x) {
50+
x; //~ ERROR cannot find value `x` in this scope
51+
} else {
52+
x; //~ ERROR cannot find value `x` in this scope
53+
}
54+
55+
if true
56+
&& if is!(true is x) && x { x } else { false }
57+
&& x //~ ERROR cannot find value `x` in this scope
58+
{
59+
x; //~ ERROR cannot find value `x` in this scope
60+
}
61+
62+
while is!(true is x) {
63+
x;
64+
break;
65+
}
66+
x; //~ ERROR cannot find value `x` in this scope
67+
68+
is!(true is x);
69+
x; //~ ERROR cannot find value `x` in this scope
70+
2571
is!(true is x);
2672
x; //~ ERROR cannot find value `x` in this scope
2773
}

tests/ui/rfcs/rfc-3573-is/name-resolution-errors.stderr

Lines changed: 161 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,191 @@ error[E0425]: cannot find value `x` in this scope
22
--> $DIR/name-resolution-errors.rs:9:8
33
|
44
LL | if x
5-
| ^ not found in this scope
5+
| ^ help: a function with a similar name exists: `f`
6+
...
7+
LL | fn f(_a: bool, _b: bool) {}
8+
| ------------------------ similarly named function `f` defined here
69

710
error[E0425]: cannot find value `x` in this scope
8-
--> $DIR/name-resolution-errors.rs:15:5
11+
--> $DIR/name-resolution-errors.rs:15:9
12+
|
13+
LL | x;
14+
| ^ help: a function with a similar name exists: `f`
15+
...
16+
LL | fn f(_a: bool, _b: bool) {}
17+
| ------------------------ similarly named function `f` defined here
18+
19+
error[E0425]: cannot find value `x` in this scope
20+
--> $DIR/name-resolution-errors.rs:17:5
921
|
1022
LL | x;
11-
| ^ not found in this scope
23+
| ^ help: a function with a similar name exists: `f`
24+
...
25+
LL | fn f(_a: bool, _b: bool) {}
26+
| ------------------------ similarly named function `f` defined here
1227

1328
error[E0425]: cannot find value `x` in this scope
14-
--> $DIR/name-resolution-errors.rs:18:8
29+
--> $DIR/name-resolution-errors.rs:20:8
1530
|
1631
LL | if x
17-
| ^ not found in this scope
32+
| ^ help: a function with a similar name exists: `f`
33+
...
34+
LL | fn f(_a: bool, _b: bool) {}
35+
| ------------------------ similarly named function `f` defined here
1836

1937
error[E0425]: cannot find value `x` in this scope
20-
--> $DIR/name-resolution-errors.rs:20:12
38+
--> $DIR/name-resolution-errors.rs:22:12
2139
|
2240
LL | && x
23-
| ^ not found in this scope
41+
| ^ help: a function with a similar name exists: `f`
42+
...
43+
LL | fn f(_a: bool, _b: bool) {}
44+
| ------------------------ similarly named function `f` defined here
2445

2546
error[E0425]: cannot find value `x` in this scope
26-
--> $DIR/name-resolution-errors.rs:21:31
47+
--> $DIR/name-resolution-errors.rs:23:31
2748
|
2849
LL | && (is!(true is x) || x)
29-
| ^ not found in this scope
50+
| ^ help: a function with a similar name exists: `f`
51+
...
52+
LL | fn f(_a: bool, _b: bool) {}
53+
| ------------------------ similarly named function `f` defined here
54+
55+
error[E0425]: cannot find value `x` in this scope
56+
--> $DIR/name-resolution-errors.rs:24:32
57+
|
58+
LL | && (!is!(true is x) || x)
59+
| ^ help: a function with a similar name exists: `f`
60+
...
61+
LL | fn f(_a: bool, _b: bool) {}
62+
| ------------------------ similarly named function `f` defined here
3063

3164
error[E0425]: cannot find value `x` in this scope
32-
--> $DIR/name-resolution-errors.rs:23:9
65+
--> $DIR/name-resolution-errors.rs:25:30
66+
|
67+
LL | && (is!(true is x) & x)
68+
| ^ help: a function with a similar name exists: `f`
69+
...
70+
LL | fn f(_a: bool, _b: bool) {}
71+
| ------------------------ similarly named function `f` defined here
72+
73+
error[E0425]: cannot find value `x` in this scope
74+
--> $DIR/name-resolution-errors.rs:27:9
3375
|
3476
LL | x;
35-
| ^ not found in this scope
77+
| ^ help: a function with a similar name exists: `f`
78+
...
79+
LL | fn f(_a: bool, _b: bool) {}
80+
| ------------------------ similarly named function `f` defined here
81+
82+
error[E0425]: cannot find value `x` in this scope
83+
--> $DIR/name-resolution-errors.rs:31:16
84+
|
85+
LL | _ => { x; }
86+
| ^ help: a function with a similar name exists: `f`
87+
...
88+
LL | fn f(_a: bool, _b: bool) {}
89+
| ------------------------ similarly named function `f` defined here
90+
91+
error[E0425]: cannot find value `x` in this scope
92+
--> $DIR/name-resolution-errors.rs:36:15
93+
|
94+
LL | () if x => {}
95+
| ^ help: a function with a similar name exists: `f`
96+
...
97+
LL | fn f(_a: bool, _b: bool) {}
98+
| ------------------------ similarly named function `f` defined here
99+
100+
error[E0425]: cannot find value `x` in this scope
101+
--> $DIR/name-resolution-errors.rs:41:17
102+
|
103+
LL | () => { x; }
104+
| ^ help: a function with a similar name exists: `f`
105+
...
106+
LL | fn f(_a: bool, _b: bool) {}
107+
| ------------------------ similarly named function `f` defined here
108+
109+
error[E0425]: cannot find value `x` in this scope
110+
--> $DIR/name-resolution-errors.rs:46:23
111+
|
112+
LL | fn f(_a: bool, _b: bool) {}
113+
| ------------------------ similarly named function `f` defined here
114+
LL | f(is!(true is x) && x, true);
115+
LL | f(is!(true is x), x);
116+
| ^ help: a function with a similar name exists: `f`
117+
118+
error[E0425]: cannot find value `x` in this scope
119+
--> $DIR/name-resolution-errors.rs:47:28
120+
|
121+
LL | fn f(_a: bool, _b: bool) {}
122+
| ------------------------ similarly named function `f` defined here
123+
...
124+
LL | f(is!(true is x) && x, x);
125+
| ^ help: a function with a similar name exists: `f`
126+
127+
error[E0425]: cannot find value `x` in this scope
128+
--> $DIR/name-resolution-errors.rs:50:9
129+
|
130+
LL | fn f(_a: bool, _b: bool) {}
131+
| ------------------------ similarly named function `f` defined here
132+
...
133+
LL | x;
134+
| ^ help: a function with a similar name exists: `f`
135+
136+
error[E0425]: cannot find value `x` in this scope
137+
--> $DIR/name-resolution-errors.rs:52:9
138+
|
139+
LL | fn f(_a: bool, _b: bool) {}
140+
| ------------------------ similarly named function `f` defined here
141+
...
142+
LL | x;
143+
| ^ help: a function with a similar name exists: `f`
144+
145+
error[E0425]: cannot find value `x` in this scope
146+
--> $DIR/name-resolution-errors.rs:57:12
147+
|
148+
LL | fn f(_a: bool, _b: bool) {}
149+
| ------------------------ similarly named function `f` defined here
150+
...
151+
LL | && x
152+
| ^ help: a function with a similar name exists: `f`
153+
154+
error[E0425]: cannot find value `x` in this scope
155+
--> $DIR/name-resolution-errors.rs:59:9
156+
|
157+
LL | fn f(_a: bool, _b: bool) {}
158+
| ------------------------ similarly named function `f` defined here
159+
...
160+
LL | x;
161+
| ^ help: a function with a similar name exists: `f`
162+
163+
error[E0425]: cannot find value `x` in this scope
164+
--> $DIR/name-resolution-errors.rs:66:5
165+
|
166+
LL | fn f(_a: bool, _b: bool) {}
167+
| ------------------------ similarly named function `f` defined here
168+
...
169+
LL | x;
170+
| ^ help: a function with a similar name exists: `f`
171+
172+
error[E0425]: cannot find value `x` in this scope
173+
--> $DIR/name-resolution-errors.rs:69:5
174+
|
175+
LL | fn f(_a: bool, _b: bool) {}
176+
| ------------------------ similarly named function `f` defined here
177+
...
178+
LL | x;
179+
| ^ help: a function with a similar name exists: `f`
36180

37181
error[E0425]: cannot find value `x` in this scope
38-
--> $DIR/name-resolution-errors.rs:26:5
182+
--> $DIR/name-resolution-errors.rs:72:5
39183
|
184+
LL | fn f(_a: bool, _b: bool) {}
185+
| ------------------------ similarly named function `f` defined here
186+
...
40187
LL | x;
41-
| ^ not found in this scope
188+
| ^ help: a function with a similar name exists: `f`
42189

43-
error: aborting due to 7 previous errors
190+
error: aborting due to 21 previous errors
44191

45192
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)