summaryrefslogtreecommitdiffstats
path: root/tests/ui/match
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/match
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/match')
-rw-r--r--tests/ui/match/issue-114691.rs39
-rw-r--r--tests/ui/match/issue-115681.rs32
-rw-r--r--tests/ui/match/issue-74050-end-span.stderr2
-rw-r--r--tests/ui/match/non-first-arm-doesnt-match-expected-return-type.rs21
-rw-r--r--tests/ui/match/non-first-arm-doesnt-match-expected-return-type.stderr12
5 files changed, 105 insertions, 1 deletions
diff --git a/tests/ui/match/issue-114691.rs b/tests/ui/match/issue-114691.rs
new file mode 100644
index 000000000..cc17d9ecf
--- /dev/null
+++ b/tests/ui/match/issue-114691.rs
@@ -0,0 +1,39 @@
+// run-pass
+
+// This test used to be miscompiled by LLVM 17.
+#![allow(dead_code)]
+
+enum Pass {
+ Opaque {
+ clear_color: [f32; 4],
+ with_depth_pre_pass: bool,
+ },
+ Transparent,
+}
+
+enum LoadOp {
+ Clear,
+ Load,
+}
+
+#[inline(never)]
+fn check(x: Option<LoadOp>) {
+ assert!(x.is_none());
+}
+
+#[inline(never)]
+fn test(mode: Pass) {
+ check(match mode {
+ Pass::Opaque {
+ with_depth_pre_pass: true,
+ ..
+ }
+ | Pass::Transparent => None,
+ _ => Some(LoadOp::Clear),
+ });
+}
+
+fn main() {
+ println!("Hello, world!");
+ test(Pass::Transparent);
+}
diff --git a/tests/ui/match/issue-115681.rs b/tests/ui/match/issue-115681.rs
new file mode 100644
index 000000000..c41e808e1
--- /dev/null
+++ b/tests/ui/match/issue-115681.rs
@@ -0,0 +1,32 @@
+// run-pass
+// compile-flags: -C opt-level=1
+
+// Make sure LLVM does not miscompile this match.
+fn main() {
+ enum Bits {
+ None = 0x00,
+ Low = 0x40,
+ High = 0x80,
+ Both = 0xC0,
+ }
+
+ let value = Box::new(0x40u8);
+ let mut out = Box::new(0u8);
+
+ let bits = match *value {
+ 0x00 => Bits::None,
+ 0x40 => Bits::Low,
+ 0x80 => Bits::High,
+ 0xC0 => Bits::Both,
+ _ => return,
+ };
+
+ match bits {
+ Bits::None | Bits::Low => {
+ *out = 1;
+ }
+ _ => (),
+ }
+
+ assert_eq!(*out, 1);
+}
diff --git a/tests/ui/match/issue-74050-end-span.stderr b/tests/ui/match/issue-74050-end-span.stderr
index 0b3425f2b..0dafeae87 100644
--- a/tests/ui/match/issue-74050-end-span.stderr
+++ b/tests/ui/match/issue-74050-end-span.stderr
@@ -6,7 +6,7 @@ LL | let _arg = match args.next() {
LL | Some(arg) => {
| --- binding `arg` declared here
LL | match arg.to_str() {
- | ^^^^^^^^^^^^ borrowed value does not live long enough
+ | ^^^ borrowed value does not live long enough
...
LL | }
| - `arg` dropped here while still borrowed
diff --git a/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.rs b/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.rs
new file mode 100644
index 000000000..85b1ef755
--- /dev/null
+++ b/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.rs
@@ -0,0 +1,21 @@
+#![allow(unused)]
+
+fn test(shouldwe: Option<u32>, shouldwe2: Option<u32>) -> u32 {
+ //~^ NOTE expected `u32` because of return type
+ match shouldwe {
+ Some(val) => {
+ match shouldwe2 {
+ Some(val) => {
+ return val;
+ }
+ None => (), //~ ERROR mismatched types
+ //~^ NOTE expected `u32`, found `()`
+ }
+ }
+ None => return 12,
+ }
+}
+
+fn main() {
+ println!("returned {}", test(None, Some(5)));
+}
diff --git a/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.stderr b/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.stderr
new file mode 100644
index 000000000..e6d93b8b5
--- /dev/null
+++ b/tests/ui/match/non-first-arm-doesnt-match-expected-return-type.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> $DIR/non-first-arm-doesnt-match-expected-return-type.rs:11:25
+ |
+LL | fn test(shouldwe: Option<u32>, shouldwe2: Option<u32>) -> u32 {
+ | --- expected `u32` because of return type
+...
+LL | None => (),
+ | ^^ expected `u32`, found `()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.