diff options
Diffstat (limited to 'tests/ui/inline-const')
19 files changed, 212 insertions, 12 deletions
diff --git a/tests/ui/inline-const/const-expr-generic-err2.stderr b/tests/ui/inline-const/const-expr-generic-err2.stderr index 00b716cd2..5876a6c9e 100644 --- a/tests/ui/inline-const/const-expr-generic-err2.stderr +++ b/tests/ui/inline-const/const-expr-generic-err2.stderr @@ -6,5 +6,5 @@ LL | let _ = [0u8; const { std::mem::size_of::<T>() }]; | = note: this may fail depending on what value the parameter takes -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/inline-const/const-expr-lifetime-err.stderr b/tests/ui/inline-const/const-expr-lifetime-err.stderr index 443fcf89c..75877bc09 100644 --- a/tests/ui/inline-const/const-expr-lifetime-err.stderr +++ b/tests/ui/inline-const/const-expr-lifetime-err.stderr @@ -14,6 +14,6 @@ LL | LL | } | - `y` dropped here while still borrowed -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0597`. diff --git a/tests/ui/inline-const/elided-lifetime-being-infer-vars.rs b/tests/ui/inline-const/elided-lifetime-being-infer-vars.rs new file mode 100644 index 000000000..5661db4a2 --- /dev/null +++ b/tests/ui/inline-const/elided-lifetime-being-infer-vars.rs @@ -0,0 +1,11 @@ +// check-pass + +#![feature(inline_const)] + +fn main() { + let _my_usize = const { + let a = 10_usize; + let b: &'_ usize = &a; + *b + }; +} diff --git a/tests/ui/inline-const/expr-unsafe-err.mir.stderr b/tests/ui/inline-const/expr-unsafe-err.mir.stderr index 1bec41e2e..ebd18f89d 100644 --- a/tests/ui/inline-const/expr-unsafe-err.mir.stderr +++ b/tests/ui/inline-const/expr-unsafe-err.mir.stderr @@ -6,6 +6,6 @@ LL | require_unsafe(); | = note: consult the function's documentation for information on how to avoid undefined behavior -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/inline-const/expr-unsafe-err.thir.stderr b/tests/ui/inline-const/expr-unsafe-err.thir.stderr index c971e8afb..45f850d1f 100644 --- a/tests/ui/inline-const/expr-unsafe-err.thir.stderr +++ b/tests/ui/inline-const/expr-unsafe-err.thir.stderr @@ -6,6 +6,6 @@ LL | require_unsafe(); | = note: consult the function's documentation for information on how to avoid undefined behavior -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/inline-const/expr-unsafe.thir.stderr b/tests/ui/inline-const/expr-unsafe.thir.stderr index 4737444fb..1ab6e42fb 100644 --- a/tests/ui/inline-const/expr-unsafe.thir.stderr +++ b/tests/ui/inline-const/expr-unsafe.thir.stderr @@ -1,9 +1,6 @@ warning: unnecessary `unsafe` block --> $DIR/expr-unsafe.rs:12:13 | -LL | unsafe { - | ------ because it's nested under this `unsafe` block -... LL | unsafe {} | ^^^^^^ unnecessary `unsafe` block | diff --git a/tests/ui/inline-const/expr-with-block-err.stderr b/tests/ui/inline-const/expr-with-block-err.stderr index 6f7408f4e..a46d73950 100644 --- a/tests/ui/inline-const/expr-with-block-err.stderr +++ b/tests/ui/inline-const/expr-with-block-err.stderr @@ -4,6 +4,6 @@ error[E0308]: mismatched types LL | const { 2 } - const { 1 }; | ^ expected `()`, found integer -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0308`. 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..02c4a60b6 --- /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 1 previous error; 1 warning emitted + diff --git a/tests/ui/inline-const/pat-unsafe-err.rs b/tests/ui/inline-const/pat-unsafe-err.rs index e290b438c..6df281c6d 100644 --- a/tests/ui/inline-const/pat-unsafe-err.rs +++ b/tests/ui/inline-const/pat-unsafe-err.rs @@ -1,11 +1,13 @@ -// ignore-test This is currently broken // revisions: mir thir +// [mir]ignore-test This is currently broken // [thir]compile-flags: -Z thir-unsafeck #![allow(incomplete_features)] #![feature(inline_const_pat)] -const unsafe fn require_unsafe() -> usize { 1 } +const unsafe fn require_unsafe() -> usize { + 1 +} fn main() { match () { @@ -14,4 +16,12 @@ fn main() { //~^ ERROR [E0133] } => (), } + + match 1 { + const { + require_unsafe() + //~^ ERROR [E0133] + }..=4 => (), + _ => (), + } } diff --git a/tests/ui/inline-const/pat-unsafe-err.thir.stderr b/tests/ui/inline-const/pat-unsafe-err.thir.stderr new file mode 100644 index 000000000..48a2cb4c7 --- /dev/null +++ b/tests/ui/inline-const/pat-unsafe-err.thir.stderr @@ -0,0 +1,19 @@ +error[E0133]: call to unsafe function `require_unsafe` is unsafe and requires unsafe function or block + --> $DIR/pat-unsafe-err.rs:15:13 + | +LL | require_unsafe(); + | ^^^^^^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior + +error[E0133]: call to unsafe function `require_unsafe` is unsafe and requires unsafe function or block + --> $DIR/pat-unsafe-err.rs:22:13 + | +LL | require_unsafe() + | ^^^^^^^^^^^^^^^^ call to unsafe function + | + = note: consult the function's documentation for information on how to avoid undefined behavior + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/inline-const/pat-unsafe.rs b/tests/ui/inline-const/pat-unsafe.rs index bcf7f6e01..36f8632af 100644 --- a/tests/ui/inline-const/pat-unsafe.rs +++ b/tests/ui/inline-const/pat-unsafe.rs @@ -1,13 +1,15 @@ -// ignore-test This is currently broken // check-pass // revisions: mir thir +// [mir]ignore-test This is currently broken // [thir]compile-flags: -Z thir-unsafeck #![allow(incomplete_features)] #![warn(unused_unsafe)] #![feature(inline_const_pat)] -const unsafe fn require_unsafe() -> usize { 1 } +const unsafe fn require_unsafe() -> usize { + 1 +} fn main() { unsafe { @@ -18,5 +20,14 @@ fn main() { //~^ WARNING unnecessary `unsafe` block } => (), } + + match 1 { + const { + unsafe {} + //~^ WARNING unnecessary `unsafe` block + require_unsafe() + }..=4 => (), + _ => (), + } } } diff --git a/tests/ui/inline-const/pat-unsafe.thir.stderr b/tests/ui/inline-const/pat-unsafe.thir.stderr new file mode 100644 index 000000000..0318b3ff2 --- /dev/null +++ b/tests/ui/inline-const/pat-unsafe.thir.stderr @@ -0,0 +1,20 @@ +warning: unnecessary `unsafe` block + --> $DIR/pat-unsafe.rs:19:17 + | +LL | unsafe {} + | ^^^^^^ unnecessary `unsafe` block + | +note: the lint level is defined here + --> $DIR/pat-unsafe.rs:7:9 + | +LL | #![warn(unused_unsafe)] + | ^^^^^^^^^^^^^ + +warning: unnecessary `unsafe` block + --> $DIR/pat-unsafe.rs:26:17 + | +LL | unsafe {} + | ^^^^^^ unnecessary `unsafe` block + +warning: 2 warnings emitted + diff --git a/tests/ui/inline-const/promotion.rs b/tests/ui/inline-const/promotion.rs new file mode 100644 index 000000000..242959c6b --- /dev/null +++ b/tests/ui/inline-const/promotion.rs @@ -0,0 +1,22 @@ +#![feature(inline_const)] +#![allow(arithmetic_overflow, unconditional_panic)] + +// The only way to have promoteds that fail is in `const fn` called from `const`/`static`. +// Make sure that in a `const` block, we do not promote such calls. +const fn div_by_zero() -> i32 { + 1 / 0 +} + +const fn mk_false() -> bool { + false +} + +fn main() { + let v = const { + if mk_false() { + let _x: &'static i32 = &div_by_zero(); + //~^ ERROR: temporary value dropped while borrowed + } + 42 + }; +} diff --git a/tests/ui/inline-const/promotion.stderr b/tests/ui/inline-const/promotion.stderr new file mode 100644 index 000000000..7f06b9781 --- /dev/null +++ b/tests/ui/inline-const/promotion.stderr @@ -0,0 +1,14 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/promotion.rs:17:37 + | +LL | let _x: &'static i32 = &div_by_zero(); + | ------------ ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0716`. 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..cd8602018 --- /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 1 previous error + +For more information about this error, try `rustc --explain E0080`. |