summaryrefslogtreecommitdiffstats
path: root/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs')
-rw-r--r--src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs
new file mode 100644
index 000000000..c39ab9544
--- /dev/null
+++ b/src/test/ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs
@@ -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
+
+ _ => (),
+ }
+}