summaryrefslogtreecommitdiffstats
path: root/tests/ui/inline-const
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
commit023939b627b7dc93b01471f7d41fb8553ddb4ffa (patch)
tree60fc59477c605c72b0a1051409062ddecc43f877 /tests/ui/inline-const
parentAdding debian version 1.72.1+dfsg1-1. (diff)
downloadrustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.tar.xz
rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/inline-const')
-rw-r--r--tests/ui/inline-const/instance-doesnt-depend-on-type.rs10
-rw-r--r--tests/ui/inline-const/interpolated.rs32
-rw-r--r--tests/ui/inline-const/pat-match-fndef.rs13
-rw-r--r--tests/ui/inline-const/pat-match-fndef.stderr17
-rw-r--r--tests/ui/inline-const/required-const.rs13
-rw-r--r--tests/ui/inline-const/required-const.stderr11
6 files changed, 96 insertions, 0 deletions
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::<u8, u8> };
+ // 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 <https://github.com/rust-lang/rust/issues/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<T>() {
+ if false {
+ const { panic!() } //~ ERROR E0080
+ }
+}
+
+fn main() {
+ foo::<i32>();
+}
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::<i32>::{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`.