diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index 0b336109921..e5dd5729d89 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -303,8 +303,6 @@ const_eval_remainder_overflow = overflow in signed remainder (dividing MIN by -1) const_eval_scalar_size_mismatch = scalar size mismatch: expected {$target_size} bytes but got {$data_size} bytes instead -const_eval_size_of_unsized = - size_of called on unsized type `{$ty}` const_eval_size_overflow = overflow computing total size of `{$name}` diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 3a4e2648b80..4362cae7ed7 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -862,7 +862,6 @@ fn diagnostic_message(&self) -> DiagnosticMessage { InvalidProgramInfo::FnAbiAdjustForForeignAbi(_) => { rustc_middle::error::middle_adjust_for_foreign_abi_error } - InvalidProgramInfo::SizeOfUnsizedType(_) => const_eval_size_of_unsized, InvalidProgramInfo::ConstPropNonsense => { panic!("We had const-prop nonsense, this should never be printed") } @@ -890,9 +889,6 @@ fn add_args( builder.set_arg("arch", arch); builder.set_arg("abi", abi.name()); } - InvalidProgramInfo::SizeOfUnsizedType(ty) => { - builder.set_arg("ty", ty); - } } } } diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index f04c73105d2..0740894a4ff 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -269,13 +269,10 @@ pub fn eval_rvalue_into_place( let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?; let layout = self.layout_of(ty)?; if let mir::NullOp::SizeOf | mir::NullOp::AlignOf = null_op && layout.is_unsized() { - // FIXME: This should be a span_bug, but const generics can run MIR - // that is not properly type-checked yet (#97477). - self.tcx.sess.delay_span_bug( + span_bug!( self.frame().current_span(), - format!("{null_op:?} MIR operator called for unsized type {ty}"), + "{null_op:?} MIR operator called for unsized type {ty}", ); - throw_inval!(SizeOfUnsizedType(ty)); } let val = match null_op { mir::NullOp::SizeOf => layout.size.bytes(), diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 2e46bfc1a38..e6ef5a41ee0 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -184,8 +184,6 @@ pub enum InvalidProgramInfo<'tcx> { /// (which unfortunately typeck does not reject). /// Not using `FnAbiError` as that contains a nested `LayoutError`. FnAbiAdjustForForeignAbi(call::AdjustForForeignAbiError), - /// SizeOf of unsized type was requested. - SizeOfUnsizedType(Ty<'tcx>), /// We are runnning into a nonsense situation due to ConstProp violating our invariants. ConstPropNonsense, } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index c1987420417..3d237eb25cc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1645,7 +1645,7 @@ fn check_expected_errors(&self, expected_errors: Vec, proc_res: & if self.props.known_bug { if !expected_errors.is_empty() { self.fatal_proc_rec( - "`known_bug` tests should not have an expected errors", + "`known_bug` tests should not have an expected error", proc_res, ); } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-80742.rs b/tests/ui/const-generics/generic_const_exprs/issue-80742.rs index 275f6995302..6b2a0153f51 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.rs @@ -1,4 +1,9 @@ // check-fail +// known-bug: #97477 +// failure-status: 101 +// normalize-stderr-test "note: .*\n\n" -> "" +// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +// rustc-env:RUST_BACKTRACE=0 // This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place @@ -27,6 +32,5 @@ pub fn new(val: T) -> Inline { } fn main() { - let dst = Inline::::new(0); //~ ERROR - //~^ ERROR + let dst = Inline::::new(0); } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr b/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr index dc3a400cbaa..79ed82e02e0 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr @@ -1,71 +1,10 @@ -error[E0080]: evaluation of `Inline::::{constant#0}` failed +error: internal compiler error: compiler/rustc_const_eval/src/interpret/step.rs:272:21: SizeOf MIR operator called for unsized type dyn Debug --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: size_of called on unsized type `dyn Debug` - | -note: inside `std::mem::size_of::` - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `Inline::::{constant#0}` - --> $DIR/issue-80742.rs:22:10 - | -LL | [u8; size_of::() + 1]: , - | ^^^^^^^^^^^^^^ -error[E0599]: the function or associated item `new` exists for struct `Inline`, but its trait bounds were not satisfied - --> $DIR/issue-80742.rs:30:36 - | -LL | struct Inline - | ---------------- function or associated item `new` not found for this struct -... -LL | let dst = Inline::::new(0); - | ^^^ function or associated item cannot be called on `Inline` due to unsatisfied trait bounds - --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL - | - = note: doesn't satisfy `dyn Debug: Sized` - | -note: trait bound `dyn Debug: Sized` was not satisfied - --> $DIR/issue-80742.rs:20:6 - | -LL | impl Inline - | ^ --------- - | | - | unsatisfied trait bound introduced here -help: consider relaxing the type parameter's implicit `Sized` bound - | -LL | impl Inline - | ++++++++ +Box +query stack during panic: +#0 [eval_to_allocation_raw] const-evaluating + checking `::{constant#0}` +#1 [eval_to_valtree] evaluating type-level constant +end of query stack +error: aborting due to previous error -error[E0080]: evaluation of `Inline::::{constant#0}` failed - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: size_of called on unsized type `dyn Debug` - | -note: inside `std::mem::size_of::` - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: inside `Inline::::{constant#0}` - --> $DIR/issue-80742.rs:14:10 - | -LL | [u8; size_of::() + 1]: , - | ^^^^^^^^^^^^^^ - -error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/issue-80742.rs:30:15 - | -LL | let dst = Inline::::new(0); - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `dyn Debug` -note: required by a bound in `Inline` - --> $DIR/issue-80742.rs:12:15 - | -LL | struct Inline - | ^ required by this bound in `Inline` -help: consider relaxing the implicit `Sized` restriction - | -LL | struct Inline - | ++++++++ - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0080, E0277, E0599. -For more information about an error, try `rustc --explain E0080`.