};
use super::{
- OpTy, MPlaceTy, Machine, EvalContext, ValueVisitor, Operand,
+ OpTy, Machine, EvalContext, ValueVisitor,
};
macro_rules! validation_failure {
_ => false,
}
} => {
- let mplace = match *op {
- // it's a ZST, the memory content cannot matter
- Operand::Immediate(_) if op.layout.is_zst() =>
- // invent an aligned mplace
- MPlaceTy::dangling(op.layout, self.ecx),
- // FIXME: what about single element arrays? They can be Scalar layout I think
- Operand::Immediate(_) => bug!("non-ZST array/slice cannot be immediate"),
- Operand::Indirect(_) => op.to_mem_place(),
- };
+ if op.layout.is_zst() {
+ return Ok(());
+ }
+ // non-ZST array cannot be immediate, slices are never immediate
+ let mplace = op.to_mem_place();
// This is the length of the array/slice.
let len = mplace.len(self.ecx)?;
+ // zero length slices have nothing to be checked
+ if len == 0 {
+ return Ok(());
+ }
// This is the element type size.
let ty_size = self.ecx.layout_of(tys)?.size;
// This is the size in bytes of the whole array.
let size = ty_size * len;
- if op.layout.is_zst() {
- return self.ecx.memory.check_align(mplace.ptr, op.layout.align);
- }
let ptr = mplace.ptr.to_ptr()?;
// NOTE: Keep this in sync with the handling of integer and float
--- /dev/null
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/validate_never_arrays.rs:3:1
+ |
+LL | const FOO: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR undefined behavior
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>[0]
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.