-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #67278 - Centril:67273, r=oli-obk
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
fn main() { | ||
let mut i: i64; | ||
// Expected type is an inference variable `?T` | ||
// because the `match` is used as a statement. | ||
// This is the "initial" type of the `coercion`. | ||
match i { | ||
// Add `bool` to the overall `coercion`. | ||
0 => true, | ||
|
||
// Necessary to cause the ICE: | ||
1 => true, | ||
|
||
// Suppose that we had `let _: bool = match i { ... }`. | ||
// In that case, as the expected type would be `bool`, | ||
// we would suggest `i == 1` as a fix. | ||
// | ||
// However, no type error happens when checking `i = 1` because `expected == ?T`, | ||
// which will unify with `typeof(i = 1) == ()`. | ||
// | ||
// However, in #67273, we would delay the unification of this arm with the above | ||
// because we used the hitherto accumulated coercion as opposed to the "initial" type. | ||
2 => i = 1, | ||
//~^ ERROR match arms have incompatible types | ||
|
||
_ => (), | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0308]: match arms have incompatible types | ||
--> $DIR/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs:22:14 | ||
| | ||
LL | / match i { | ||
LL | | // Add `bool` to the overall `coercion`. | ||
LL | | 0 => true, | ||
| | ---- this is found to be of type `bool` | ||
LL | | | ||
LL | | // Necessary to cause the ICE: | ||
LL | | 1 => true, | ||
| | ---- this is found to be of type `bool` | ||
... | | ||
LL | | 2 => i = 1, | ||
| | ^^^^^ expected `bool`, found `()` | ||
... | | ||
LL | | _ => (), | ||
LL | | } | ||
| |_____- `match` arms have incompatible types | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |