diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 1b99f54719fb4..2a03a840eb1aa 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -449,9 +449,16 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // all. That said, we have to allow calling functions inside a `const trait`. These // *are* const-checked! if !ecx.tcx.is_const_fn(def) || find_attr!(ecx.tcx, def, RustcDoNotConstCheck) { - // We certainly do *not* want to actually call the fn - // though, so be sure we return here. - throw_unsup_format!("calling non-const function `{}`", instance) + // We certainly do *not* want to actually call this fn. const-checking should have + // prevented this, but this can be reached with unleashed-miri, so make testing + // simpler by avoiding ICEs there. (Technically this can still ICE if miri-unleash + // was set in a dependency rather than the current crate. That's okay, it's an + // internal unstable feature.) + if ecx.tcx.sess.opts.unstable_opts.unleash_the_miri_inside_of_you { + throw_unsup_format!("calling non-const function `{}`", instance) + } else { + span_bug!(ecx.cur_span(), "calling non-const function `{}`", instance) + } } } diff --git a/tests/ui/consts/const-eval/do_not_const_check.rs b/tests/ui/consts/const-eval/do_not_const_check.rs index ced2557bffd19..7ed6ca1491f26 100644 --- a/tests/ui/consts/const-eval/do_not_const_check.rs +++ b/tests/ui/consts/const-eval/do_not_const_check.rs @@ -1,5 +1,17 @@ //! Ensure that we refuse to run a do_not_const_check function, even if the body *would* const-check //! at the moment. + +//@ rustc-env:RUSTC_ICE=0 +//@ failure-status: 101 +//@ normalize-stderr: "note: compiler flags.*\n\n" -> "" +//@ normalize-stderr: "note: rustc.*running on.*" -> "note: rustc {version} running on {platform}" +//@ normalize-stderr: "thread 'rustc'.*panicked.*:\n.*\n" -> "" +//@ normalize-stderr: " +\d{1,}: .*\n" -> "" +//@ normalize-stderr: " + at .*\n" -> "" +//@ normalize-stderr: " +.*omitted.*frames?.*\n" -> "" +//@ normalize-stderr: ".*note: Some details are omitted.*\n" -> "" +//@ normalize-stderr: "(internal compiler error: ).*(compiler/[^:]+):\d+:\d+: " -> "$1$2:LL:CC: " + #![feature(rustc_attrs, intrinsics)] #[rustc_do_not_const_check] diff --git a/tests/ui/consts/const-eval/do_not_const_check.stderr b/tests/ui/consts/const-eval/do_not_const_check.stderr index 7b91d75298e06..7db40e7ab0114 100644 --- a/tests/ui/consts/const-eval/do_not_const_check.stderr +++ b/tests/ui/consts/const-eval/do_not_const_check.stderr @@ -1,17 +1,40 @@ -error[E0080]: calling non-const function `mostly_harmless` - --> $DIR/do_not_const_check.rs:9:5 +error: internal compiler error: compiler/rustc_const_eval/src/const_eval/machine.rs:LL:CC: calling non-const function `mostly_harmless` + --> $DIR/do_not_const_check.rs:21:5 | -LL | const _: () = { LL | mostly_harmless(); - | ^^^^^^^^^^^^^^^^^ evaluation of `_` failed here + | ^^^^^^^^^^^^^^^^^ -error[E0080]: calling non-const function `integer_min::` - --> $DIR/do_not_const_check.rs:22:5 + +stack backtrace: + +note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly + +note: rustc {version} running on {platform} + +query stack during panic: +#0 [eval_to_allocation_raw] const-evaluating + checking `_` +#1 [eval_to_const_value_raw] simplifying constant for the type system `_` +#2 [eval_to_const_value_raw] simplifying constant for the type system `_` +#3 [analysis] running analysis passes on crate `do_not_const_check` +end of query stack +error: internal compiler error: compiler/rustc_const_eval/src/const_eval/machine.rs:LL:CC: calling non-const function `integer_min::` + --> $DIR/do_not_const_check.rs:34:5 | -LL | const _: () = { LL | integer_min(0, 1); - | ^^^^^^^^^^^^^^^^^ evaluation of `_` failed here + | ^^^^^^^^^^^^^^^^^ + + +stack backtrace: + +note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly + +note: rustc {version} running on {platform} +query stack during panic: +#0 [eval_to_allocation_raw] const-evaluating + checking `_` +#1 [eval_to_const_value_raw] simplifying constant for the type system `_` +#2 [eval_to_const_value_raw] simplifying constant for the type system `_` +#3 [analysis] running analysis passes on crate `do_not_const_check` +end of query stack error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.rs b/tests/ui/consts/qualif-indirect-mutation-fail.rs index 00c9d4900f5f6..26d251788c3ab 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.rs +++ b/tests/ui/consts/qualif-indirect-mutation-fail.rs @@ -13,26 +13,30 @@ pub const fn f() { let _ = &mut a.1; } -// Mutable borrow of a type with drop impl. -pub const A1: () = { - let mut x = None; //~ ERROR destructor of - let mut y = Some(NotConstDestruct); - let a = &mut x; - let b = &mut y; - std::mem::swap(a, b); - std::mem::forget(y); -}; //~ ERROR calling non-const function `::drop` +// FIXME: we make these associated consts to work around +// . +impl NotConstDestruct { + // Mutable borrow of a type with drop impl. + pub const A1: () = { + let mut x = None; //~ ERROR destructor of + let mut y = Some(NotConstDestruct); + let a = &mut x; + let b = &mut y; + std::mem::swap(a, b); + std::mem::forget(y); + }; -// Mutable borrow of a type with drop impl. -pub const A2: () = { - let mut x = None; - let mut y = Some(NotConstDestruct); - let a = &mut x; - let b = &mut y; - std::mem::swap(a, b); - std::mem::forget(y); - let _z = x; //~ ERROR destructor of -}; //~ ERROR calling non-const function `::drop` + // Mutable borrow of a type with drop impl. + pub const A2: () = { + let mut x = None; + let mut y = Some(NotConstDestruct); + let a = &mut x; + let b = &mut y; + std::mem::swap(a, b); + std::mem::forget(y); + let _z = x; //~ ERROR destructor of + }; +} // Shared borrow of a type that might be !Freeze and Drop. pub const fn g1() { diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr index aef0bed72d892..2301490065d45 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr +++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr @@ -1,46 +1,3 @@ -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:18:9 - | -LL | let mut x = None; - | ^^^^^ the destructor for this type cannot be evaluated in constants -... -LL | }; - | - value is dropped here - -error[E0080]: calling non-const function `::drop` - --> $DIR/qualif-indirect-mutation-fail.rs:24:1 - | -LL | pub const A1: () = { -... -LL | }; - | ^ evaluation of `A1` failed inside this call - | -note: inside `std::ptr::drop_glue::> - shim(Some(Option))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `std::ptr::drop_glue:: - shim(Some(NotConstDestruct))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - -error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:34:9 - | -LL | let _z = x; - | ^^ the destructor for this type cannot be evaluated in constants -LL | }; - | - value is dropped here - -error[E0080]: calling non-const function `::drop` - --> $DIR/qualif-indirect-mutation-fail.rs:35:1 - | -LL | pub const A2: () = { -... -LL | }; - | ^ evaluation of `A2` failed inside this call - | -note: inside `std::ptr::drop_glue::> - shim(Some(Option))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL -note: inside `std::ptr::drop_glue:: - shim(Some(NotConstDestruct))` - --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL - error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time --> $DIR/qualif-indirect-mutation-fail.rs:12:9 | @@ -50,8 +7,25 @@ LL | let _ = &mut a.1; LL | } | - value is dropped here +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:21:13 + | +LL | let mut x = None; + | ^^^^^ the destructor for this type cannot be evaluated in constants +... +LL | }; + | - value is dropped here + +error[E0493]: destructor of `Option` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:37:13 + | +LL | let _z = x; + | ^^ the destructor for this type cannot be evaluated in constants +LL | }; + | - value is dropped here + error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:39:9 + --> $DIR/qualif-indirect-mutation-fail.rs:43:9 | LL | let x: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -60,7 +34,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:47:9 + --> $DIR/qualif-indirect-mutation-fail.rs:51:9 | LL | let _y = x; | ^^ the destructor for this type cannot be evaluated in constant functions @@ -68,7 +42,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:55:9 + --> $DIR/qualif-indirect-mutation-fail.rs:59:9 | LL | let mut y: Option = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions @@ -77,7 +51,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:52:9 + --> $DIR/qualif-indirect-mutation-fail.rs:56:9 | LL | let mut x: Option = None; | ^^^^^ the destructor for this type cannot be evaluated in constant functions @@ -86,7 +60,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:65:9 + --> $DIR/qualif-indirect-mutation-fail.rs:69:9 | LL | let y: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -95,7 +69,7 @@ LL | } | - value is dropped here error[E0493]: destructor of `Option` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:62:9 + --> $DIR/qualif-indirect-mutation-fail.rs:66:9 | LL | let x: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions @@ -103,7 +77,6 @@ LL | let x: Option = None; LL | } | - value is dropped here -error: aborting due to 11 previous errors +error: aborting due to 9 previous errors -Some errors have detailed explanations: E0080, E0493. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0493`.