From 28f60ff9a4f11432ad5c2910a706522f04e0f3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Apr 2024 21:27:42 +0200 Subject: [PATCH 1/3] add test for #121413 Fixes #121413 --- .../consts/const_refs_to_static-ice-121413.rs | 16 +++++++ .../const_refs_to_static-ice-121413.stderr | 46 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/ui/consts/const_refs_to_static-ice-121413.rs create mode 100644 tests/ui/consts/const_refs_to_static-ice-121413.stderr diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.rs b/tests/ui/consts/const_refs_to_static-ice-121413.rs new file mode 100644 index 0000000000000..8a24fb799b6b8 --- /dev/null +++ b/tests/ui/consts/const_refs_to_static-ice-121413.rs @@ -0,0 +1,16 @@ +// ICE: ImmTy { imm: Scalar(alloc1), ty: *const dyn Sync } input to a fat-to-thin cast (*const dyn Sync -> *const usize +// or with -Zextra-const-ub-checks: expected wide pointer extra data (e.g. slice length or trait object vtable) +// issue: rust-lang/rust#121413 +//@ compile-flags: -Zextra-const-ub-checks +// ignore-tidy-linelength +#![feature(const_refs_to_static)] +const REF_INTERIOR_MUT: &usize = { + static FOO: Sync = AtomicUsize::new(0); + //~^ ERROR failed to resolve: use of undeclared type `AtomicUsize` + //~| WARN trait objects without an explicit `dyn` are deprecated + //~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time + //~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + unsafe { &*(&FOO as *const _ as *const usize) } +}; +pub fn main() {} diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.stderr b/tests/ui/consts/const_refs_to_static-ice-121413.stderr new file mode 100644 index 0000000000000..c977c698a92e9 --- /dev/null +++ b/tests/ui/consts/const_refs_to_static-ice-121413.stderr @@ -0,0 +1,46 @@ +error[E0433]: failed to resolve: use of undeclared type `AtomicUsize` + --> $DIR/const_refs_to_static-ice-121413.rs:8:24 + | +LL | static FOO: Sync = AtomicUsize::new(0); + | ^^^^^^^^^^^ use of undeclared type `AtomicUsize` + | +help: consider importing this struct + | +LL + use std::sync::atomic::AtomicUsize; + | + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/const_refs_to_static-ice-121413.rs:8:17 + | +LL | static FOO: Sync = AtomicUsize::new(0); + | ^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` on by default +help: if this is an object-safe trait, use `dyn` + | +LL | static FOO: dyn Sync = AtomicUsize::new(0); + | +++ + +error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time + --> $DIR/const_refs_to_static-ice-121413.rs:8:17 + | +LL | static FOO: Sync = AtomicUsize::new(0); + | ^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Sync + 'static)` + +error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time + --> $DIR/const_refs_to_static-ice-121413.rs:8:24 + | +LL | static FOO: Sync = AtomicUsize::new(0); + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Sync + 'static)` + = note: constant expressions must have a statically known size + +error: aborting due to 3 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0277, E0433. +For more information about an error, try `rustc --explain E0277`. From 751f662b703d27e028769722a8a47e02d3948b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Apr 2024 21:31:21 +0200 Subject: [PATCH 2/3] add test for ice #121463 Fixes #121463 --- ...T-struct-pattern-box-pattern-ice-121463.rs | 12 +++++++++++ ...ruct-pattern-box-pattern-ice-121463.stderr | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs create mode 100644 tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr diff --git a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs new file mode 100644 index 0000000000000..cf927e34fb418 --- /dev/null +++ b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs @@ -0,0 +1,12 @@ +// issue rust-lang/rust#121463 +// ICE non-ADT in struct pattern +#![feature(box_patterns)] + +fn main() { + let mut a = E::StructVar { boxed: Box::new(5_i32) }; + //~^ ERROR failed to resolve: use of undeclared type `E` + match a { + E::StructVar { box boxed } => { } + //~^ ERROR failed to resolve: use of undeclared type `E` + } +} diff --git a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr new file mode 100644 index 0000000000000..349546606a57e --- /dev/null +++ b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr @@ -0,0 +1,21 @@ +error[E0433]: failed to resolve: use of undeclared type `E` + --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:6:17 + | +LL | let mut a = E::StructVar { boxed: Box::new(5_i32) }; + | ^ + | | + | use of undeclared type `E` + | help: a trait with a similar name exists: `Eq` + +error[E0433]: failed to resolve: use of undeclared type `E` + --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:9:9 + | +LL | E::StructVar { box boxed } => { } + | ^ + | | + | use of undeclared type `E` + | help: a trait with a similar name exists: `Eq` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. From a42adf2f9549eedb715b027e3ba7794bddab127e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Apr 2024 21:43:47 +0200 Subject: [PATCH 3/3] add test for ICE caused by using feature(generic_const_exprs) #114463 Fixes #114463 --- .../cannot-convert-refree-ice-114463.rs | 10 ++++++++++ .../cannot-convert-refree-ice-114463.stderr | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.stderr diff --git a/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.rs b/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.rs new file mode 100644 index 0000000000000..2ce998e9fd9cf --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.rs @@ -0,0 +1,10 @@ +// issue: rust-lang/rust#114463 +// ICE cannot convert `ReFree ..` to a region vid +#![feature(generic_const_exprs)] +//~^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes +fn bug<'a>() { + [(); (|_: &'a u8| (), 0).1]; + //~^ ERROR cannot capture late-bound lifetime in constant +} + +pub fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.stderr b/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.stderr new file mode 100644 index 0000000000000..e4845405ec816 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/cannot-convert-refree-ice-114463.stderr @@ -0,0 +1,19 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/cannot-convert-refree-ice-114463.rs:3:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: cannot capture late-bound lifetime in constant + --> $DIR/cannot-convert-refree-ice-114463.rs:6:16 + | +LL | fn bug<'a>() { + | -- lifetime defined here +LL | [(); (|_: &'a u8| (), 0).1]; + | ^^ + +error: aborting due to 1 previous error; 1 warning emitted +