Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/codegen-llvm/enum/enum-array-index-spare-niche.rs
Original file line number Diff line number Diff line change
@@ -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<Outer, Error> {
// 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<Outer>` (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))
}
17 changes: 17 additions & 0 deletions tests/ui/derives/clone-vector-element-size.rs
Original file line number Diff line number Diff line change
@@ -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<Foo> = Vec::new();
let _ = foo.clone();
}
24 changes: 24 additions & 0 deletions tests/ui/traits/const-traits/self-receiver-type-mismatch.rs
Original file line number Diff line number Diff line change
@@ -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<T = [(); Cls.trigger()]> {
V(T),
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/traits/const-traits/self-receiver-type-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading