Skip to content

Commit d1c2815

Browse files
committed
Use diverges instead of !-type
1 parent d415fae commit d1c2815

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630630
// If we encountered a `break`, then (no surprise) it may be possible to break from the
631631
// loop... unless the value being returned from the loop diverges itself, e.g.
632632
// `break return 5` or `break loop {}`.
633-
ctxt.may_break |= !e_ty.is_never();
633+
ctxt.may_break |= !self.diverges.get().is_always();
634634

635635
// the type of a `break` is always `!`, since it diverges
636636
tcx.types.never

src/test/ui/break-diverging-value.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ fn loop_break_break() -> i32 { //~ ERROR mismatched types
1212
let loop_value = loop { break break };
1313
}
1414

15-
fn loop_break_return_2() -> i32 { //~ ERROR mismatched types
16-
let loop_value = loop { break { return; () } };
17-
//~^ ERROR `return;` in a function whose return type is not `()`
15+
fn loop_break_return_2() -> i32 {
16+
let loop_value = loop { break { return 0; () } }; // ok
1817
}
1918

2019
enum Void {}

src/test/ui/break-diverging-value.stderr

+3-18
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,14 @@ LL | fn loop_break_break() -> i32 {
66
| |
77
| implicitly returns `()` as its body has no tail or `return` expression
88

9-
error[E0069]: `return;` in a function whose return type is not `()`
10-
--> $DIR/break-diverging-value.rs:16:37
11-
|
12-
LL | let loop_value = loop { break { return; () } };
13-
| ^^^^^^ return type is not `()`
14-
15-
error[E0308]: mismatched types
16-
--> $DIR/break-diverging-value.rs:15:29
17-
|
18-
LL | fn loop_break_return_2() -> i32 {
19-
| ------------------- ^^^ expected `i32`, found `()`
20-
| |
21-
| implicitly returns `()` as its body has no tail or `return` expression
22-
239
error[E0308]: mismatched types
24-
--> $DIR/break-diverging-value.rs:26:25
10+
--> $DIR/break-diverging-value.rs:25:25
2511
|
2612
LL | fn loop_break_void() -> i32 {
2713
| --------------- ^^^ expected `i32`, found `()`
2814
| |
2915
| implicitly returns `()` as its body has no tail or `return` expression
3016

31-
error: aborting due to 4 previous errors
17+
error: aborting due to 2 previous errors
3218

33-
Some errors have detailed explanations: E0069, E0308.
34-
For more information about an error, try `rustc --explain E0069`.
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)