From f493cab3e3d99692bf4de0d28acab3a918472d2f Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Thu, 9 Apr 2026 09:35:54 +0100 Subject: [PATCH 1/3] Add a test for an LLVM crash "Vector elements must have same size" --- tests/ui/derives/clone-vector-element-size.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/ui/derives/clone-vector-element-size.rs diff --git a/tests/ui/derives/clone-vector-element-size.rs b/tests/ui/derives/clone-vector-element-size.rs new file mode 100644 index 0000000000000..1f29657372452 --- /dev/null +++ b/tests/ui/derives/clone-vector-element-size.rs @@ -0,0 +1,17 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/104037. +//! LLVM used to hit an assertion "Vector elements must have same size" +//! when compiling derived Clone with MIR optimisation level of 3. + +//@ build-pass +//@ compile-flags: -Zmir-opt-level=3 -Copt-level=3 + +#[derive(Clone)] +pub struct Foo(Bar, u32); + +#[derive(Clone, Copy)] +pub struct Bar(u8, u8, u8); + +fn main() { + let foo: Vec = Vec::new(); + let _ = foo.clone(); +} From 12e847f75c57deb188c977a1254ad5252fb620e6 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Thu, 9 Apr 2026 09:35:57 +0100 Subject: [PATCH 2/3] Add a test for a const evaluator ICE on a self-receiver type mismatch --- .../self-receiver-type-mismatch.rs | 24 +++++++++++++++++++ .../self-receiver-type-mismatch.stderr | 12 ++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/traits/const-traits/self-receiver-type-mismatch.rs create mode 100644 tests/ui/traits/const-traits/self-receiver-type-mismatch.stderr diff --git a/tests/ui/traits/const-traits/self-receiver-type-mismatch.rs b/tests/ui/traits/const-traits/self-receiver-type-mismatch.rs new file mode 100644 index 0000000000000..61f0dbe3a9751 --- /dev/null +++ b/tests/ui/traits/const-traits/self-receiver-type-mismatch.rs @@ -0,0 +1,24 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/112623. +//! The const evaluator used to ICE with an assertion failure on a size mismatch +//! when a trait impl changed the `self` receiver type from by-value to by-reference. + +#![feature(const_trait_impl)] + +const trait Func { + fn trigger(self) -> usize; +} + +struct Cls; + +impl const Func for Cls { + fn trigger(&self, a: usize) -> usize { + //~^ ERROR method `trigger` has 2 parameters but the declaration in trait `Func::trigger` has 1 + 0 + } +} + +enum Bug { + V(T), +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/self-receiver-type-mismatch.stderr b/tests/ui/traits/const-traits/self-receiver-type-mismatch.stderr new file mode 100644 index 0000000000000..4fd65d38a40d5 --- /dev/null +++ b/tests/ui/traits/const-traits/self-receiver-type-mismatch.stderr @@ -0,0 +1,12 @@ +error[E0050]: method `trigger` has 2 parameters but the declaration in trait `Func::trigger` has 1 + --> $DIR/self-receiver-type-mismatch.rs:14:16 + | +LL | fn trigger(self) -> usize; + | ---- trait requires 1 parameter +... +LL | fn trigger(&self, a: usize) -> usize { + | ^^^^^^^^^^^^^^^ expected 1 parameter, found 2 + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0050`. From fc9f492049072489988d201dd2baed1b6c513925 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Thu, 9 Apr 2026 09:36:00 +0100 Subject: [PATCH 3/3] Add a codegen test for a missed optimisation with spare niches --- .../enum/enum-array-index-spare-niche.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/codegen-llvm/enum/enum-array-index-spare-niche.rs diff --git a/tests/codegen-llvm/enum/enum-array-index-spare-niche.rs b/tests/codegen-llvm/enum/enum-array-index-spare-niche.rs new file mode 100644 index 0000000000000..e758996a29e06 --- /dev/null +++ b/tests/codegen-llvm/enum/enum-array-index-spare-niche.rs @@ -0,0 +1,28 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/113899. +//! When indexing into an array of an enum type with spare niches, the compiler +//! used to emit a superfluous branch checking whether the loaded value was +//! a niche value. Every element in the array is a valid variant, so this check +//! is unnecessary and should be optimised away. + +//@ compile-flags: -Copt-level=3 +#![crate_type = "lib"] + +#[derive(Clone, Copy)] +pub enum Outer { + A([u8; 8]), + B([u8; 8]), +} + +pub struct Error(u8); + +// CHECK-LABEL: @test +#[no_mangle] +pub fn test(x: usize) -> Result { + // There should be exactly one comparison: the bounds check on `x`. + // There must be no second comparison checking the discriminant + // against the niche value used by `Option` (from `get()`). + // CHECK: icmp ult + // CHECK-NOT: icmp + // CHECK: ret void + [Outer::A([10; 8]), Outer::B([20; 8])].get(x).copied().ok_or(Error(5)) +}