Use diverges instead of !-type

This commit is contained in:
varkor 2020-10-22 23:12:46 +01:00
parent d415fae8b7
commit d1c2815d6a
3 changed files with 6 additions and 22 deletions

View File

@ -630,7 +630,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If we encountered a `break`, then (no surprise) it may be possible to break from the
// loop... unless the value being returned from the loop diverges itself, e.g.
// `break return 5` or `break loop {}`.
ctxt.may_break |= !e_ty.is_never();
ctxt.may_break |= !self.diverges.get().is_always();
// the type of a `break` is always `!`, since it diverges
tcx.types.never

View File

@ -12,9 +12,8 @@ fn loop_break_break() -> i32 { //~ ERROR mismatched types
let loop_value = loop { break break };
}
fn loop_break_return_2() -> i32 { //~ ERROR mismatched types
let loop_value = loop { break { return; () } };
//~^ ERROR `return;` in a function whose return type is not `()`
fn loop_break_return_2() -> i32 {
let loop_value = loop { break { return 0; () } }; // ok
}
enum Void {}

View File

@ -6,29 +6,14 @@ LL | fn loop_break_break() -> i32 {
| |
| implicitly returns `()` as its body has no tail or `return` expression
error[E0069]: `return;` in a function whose return type is not `()`
--> $DIR/break-diverging-value.rs:16:37
|
LL | let loop_value = loop { break { return; () } };
| ^^^^^^ return type is not `()`
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:15:29
|
LL | fn loop_break_return_2() -> i32 {
| ------------------- ^^^ expected `i32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:26:25
--> $DIR/break-diverging-value.rs:25:25
|
LL | fn loop_break_void() -> i32 {
| --------------- ^^^ expected `i32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
error: aborting due to 4 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0069, E0308.
For more information about an error, try `rustc --explain E0069`.
For more information about this error, try `rustc --explain E0308`.