From 023939b627b7dc93b01471f7d41fb8553ddb4ffa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:59:24 +0200 Subject: Merging upstream version 1.73.0+dfsg1. Signed-off-by: Daniel Baumann --- .../inline-const/instance-doesnt-depend-on-type.rs | 10 +++++++ tests/ui/inline-const/interpolated.rs | 32 ++++++++++++++++++++++ tests/ui/inline-const/pat-match-fndef.rs | 13 +++++++++ tests/ui/inline-const/pat-match-fndef.stderr | 17 ++++++++++++ tests/ui/inline-const/required-const.rs | 13 +++++++++ tests/ui/inline-const/required-const.stderr | 11 ++++++++ 6 files changed, 96 insertions(+) create mode 100644 tests/ui/inline-const/instance-doesnt-depend-on-type.rs create mode 100644 tests/ui/inline-const/interpolated.rs create mode 100644 tests/ui/inline-const/pat-match-fndef.rs create mode 100644 tests/ui/inline-const/pat-match-fndef.stderr create mode 100644 tests/ui/inline-const/required-const.rs create mode 100644 tests/ui/inline-const/required-const.stderr (limited to 'tests/ui/inline-const') diff --git a/tests/ui/inline-const/instance-doesnt-depend-on-type.rs b/tests/ui/inline-const/instance-doesnt-depend-on-type.rs new file mode 100644 index 000000000..bc739785c --- /dev/null +++ b/tests/ui/inline-const/instance-doesnt-depend-on-type.rs @@ -0,0 +1,10 @@ +// check-pass +// issue: 114660 + +#![feature(inline_const)] + +fn main() { + const { core::mem::transmute:: }; + // Don't resolve the instance of this inline constant to be an intrinsic, + // even if the type of the constant is `extern "intrinsic" fn(u8) -> u8`. +} diff --git a/tests/ui/inline-const/interpolated.rs b/tests/ui/inline-const/interpolated.rs new file mode 100644 index 000000000..3fcc621c9 --- /dev/null +++ b/tests/ui/inline-const/interpolated.rs @@ -0,0 +1,32 @@ +// check-pass + +#![feature(inline_const)] + +// This used to be unsupported since the parser first tries to check if we have +// any nested items, and then checks for statements (and expressions). The heuristic +// that we were using to detect the beginning of a const item was incorrect, so +// this used to fail. +macro_rules! m { + ($b:block) => { + fn foo() { + const $b + } + } +} + +// This has worked since inline-consts were implemented, since the position that +// the const block is located at doesn't support nested items (e.g. because +// `let x = const X: u32 = 1;` is invalid), so there's no ambiguity parsing the +// inline const. +macro_rules! m2 { + ($b:block) => { + fn foo2() { + let _ = const $b; + } + } +} + +m!({}); +m2!({}); + +fn main() {} diff --git a/tests/ui/inline-const/pat-match-fndef.rs b/tests/ui/inline-const/pat-match-fndef.rs new file mode 100644 index 000000000..fbd4dc66c --- /dev/null +++ b/tests/ui/inline-const/pat-match-fndef.rs @@ -0,0 +1,13 @@ +#![feature(inline_const_pat)] +//~^ WARN the feature `inline_const_pat` is incomplete + +fn uwu() {} + +fn main() { + let x = []; + match x[123] { + const { uwu } => {} + //~^ ERROR `fn() {uwu}` cannot be used in patterns + _ => {} + } +} diff --git a/tests/ui/inline-const/pat-match-fndef.stderr b/tests/ui/inline-const/pat-match-fndef.stderr new file mode 100644 index 000000000..c94782b17 --- /dev/null +++ b/tests/ui/inline-const/pat-match-fndef.stderr @@ -0,0 +1,17 @@ +warning: the feature `inline_const_pat` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/pat-match-fndef.rs:1:12 + | +LL | #![feature(inline_const_pat)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #76001 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: `fn() {uwu}` cannot be used in patterns + --> $DIR/pat-match-fndef.rs:9:9 + | +LL | const { uwu } => {} + | ^^^^^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted + diff --git a/tests/ui/inline-const/required-const.rs b/tests/ui/inline-const/required-const.rs new file mode 100644 index 000000000..048341066 --- /dev/null +++ b/tests/ui/inline-const/required-const.rs @@ -0,0 +1,13 @@ +// build-fail +// compile-flags: -Zmir-opt-level=3 +#![feature(inline_const)] + +fn foo() { + if false { + const { panic!() } //~ ERROR E0080 + } +} + +fn main() { + foo::(); +} diff --git a/tests/ui/inline-const/required-const.stderr b/tests/ui/inline-const/required-const.stderr new file mode 100644 index 000000000..d6948e7ac --- /dev/null +++ b/tests/ui/inline-const/required-const.stderr @@ -0,0 +1,11 @@ +error[E0080]: evaluation of `foo::::{constant#0}` failed + --> $DIR/required-const.rs:7:17 + | +LL | const { panic!() } + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/required-const.rs:7:17 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. -- cgit v1.2.3