/// Free-form case. Only for errors that are never caught!
Unsupported(String),
- /// FIXME(#64506) Error used to work around accessing projections of
- /// uninhabited types.
- UninhabitedValue,
-
// -- Everything below is not categorized yet --
FunctionAbiMismatch(Abi, Abi),
FunctionArgMismatch(Ty<'tcx>, Ty<'tcx>),
not a power of two"),
Unsupported(ref msg) =>
write!(f, "{}", msg),
- UninhabitedValue =>
- write!(f, "tried to use an uninhabited value"),
}
}
}
});
(present_variants.next(), present_variants.next())
};
- if present_first.is_none() {
- // Uninhabited because it has no variants, or only absent ones.
- return tcx.layout_raw(param_env.and(tcx.types.never));
- }
+ let present_first = if present_first.is_none() {
+ if def.is_enum() {
+ // Uninhabited because it has no variants, or only absent ones.
+ return tcx.layout_raw(param_env.and(tcx.types.never));
+ } else {
+ // if it's a struct, still compute a layout so that we can still compute the
+ // field offsets
+ Some(VariantIdx::new(0))
+ }
+ } else {
+ present_first
+ };
let is_struct = !def.is_enum() ||
// Only one variant is present.
use rustc::mir::interpret::truncate;
use rustc::ty::{self, Ty};
use rustc::ty::layout::{
- self, Size, Abi, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt
+ self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt
};
use rustc::ty::TypeFoldable;
layout::FieldPlacement::Array { stride, .. } => {
let len = base.len(self)?;
if field >= len {
- // This can be violated because this runs during promotion on code where the
- // type system has not yet ensured that such things don't happen.
+ // This can be violated because the index (field) can be a runtime value
+ // provided by the user.
debug!("tried to access element {} of array/slice with length {}", field, len);
throw_panic!(BoundsCheck { len, index: field });
}
stride * field
}
layout::FieldPlacement::Union(count) => {
- // FIXME(#64506) `UninhabitedValue` can be removed when this issue is resolved
- if base.layout.abi == Abi::Uninhabited {
- throw_unsup!(UninhabitedValue);
- }
assert!(field < count as u64,
- "Tried to access field {} of union with {} fields", field, count);
+ "Tried to access field {} of union {:#?} with {} fields",
+ field, base.layout, count);
// Offset is always 0
Size::from_bytes(0)
}