From d1b2d29528b7794b41e66fc2136e395a02f8529b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:59:35 +0200 Subject: Merging upstream version 1.73.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/match/issue-114691.rs | 39 ++++++++++++++++++++++ tests/ui/match/issue-115681.rs | 32 ++++++++++++++++++ tests/ui/match/issue-74050-end-span.stderr | 2 +- ...-first-arm-doesnt-match-expected-return-type.rs | 21 ++++++++++++ ...st-arm-doesnt-match-expected-return-type.stderr | 12 +++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/ui/match/issue-114691.rs create mode 100644 tests/ui/match/issue-115681.rs create mode 100644 tests/ui/match/non-first-arm-doesnt-match-expected-return-type.rs create mode 100644 tests/ui/match/non-first-arm-doesnt-match-expected-return-type.stderr (limited to 'tests/ui/match') 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) { + 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, shouldwe2: Option) -> 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, shouldwe2: Option) -> 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`. -- cgit v1.2.3