Rollup merge of #81185 - osa1:fix_80742, r=oli-obk
Fix ICE in mir when evaluating SizeOf on unsized type Not quite ready yet. This tries to fix #80742 as discussed on [Zulip topic][1], by using `delay_span_bug`. I don't understand what `delay_span_bug` does. It seems like my error message is never used. With this patch, in this program: ```rust #![allow(incomplete_features)] #![feature(const_evaluatable_checked)] #![feature(const_generics)] use std::fmt::Debug; use std::marker::PhantomData; use std::mem::size_of; struct Inline<T> where [u8; size_of::<T>() + 1]: , { _phantom: PhantomData<T>, buf: [u8; size_of::<T>() + 1], } impl<T> Inline<T> where [u8; size_of::<T>() + 1]: , { pub fn new(val: T) -> Inline<T> { todo!() } } fn main() { let dst = Inline::<dyn Debug>::new(0); // line 27 } ``` these errors are printed, both for line 27 (annotated line above): - "no function or associated item named `new` found for struct `Inline<dyn Debug>` in the current scope" - "the size for values of type `dyn Debug` cannot be known at compilation time" Second error makes sense, but I'm not sure about the first one and why it's even printed. Finally, I'm not sure about the span passing in `const_eval`. [1]: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Help.20fixing.20.2380742
This commit is contained in:
commit
bc950c85c5
3 changed files with 82 additions and 4 deletions
|
@ -264,10 +264,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
NullaryOp(mir::NullOp::SizeOf, ty) => {
|
||||
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty);
|
||||
let layout = self.layout_of(ty)?;
|
||||
assert!(
|
||||
!layout.is_unsized(),
|
||||
"SizeOf nullary MIR operator called for unsized type"
|
||||
);
|
||||
if layout.is_unsized() {
|
||||
// FIXME: This should be a span_bug (#80742)
|
||||
self.tcx.sess.delay_span_bug(
|
||||
self.frame().current_span(),
|
||||
&format!("SizeOf nullary MIR operator called for unsized type {}", ty),
|
||||
);
|
||||
}
|
||||
self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), dest)?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue