From e0586a6e1a013c99cee2ad63a915b85ff716af0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 19 Apr 2024 18:27:25 +0200 Subject: [PATCH 1/2] add test for #83993 Fixes #83993 --- .../adt_const_params/index-oob-ice-83993.rs | 18 ++++++++++++ .../index-oob-ice-83993.stderr | 29 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs create mode 100644 tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs new file mode 100644 index 0000000000000..0d1f023d565fb --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs @@ -0,0 +1,18 @@ +// issue: rust-lang/rust/#83993 + +#![feature(adt_const_params)] +//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes +fn bug<'a>() +where + for<'b> [(); { + let x: &'b (); + //~^ ERROR generic parameters may not be used in const operations + 0 + }]: +{} + +fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { } +//~^ ERROR generic parameters may not be used in const operations +fn good() where for<'b> [();{0}]: Sized { } + +pub fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr new file mode 100644 index 0000000000000..a49dfc319167b --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr @@ -0,0 +1,29 @@ +error: generic parameters may not be used in const operations + --> $DIR/index-oob-ice-83993.rs:8:17 + | +LL | let x: &'b (); + | ^^ cannot perform const operation using `'b` + | + = note: lifetime parameters may not be used in const expressions + = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: generic parameters may not be used in const operations + --> $DIR/index-oob-ice-83993.rs:14:36 + | +LL | fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { } + | ^^ cannot perform const operation using `'b` + | + = note: lifetime parameters may not be used in const expressions + = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions + +warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/index-oob-ice-83993.rs:3:12 + | +LL | #![feature(adt_const_params)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #95174 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to 2 previous errors; 1 warning emitted + From b015f61488f4f25e2007446540e2201a0ce6c0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 19 Apr 2024 22:23:17 +0200 Subject: [PATCH 2/2] add more known-crashes tests --- tests/crashes/103708.rs | 16 ++++++++++++++++ tests/crashes/104685.rs | 15 +++++++++++++++ tests/crashes/105249.rs | 16 ++++++++++++++++ tests/crashes/115994.rs | 17 +++++++++++++++++ tests/crashes/116721.rs | 9 +++++++++ tests/crashes/118244.rs | 22 ++++++++++++++++++++++ tests/crashes/124083.rs | 9 +++++++++ tests/crashes/124151.rs | 14 ++++++++++++++ tests/crashes/124164.rs | 4 ++++ 9 files changed, 122 insertions(+) create mode 100644 tests/crashes/103708.rs create mode 100644 tests/crashes/104685.rs create mode 100644 tests/crashes/105249.rs create mode 100644 tests/crashes/115994.rs create mode 100644 tests/crashes/116721.rs create mode 100644 tests/crashes/118244.rs create mode 100644 tests/crashes/124083.rs create mode 100644 tests/crashes/124151.rs create mode 100644 tests/crashes/124164.rs diff --git a/tests/crashes/103708.rs b/tests/crashes/103708.rs new file mode 100644 index 0000000000000..f3154279cf54a --- /dev/null +++ b/tests/crashes/103708.rs @@ -0,0 +1,16 @@ +//@ known-bug: #103708 +#![feature(min_specialization)] + +trait MySpecTrait { + fn f(); +} + +impl<'a, T: ?Sized> MySpecTrait for T { + default fn f() {} +} + +impl<'a, T: ?Sized> MySpecTrait for &'a T { + fn f() {} +} + +fn main() {} diff --git a/tests/crashes/104685.rs b/tests/crashes/104685.rs new file mode 100644 index 0000000000000..25ddbb2efaa2e --- /dev/null +++ b/tests/crashes/104685.rs @@ -0,0 +1,15 @@ +//@ known-bug: #104685 +//@ compile-flags: -Zextra-const-ub-checks +#![feature(extern_types)] + +extern { + pub type ExternType; +} + +extern "C" { + pub static EXTERN: ExternType; +} + +pub static EMPTY: () = unsafe { &EXTERN; }; + +fn main() {} diff --git a/tests/crashes/105249.rs b/tests/crashes/105249.rs new file mode 100644 index 0000000000000..592ed5b6dbc8f --- /dev/null +++ b/tests/crashes/105249.rs @@ -0,0 +1,16 @@ +//@ known-bug: #105249 +//@ compile-flags: -Zpolymorphize=on + +trait Foo { + fn print<'a>(&'a self) where T: 'a { println!("foo"); } +} + +impl<'a> Foo<&'a ()> for () { } + +trait Bar: for<'a> Foo<&'a ()> { } + +impl Bar for () {} + +fn main() { + (&() as &dyn Bar).print(); // Segfault +} diff --git a/tests/crashes/115994.rs b/tests/crashes/115994.rs new file mode 100644 index 0000000000000..23d1507136f7c --- /dev/null +++ b/tests/crashes/115994.rs @@ -0,0 +1,17 @@ +//@ known-bug: #115994 +//@ compile-flags: -Cdebuginfo=2 --crate-type lib + +// To prevent "overflow while adding drop-check rules". +use std::mem::ManuallyDrop; + +pub enum Foo { + Leaf(U), + + Branch(BoxedFoo>), +} + +pub type BoxedFoo = ManuallyDrop>>; + +pub fn test() -> Foo { + todo!() +} diff --git a/tests/crashes/116721.rs b/tests/crashes/116721.rs new file mode 100644 index 0000000000000..fc1a6530bc82b --- /dev/null +++ b/tests/crashes/116721.rs @@ -0,0 +1,9 @@ +//@ known-bug: #116721 +//@ compile-flags: -Zmir-opt-level=3 --emit=mir +fn hey(it: &[T]) +where + [T]: Clone, +{ +} + +fn main() {} diff --git a/tests/crashes/118244.rs b/tests/crashes/118244.rs new file mode 100644 index 0000000000000..bfa1f5b7dd489 --- /dev/null +++ b/tests/crashes/118244.rs @@ -0,0 +1,22 @@ +//@ known-bug: #118244 +//@ compile-flags: -Cdebuginfo=2 + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] +struct Inner; +impl Inner where [(); N + M]: { + fn i() -> Self { + Self + } +} + +struct Outer(Inner) where [(); A + (B * 2)]:; +impl Outer where [(); A + (B * 2)]: { + fn o() -> Self { + Self(Inner::i()) + } +} + +fn main() { + Outer::<1, 1>::o(); +} diff --git a/tests/crashes/124083.rs b/tests/crashes/124083.rs new file mode 100644 index 0000000000000..e9cbf3f708614 --- /dev/null +++ b/tests/crashes/124083.rs @@ -0,0 +1,9 @@ +//@ known-bug: #124083 + +struct Outest(&'a ()); + +fn make() -> Outest {} + +fn main() { + if let Outest("foo") = make() {} +} diff --git a/tests/crashes/124151.rs b/tests/crashes/124151.rs new file mode 100644 index 0000000000000..5e55ac2aa943c --- /dev/null +++ b/tests/crashes/124151.rs @@ -0,0 +1,14 @@ +//@ known-bug: #124151 +#![feature(generic_const_exprs)] + +use std::ops::Add; + +pub struct Dimension; + +pub struct Quantity(S); + +impl Add for Quantity {} + +pub fn add(x: Quantity) -> Quantity { + x + y +} diff --git a/tests/crashes/124164.rs b/tests/crashes/124164.rs new file mode 100644 index 0000000000000..8c9b4bddbe80d --- /dev/null +++ b/tests/crashes/124164.rs @@ -0,0 +1,4 @@ +//@ known-bug: #124164 +static S_COUNT: = std::sync::atomic::AtomicUsize::new(0); + +fn main() {}