Skip to content

Commit 8d1e5b8

Browse files
committed
Various test changes
1 parent 9903968 commit 8d1e5b8

11 files changed

+200
-19
lines changed

src/test/incremental/hashes/if_expressions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn add_else_branch(x: bool) -> u32 {
9494
}
9595

9696
#[cfg(not(cfail1))]
97-
#[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
97+
#[rustc_clean(cfg="cfail2", except="HirBody")]
9898
#[rustc_clean(cfg="cfail3")]
9999
pub fn add_else_branch(x: bool) -> u32 {
100100
let mut ret = 1;
@@ -191,7 +191,7 @@ pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
191191
}
192192

193193
#[cfg(not(cfail1))]
194-
#[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
194+
#[rustc_clean(cfg="cfail2", except="HirBody")]
195195
#[rustc_clean(cfg="cfail3")]
196196
pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
197197
let mut ret = 1;

src/test/run-pass/if-ret.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: unreachable block in `if` expression
2+
--> $DIR/if-ret.rs:4:24
3+
|
4+
LL | fn foo() { if (return) { } }
5+
| ^^^
6+
|
7+
= note: #[warn(unreachable_code)] on by default
8+

src/test/ui/if/if-let-arm-types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
fn main() {
22
if let Some(b) = None {
3-
//~^ NOTE if let` arms have incompatible types
3+
//~^ NOTE if and else have incompatible types
44
()
5+
//~^ NOTE expected because of this
56
} else {
67
1
78
};
8-
//~^^ ERROR: `if let` arms have incompatible types
9+
//~^^ ERROR: if and else have incompatible types
910
//~| NOTE expected (), found integer
1011
//~| NOTE expected type `()`
1112
}

src/test/ui/if/if-let-arm-types.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
error[E0308]: `if let` arms have incompatible types
2-
--> $DIR/if-let-arm-types.rs:6:9
1+
error[E0308]: if and else have incompatible types
2+
--> $DIR/if-let-arm-types.rs:7:9
33
|
44
LL | / if let Some(b) = None {
55
LL | |
66
LL | | ()
7+
| | -- expected because of this
8+
LL | |
79
LL | | } else {
810
LL | | 1
911
| | ^ expected (), found integer
1012
LL | | };
11-
| |_____- `if let` arms have incompatible types
13+
| |_____- if and else have incompatible types
1214
|
1315
= note: expected type `()`
1416
found type `{integer}`

src/test/ui/if/if-without-else-as-fn-expr.rs

+30
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ fn foo(bar: usize) -> usize {
33
return 3;
44
}
55
//~^^^ ERROR if may be missing an else clause
6+
//~| ERROR mismatched types [E0308]
67
}
78

89
fn foo2(bar: usize) -> usize {
910
let x: usize = if bar % 5 == 0 {
1011
return 3;
1112
};
1213
//~^^^ ERROR if may be missing an else clause
14+
//~| ERROR mismatched types [E0308]
1315
x
1416
}
1517

@@ -18,8 +20,36 @@ fn foo3(bar: usize) -> usize {
1820
3
1921
}
2022
//~^^^ ERROR if may be missing an else clause
23+
//~| ERROR mismatched types [E0308]
2124
}
2225

26+
fn foo_let(bar: usize) -> usize {
27+
if let 0 = 1 {
28+
return 3;
29+
}
30+
//~^^^ ERROR if may be missing an else clause
31+
//~| ERROR mismatched types [E0308]
32+
}
33+
34+
fn foo2_let(bar: usize) -> usize {
35+
let x: usize = if let 0 = 1 {
36+
return 3;
37+
};
38+
//~^^^ ERROR if may be missing an else clause
39+
//~| ERROR mismatched types [E0308]
40+
x
41+
}
42+
43+
fn foo3_let(bar: usize) -> usize {
44+
if let 0 = 1 {
45+
3
46+
}
47+
//~^^^ ERROR if may be missing an else clause
48+
//~| ERROR mismatched types [E0308]
49+
}
50+
51+
// FIXME(60254): deduplicate first error in favor of second.
52+
2353
fn main() {
2454
let _ = foo(1);
2555
}

src/test/ui/if/if-without-else-as-fn-expr.stderr

+119-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/if-without-else-as-fn-expr.rs:2:5
3+
|
4+
LL | / if bar % 5 == 0 {
5+
LL | | return 3;
6+
LL | | }
7+
| |_____^ expected usize, found ()
8+
|
9+
= note: expected type `usize`
10+
found type `()`
11+
112
error[E0317]: if may be missing an else clause
213
--> $DIR/if-without-else-as-fn-expr.rs:2:5
314
|
@@ -13,8 +24,20 @@ LL | | }
1324
= note: `if` expressions without `else` evaluate to `()`
1425
= help: consider adding an `else` block that evaluates to the expected type
1526

27+
error[E0308]: mismatched types
28+
--> $DIR/if-without-else-as-fn-expr.rs:10:20
29+
|
30+
LL | let x: usize = if bar % 5 == 0 {
31+
| ____________________^
32+
LL | | return 3;
33+
LL | | };
34+
| |_____^ expected usize, found ()
35+
|
36+
= note: expected type `usize`
37+
found type `()`
38+
1639
error[E0317]: if may be missing an else clause
17-
--> $DIR/if-without-else-as-fn-expr.rs:9:20
40+
--> $DIR/if-without-else-as-fn-expr.rs:10:20
1841
|
1942
LL | let x: usize = if bar % 5 == 0 {
2043
| _________-__________^
@@ -29,8 +52,19 @@ LL | | };
2952
= note: `if` expressions without `else` evaluate to `()`
3053
= help: consider adding an `else` block that evaluates to the expected type
3154

55+
error[E0308]: mismatched types
56+
--> $DIR/if-without-else-as-fn-expr.rs:19:5
57+
|
58+
LL | / if bar % 5 == 0 {
59+
LL | | 3
60+
LL | | }
61+
| |_____^ expected usize, found ()
62+
|
63+
= note: expected type `usize`
64+
found type `()`
65+
3266
error[E0317]: if may be missing an else clause
33-
--> $DIR/if-without-else-as-fn-expr.rs:17:5
67+
--> $DIR/if-without-else-as-fn-expr.rs:19:5
3468
|
3569
LL | fn foo3(bar: usize) -> usize {
3670
| ----- expected `usize` because of this return type
@@ -44,6 +78,87 @@ LL | | }
4478
= note: `if` expressions without `else` evaluate to `()`
4579
= help: consider adding an `else` block that evaluates to the expected type
4680

47-
error: aborting due to 3 previous errors
81+
error[E0308]: mismatched types
82+
--> $DIR/if-without-else-as-fn-expr.rs:27:5
83+
|
84+
LL | / if let 0 = 1 {
85+
LL | | return 3;
86+
LL | | }
87+
| |_____^ expected usize, found ()
88+
|
89+
= note: expected type `usize`
90+
found type `()`
91+
92+
error[E0317]: if may be missing an else clause
93+
--> $DIR/if-without-else-as-fn-expr.rs:27:5
94+
|
95+
LL | fn foo_let(bar: usize) -> usize {
96+
| ----- expected `usize` because of this return type
97+
LL | / if let 0 = 1 {
98+
LL | | return 3;
99+
LL | | }
100+
| |_____^ expected usize, found ()
101+
|
102+
= note: expected type `usize`
103+
found type `()`
104+
= note: `if` expressions without `else` evaluate to `()`
105+
= help: consider adding an `else` block that evaluates to the expected type
106+
107+
error[E0308]: mismatched types
108+
--> $DIR/if-without-else-as-fn-expr.rs:35:20
109+
|
110+
LL | let x: usize = if let 0 = 1 {
111+
| ____________________^
112+
LL | | return 3;
113+
LL | | };
114+
| |_____^ expected usize, found ()
115+
|
116+
= note: expected type `usize`
117+
found type `()`
118+
119+
error[E0317]: if may be missing an else clause
120+
--> $DIR/if-without-else-as-fn-expr.rs:35:20
121+
|
122+
LL | let x: usize = if let 0 = 1 {
123+
| _________-__________^
124+
| | |
125+
| | expected because of this assignment
126+
LL | | return 3;
127+
LL | | };
128+
| |_____^ expected usize, found ()
129+
|
130+
= note: expected type `usize`
131+
found type `()`
132+
= note: `if` expressions without `else` evaluate to `()`
133+
= help: consider adding an `else` block that evaluates to the expected type
134+
135+
error[E0308]: mismatched types
136+
--> $DIR/if-without-else-as-fn-expr.rs:44:5
137+
|
138+
LL | / if let 0 = 1 {
139+
LL | | 3
140+
LL | | }
141+
| |_____^ expected usize, found ()
142+
|
143+
= note: expected type `usize`
144+
found type `()`
145+
146+
error[E0317]: if may be missing an else clause
147+
--> $DIR/if-without-else-as-fn-expr.rs:44:5
148+
|
149+
LL | fn foo3_let(bar: usize) -> usize {
150+
| ----- expected `usize` because of this return type
151+
LL | / if let 0 = 1 {
152+
LL | | 3
153+
LL | | }
154+
| |_____^ expected usize, found ()
155+
|
156+
= note: expected type `usize`
157+
found type `()`
158+
= note: `if` expressions without `else` evaluate to `()`
159+
= help: consider adding an `else` block that evaluates to the expected type
160+
161+
error: aborting due to 12 previous errors
48162

49-
For more information about this error, try `rustc --explain E0317`.
163+
Some errors have detailed explanations: E0308, E0317.
164+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/issues/issue-19991.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ LL | |
66
LL | |
77
LL | |
88
LL | | 765
9+
| | --- found here
910
LL | | };
1011
| |_____^ expected (), found integer
1112
|
1213
= note: expected type `()`
1314
found type `{integer}`
15+
= note: `if` expressions without `else` evaluate to `()`
16+
= help: consider adding an `else` block that evaluates to the expected type
1417

1518
error: aborting due to previous error
1619

src/test/ui/issues/issue-50577.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ fn main() {
22
enum Foo {
33
Drop = assert_eq!(1, 1)
44
//~^ ERROR if may be missing an else clause
5+
//~| ERROR mismatched types [E0308]
56
}
67
}

src/test/ui/issues/issue-50577.stderr

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-50577.rs:3:16
3+
|
4+
LL | Drop = assert_eq!(1, 1)
5+
| ^^^^^^^^^^^^^^^^ expected isize, found ()
6+
|
7+
= note: expected type `isize`
8+
found type `()`
9+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
10+
111
error[E0317]: if may be missing an else clause
212
--> $DIR/issue-50577.rs:3:16
313
|
@@ -13,6 +23,7 @@ LL | Drop = assert_eq!(1, 1)
1323
= help: consider adding an `else` block that evaluates to the expected type
1424
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1525

16-
error: aborting due to previous error
26+
error: aborting due to 2 previous errors
1727

18-
For more information about this error, try `rustc --explain E0317`.
28+
Some errors have detailed explanations: E0308, E0317.
29+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/reachable/expr_if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![deny(unreachable_code)]
55

66
fn foo() {
7-
if {return} {
7+
if {return} { //~ ERROR unreachable block in `if` expression
88
println!("Hello, world!");
99
}
1010
}

src/test/ui/reachable/expr_if.stderr

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
error: unreachable statement
2-
--> $DIR/expr_if.rs:27:5
1+
error: unreachable block in `if` expression
2+
--> $DIR/expr_if.rs:7:17
33
|
4-
LL | println!("But I am.");
5-
| ^^^^^^^^^^^^^^^^^^^^^^
4+
LL | if {return} {
5+
| _________________^
6+
LL | | println!("Hello, world!");
7+
LL | | }
8+
| |_____^
69
|
710
note: lint level defined here
811
--> $DIR/expr_if.rs:4:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
15+
16+
error: unreachable statement
17+
--> $DIR/expr_if.rs:27:5
18+
|
19+
LL | println!("But I am.");
20+
| ^^^^^^^^^^^^^^^^^^^^^^
21+
|
1222
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1323

14-
error: aborting due to previous error
24+
error: aborting due to 2 previous errors
1525

0 commit comments

Comments
 (0)