Auto merge of #149649 - wesleywiser:revert_147793, r=wesleywiser

[beta] Revert "Replace NullOp::SizeOf and NullOp::AlignOf by lang items."

Totally clean revert, tests pass on my local machine.

Fixes rust-lang/rust#149081 on 1.92 beta

cc `@lcnr` `@BoxyUwU` `@jieyouxu` `@cjgillot`
This commit is contained in:
bors 2025-12-05 04:37:58 +00:00
commit 5cd7b3150d
89 changed files with 766 additions and 757 deletions

View file

@ -1046,6 +1046,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
let trait_ref =
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [ty]);
self.prove_trait_ref(
trait_ref,
location.to_locations(),
ConstraintCategory::SizedBound,
);
}
&Rvalue::NullaryOp(NullOp::ContractChecks, _) => {}
&Rvalue::NullaryOp(NullOp::UbChecks, _) => {}

View file

@ -72,6 +72,10 @@ pub fn debug_tuple() -> DebugTuple {
DebugTuple(())
}
pub fn size_of<T>() -> usize {
intrinsics::size_of::<T>()
}
pub fn use_size_of() -> usize {
size_of::<u64>()
}

View file

@ -6,7 +6,6 @@
extern_types,
decl_macro,
rustc_attrs,
rustc_private,
transparent_unions,
auto_traits,
freeze_impls,
@ -595,7 +594,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
impl<T> Box<T> {
pub fn new(val: T) -> Box<T> {
unsafe {
let size = size_of::<T>();
let size = intrinsics::size_of::<T>();
let ptr = libc::malloc(size);
intrinsics::copy(&val as *const T as *const u8, ptr, size);
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
@ -647,11 +646,11 @@ pub mod intrinsics {
#[rustc_intrinsic]
pub fn abort() -> !;
#[rustc_intrinsic]
pub const fn size_of<T>() -> usize;
pub fn size_of<T>() -> usize;
#[rustc_intrinsic]
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
#[rustc_intrinsic]
pub const fn align_of<T>() -> usize;
pub fn align_of<T>() -> usize;
#[rustc_intrinsic]
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
#[rustc_intrinsic]
@ -716,23 +715,6 @@ impl<T> Index<usize> for [T] {
}
}
pub const fn size_of<T>() -> usize {
<T as SizedTypeProperties>::SIZE
}
pub const fn align_of<T>() -> usize {
<T as SizedTypeProperties>::ALIGN
}
trait SizedTypeProperties: Sized {
#[lang = "mem_size_const"]
const SIZE: usize = intrinsics::size_of::<Self>();
#[lang = "mem_align_const"]
const ALIGN: usize = intrinsics::align_of::<Self>();
}
impl<T> SizedTypeProperties for T {}
extern "C" {
type VaListImpl;
}

View file

@ -109,10 +109,10 @@ fn start<T: Termination + 'static>(
puts(*argv as *const i8);
}
unsafe {
puts(*((argv as usize + size_of::<*const u8>()) as *const *const i8));
puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8));
}
unsafe {
puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const i8));
puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8));
}
}
@ -213,8 +213,8 @@ fn main() {
assert_eq!(intrinsics::size_of_val(a) as u8, 16);
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
assert_eq!(align_of::<u16>() as u8, 2);
assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8);
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
let u8_needs_drop = const { intrinsics::needs_drop::<u8>() };
assert!(!u8_needs_drop);

View file

@ -833,6 +833,8 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
let layout = fx.layout_of(fx.monomorphize(ty));
let val = match null_op {
NullOp::SizeOf => layout.size.bytes(),
NullOp::AlignOf => layout.align.bytes(),
NullOp::OffsetOf(fields) => fx
.tcx
.offset_of_subfield(

View file

@ -611,6 +611,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let ty = self.monomorphize(ty);
let layout = bx.cx().layout_of(ty);
let val = match null_op {
mir::NullOp::SizeOf => {
assert!(bx.cx().type_is_sized(ty));
let val = layout.size.bytes();
bx.cx().const_usize(val)
}
mir::NullOp::AlignOf => {
assert!(bx.cx().type_is_sized(ty));
let val = layout.align.bytes();
bx.cx().const_usize(val)
}
mir::NullOp::OffsetOf(fields) => {
let val = bx
.tcx()

View file

@ -646,7 +646,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
Rvalue::Cast(_, _, _) => {}
Rvalue::NullaryOp(
NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks,
NullOp::SizeOf
| NullOp::AlignOf
| NullOp::OffsetOf(_)
| NullOp::UbChecks
| NullOp::ContractChecks,
_,
) => {}
Rvalue::ShallowInitBox(_, _) => {}

View file

@ -414,6 +414,8 @@ fn report_eval_error<'tcx>(
let (error, backtrace) = error.into_parts();
backtrace.print_backtrace();
let instance = with_no_trimmed_paths!(cid.instance.to_string());
super::report(
ecx,
error,
@ -428,7 +430,7 @@ fn report_eval_error<'tcx>(
diag.subdiagnostic(frame);
}
// Add after the frame rendering above, as it adds its own `instance` args.
diag.arg("instance", with_no_trimmed_paths!(cid.instance.to_string()));
diag.arg("instance", instance);
diag.arg("num_frames", num_frames);
},
)

View file

@ -156,24 +156,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let b_ty = self.read_type_id(&args[1])?;
self.write_scalar(Scalar::from_bool(a_ty == b_ty), dest)?;
}
sym::size_of => {
let tp_ty = instance.args.type_at(0);
let layout = self.layout_of(tp_ty)?;
if !layout.is_sized() {
span_bug!(self.cur_span(), "unsized type for `size_of`");
}
let val = layout.size.bytes();
self.write_scalar(Scalar::from_target_usize(val, self), dest)?;
}
sym::align_of => {
let tp_ty = instance.args.type_at(0);
let layout = self.layout_of(tp_ty)?;
if !layout.is_sized() {
span_bug!(self.cur_span(), "unsized type for `align_of`");
}
let val = layout.align.bytes();
self.write_scalar(Scalar::from_target_usize(val, self), dest)?;
}
sym::variant_count => {
let tp_ty = instance.args.type_at(0);
let ty = match tp_ty.kind() {

View file

@ -517,6 +517,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let usize_layout = || self.layout_of(self.tcx.types.usize).unwrap();
interp_ok(match null_op {
SizeOf => {
if !layout.is_sized() {
span_bug!(self.cur_span(), "unsized type for `NullaryOp::SizeOf`");
}
let val = layout.size.bytes();
ImmTy::from_uint(val, usize_layout())
}
AlignOf => {
if !layout.is_sized() {
span_bug!(self.cur_span(), "unsized type for `NullaryOp::AlignOf`");
}
let val = layout.align.bytes();
ImmTy::from_uint(val, usize_layout())
}
OffsetOf(fields) => {
let val =
self.tcx.offset_of_subfield(self.typing_env, layout, fields.iter()).bytes();

View file

@ -168,8 +168,6 @@ language_item_table! {
MetaSized, sym::meta_sized, meta_sized_trait, Target::Trait, GenericRequirement::Exact(0);
PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0);
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
AlignOf, sym::mem_align_const, align_const, Target::AssocConst, GenericRequirement::Exact(0);
SizeOf, sym::mem_size_const, size_const, Target::AssocConst, GenericRequirement::Exact(0);
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);

View file

@ -1092,6 +1092,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
NullaryOp(ref op, ref t) => {
let t = with_no_trimmed_paths!(format!("{}", t));
match op {
NullOp::SizeOf => write!(fmt, "SizeOf({t})"),
NullOp::AlignOf => write!(fmt, "AlignOf({t})"),
NullOp::OffsetOf(fields) => write!(fmt, "OffsetOf({t}, {fields:?})"),
NullOp::UbChecks => write!(fmt, "UbChecks()"),
NullOp::ContractChecks => write!(fmt, "ContractChecks()"),

View file

@ -597,18 +597,6 @@ impl<'tcx> Operand<'tcx> {
}))
}
/// Convenience helper to make a constant that refers to the given `DefId` and args. Since this
/// is used to synthesize MIR, assumes `user_ty` is None.
pub fn unevaluated_constant(
tcx: TyCtxt<'tcx>,
def_id: DefId,
args: &[GenericArg<'tcx>],
span: Span,
) -> Self {
let const_ = Const::from_unevaluated(tcx, def_id).instantiate(tcx, args);
Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
}
pub fn is_move(&self) -> bool {
matches!(self, Operand::Move(..))
}
@ -794,7 +782,9 @@ impl<'tcx> Rvalue<'tcx> {
op.ty(tcx, arg_ty)
}
Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => tcx.types.usize,
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => {
tcx.types.usize
}
Rvalue::NullaryOp(NullOp::ContractChecks, _)
| Rvalue::NullaryOp(NullOp::UbChecks, _) => tcx.types.bool,
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
@ -863,7 +853,7 @@ impl BorrowKind {
impl<'tcx> NullOp<'tcx> {
pub fn ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self {
NullOp::OffsetOf(_) => tcx.types.usize,
NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) => tcx.types.usize,
NullOp::UbChecks | NullOp::ContractChecks => tcx.types.bool,
}
}

View file

@ -1563,6 +1563,10 @@ pub enum AggregateKind<'tcx> {
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum NullOp<'tcx> {
/// Returns the size of a value of that type
SizeOf,
/// Returns the minimum alignment of a type
AlignOf,
/// Returns the offset of a field
OffsetOf(&'tcx List<(VariantIdx, FieldIdx)>),
/// Returns whether we should perform some UB-checking at runtime.

View file

@ -126,12 +126,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let tcx = this.tcx;
let source_info = this.source_info(expr_span);
let size = tcx.require_lang_item(LangItem::SizeOf, expr_span);
let size = Operand::unevaluated_constant(tcx, size, &[value_ty.into()], expr_span);
let size = this.temp(tcx.types.usize, expr_span);
this.cfg.push_assign(
block,
source_info,
size,
Rvalue::NullaryOp(NullOp::SizeOf, value_ty),
);
let align = tcx.require_lang_item(LangItem::AlignOf, expr_span);
let align =
Operand::unevaluated_constant(tcx, align, &[value_ty.into()], expr_span);
let align = this.temp(tcx.types.usize, expr_span);
this.cfg.push_assign(
block,
source_info,
align,
Rvalue::NullaryOp(NullOp::AlignOf, value_ty),
);
// malloc some memory of suitable size and align:
let exchange_malloc = Operand::function_handle(
@ -148,8 +157,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
TerminatorKind::Call {
func: exchange_malloc,
args: [
Spanned { node: size, span: DUMMY_SP },
Spanned { node: align, span: DUMMY_SP },
Spanned { node: Operand::Move(size), span: DUMMY_SP },
Spanned { node: Operand::Move(align), span: DUMMY_SP },
]
.into(),
destination: storage,

View file

@ -452,7 +452,11 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
| Rvalue::RawPtr(..)
| Rvalue::Discriminant(..)
| Rvalue::NullaryOp(
NullOp::OffsetOf(..) | NullOp::UbChecks | NullOp::ContractChecks,
NullOp::SizeOf
| NullOp::AlignOf
| NullOp::OffsetOf(..)
| NullOp::UbChecks
| NullOp::ContractChecks,
_,
) => {}
}

View file

@ -1,5 +1,4 @@
use rustc_abi::Align;
use rustc_hir::LangItem;
use rustc_index::IndexVec;
use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::visit::PlaceContext;
@ -60,9 +59,10 @@ fn insert_alignment_check<'tcx>(
stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((addr, rvalue)))));
// Get the alignment of the pointee
let align_def_id = tcx.require_lang_item(LangItem::AlignOf, source_info.span);
let alignment =
Operand::unevaluated_constant(tcx, align_def_id, &[pointee_ty.into()], source_info.span);
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
let rvalue = Rvalue::NullaryOp(NullOp::AlignOf, pointee_ty);
stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((alignment, rvalue)))));
// Subtract 1 from the alignment to get the alignment mask
let alignment_mask =
@ -76,7 +76,7 @@ fn insert_alignment_check<'tcx>(
source_info,
StatementKind::Assign(Box::new((
alignment_mask,
Rvalue::BinaryOp(BinOp::Sub, Box::new((alignment.clone(), one))),
Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(alignment), one))),
))),
));
@ -141,7 +141,7 @@ fn insert_alignment_check<'tcx>(
PointerCheck {
cond: Operand::Copy(is_ok),
assert_kind: Box::new(AssertKind::MisalignedPointerDereference {
required: alignment,
required: Operand::Copy(alignment),
found: Operand::Copy(addr),
}),
}

View file

@ -1,4 +1,3 @@
use rustc_hir::LangItem;
use rustc_index::IndexVec;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext};
use rustc_middle::mir::*;
@ -63,23 +62,35 @@ fn insert_null_check<'tcx>(
Operand::Constant(Box::new(ConstOperand {
span: source_info.span,
user_ty: None,
const_: Const::from_bool(tcx, true),
const_: Const::Val(ConstValue::from_bool(true), tcx.types.bool),
}))
}
// Other usages of null pointers only are UB if the pointee is not a ZST.
_ => {
let size_of = tcx.require_lang_item(LangItem::SizeOf, source_info.span);
let size_of =
Operand::unevaluated_constant(tcx, size_of, &[pointee_ty.into()], source_info.span);
let pointee_should_be_checked =
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
let rvalue = Rvalue::BinaryOp(BinOp::Ne, Box::new((size_of, zero.clone())));
let rvalue = Rvalue::NullaryOp(NullOp::SizeOf, pointee_ty);
let sizeof_pointee =
local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into();
stmts.push(Statement::new(
source_info,
StatementKind::Assign(Box::new((pointee_should_be_checked, rvalue))),
StatementKind::Assign(Box::new((sizeof_pointee, rvalue))),
));
Operand::Copy(pointee_should_be_checked.into())
// Check that the pointee is not a ZST.
let is_pointee_not_zst =
local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into();
stmts.push(Statement::new(
source_info,
StatementKind::Assign(Box::new((
is_pointee_not_zst,
Rvalue::BinaryOp(
BinOp::Ne,
Box::new((Operand::Copy(sizeof_pointee), zero.clone())),
),
))),
));
// Pointer needs to be checked only if pointee is not a ZST.
Operand::Copy(is_pointee_not_zst)
}
};

View file

@ -466,6 +466,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
return ValueOrPlace::Value(FlatSet::Top);
};
let val = match null_op {
NullOp::SizeOf if layout.is_sized() => layout.size.bytes(),
NullOp::AlignOf if layout.is_sized() => layout.align.bytes(),
NullOp::OffsetOf(fields) => self
.ecx
.tcx

View file

@ -670,7 +670,14 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
}
NullaryOp(null_op, arg_ty) => {
let arg_layout = self.ecx.layout_of(arg_ty).ok()?;
if let NullOp::SizeOf | NullOp::AlignOf = null_op
&& arg_layout.is_unsized()
{
return None;
}
let val = match null_op {
NullOp::SizeOf => arg_layout.size.bytes(),
NullOp::AlignOf => arg_layout.align.bytes(),
NullOp::OffsetOf(fields) => self
.tcx
.offset_of_subfield(self.typing_env(), arg_layout, fields.iter())

View file

@ -264,7 +264,6 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
terminator: &mut Terminator<'tcx>,
statements: &mut Vec<Statement<'tcx>>,
) {
let source_info = terminator.source_info;
if let TerminatorKind::Call {
func, args, destination, target: Some(destination_block), ..
} = &terminator.kind
@ -273,16 +272,12 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
&& self.tcx.is_intrinsic(fn_def_id, sym::align_of_val)
&& let ty::Slice(elem_ty) = *generics.type_at(0).kind()
{
let align_def_id = self.tcx.require_lang_item(LangItem::AlignOf, source_info.span);
let align_const = Operand::unevaluated_constant(
self.tcx,
align_def_id,
&[elem_ty.into()],
source_info.span,
);
statements.push(Statement::new(
source_info,
StatementKind::Assign(Box::new((*destination, Rvalue::Use(align_const)))),
terminator.source_info,
StatementKind::Assign(Box::new((
*destination,
Rvalue::NullaryOp(NullOp::AlignOf, elem_ty),
))),
));
terminator.kind = TerminatorKind::Goto { target: *destination_block };
}

View file

@ -608,6 +608,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
NullaryOp(ref null_op, ty) => {
let op_layout = self.ecx.layout_of(ty).ok()?;
let val = match null_op {
NullOp::SizeOf => op_layout.size.bytes(),
NullOp::AlignOf => op_layout.align.bytes(),
NullOp::OffsetOf(fields) => self
.tcx
.offset_of_subfield(self.typing_env, op_layout, fields.iter())

View file

@ -139,6 +139,23 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
));
terminator.kind = TerminatorKind::Goto { target };
}
sym::size_of | sym::align_of => {
let target = target.unwrap();
let tp_ty = generic_args.type_at(0);
let null_op = match intrinsic.name {
sym::size_of => NullOp::SizeOf,
sym::align_of => NullOp::AlignOf,
_ => bug!("unexpected intrinsic"),
};
block.statements.push(Statement::new(
terminator.source_info,
StatementKind::Assign(Box::new((
*destination,
Rvalue::NullaryOp(null_op, tp_ty),
))),
));
terminator.kind = TerminatorKind::Goto { target };
}
sym::read_via_copy => {
let Ok([arg]) = take_array(args) else {
span_bug!(terminator.source_info.span, "Wrong number of arguments");

View file

@ -450,6 +450,8 @@ impl<'tcx> Validator<'_, 'tcx> {
}
Rvalue::NullaryOp(op, _) => match op {
NullOp::SizeOf => {}
NullOp::AlignOf => {}
NullOp::OffsetOf(_) => {}
NullOp::UbChecks => {}
NullOp::ContractChecks => {}

View file

@ -1478,7 +1478,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
Rvalue::Repeat(_, _)
| Rvalue::ThreadLocalRef(_)
| Rvalue::RawPtr(_, _)
| Rvalue::NullaryOp(NullOp::UbChecks | NullOp::ContractChecks, _)
| Rvalue::NullaryOp(
NullOp::SizeOf | NullOp::AlignOf | NullOp::UbChecks | NullOp::ContractChecks,
_,
)
| Rvalue::Discriminant(_) => {}
Rvalue::WrapUnsafeBinder(op, ty) => {

View file

@ -641,7 +641,9 @@ impl Rvalue {
.discriminant_ty()
.ok_or_else(|| error!("Expected a `RigidTy` but found: {place_ty:?}"))
}
Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => Ok(Ty::usize_ty()),
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => {
Ok(Ty::usize_ty())
}
Rvalue::NullaryOp(NullOp::ContractChecks, _)
| Rvalue::NullaryOp(NullOp::UbChecks, _) => Ok(Ty::bool_ty()),
Rvalue::Aggregate(ak, ops) => match *ak {
@ -1022,6 +1024,10 @@ pub enum CastKind {
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum NullOp {
/// Returns the size of a value of that type.
SizeOf,
/// Returns the minimum alignment of a type.
AlignOf,
/// Returns the offset of a field.
OffsetOf(Vec<(VariantIdx, FieldIdx)>),
/// cfg!(ub_checks), but at codegen time

View file

@ -323,6 +323,8 @@ impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> {
) -> Self::T {
use rustc_middle::mir::NullOp::*;
match self {
SizeOf => crate::mir::NullOp::SizeOf,
AlignOf => crate::mir::NullOp::AlignOf,
OffsetOf(indices) => crate::mir::NullOp::OffsetOf(
indices.iter().map(|idx| idx.stable(tables, cx)).collect(),
),

View file

@ -1387,13 +1387,11 @@ symbols! {
maybe_uninit,
maybe_uninit_uninit,
maybe_uninit_zeroed,
mem_align_const,
mem_align_of,
mem_discriminant,
mem_drop,
mem_forget,
mem_replace,
mem_size_const,
mem_size_of,
mem_size_of_val,
mem_swap,

View file

@ -333,7 +333,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
#[rustc_const_stable(feature = "const_mem_size_of", since = "1.24.0")]
#[rustc_diagnostic_item = "mem_size_of"]
pub const fn size_of<T>() -> usize {
<T as SizedTypeProperties>::SIZE
intrinsics::size_of::<T>()
}
/// Returns the size of the pointed-to value in bytes.
@ -441,7 +441,7 @@ pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(note = "use `align_of` instead", since = "1.2.0", suggestion = "align_of")]
pub fn min_align_of<T>() -> usize {
<T as SizedTypeProperties>::ALIGN
intrinsics::align_of::<T>()
}
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@ -488,7 +488,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
#[rustc_const_stable(feature = "const_align_of", since = "1.24.0")]
#[rustc_diagnostic_item = "mem_align_of"]
pub const fn align_of<T>() -> usize {
<T as SizedTypeProperties>::ALIGN
intrinsics::align_of::<T>()
}
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@ -1236,16 +1236,6 @@ pub const fn variant_count<T>() -> usize {
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
pub trait SizedTypeProperties: Sized {
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
#[lang = "mem_size_const"]
const SIZE: usize = intrinsics::size_of::<Self>();
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
#[lang = "mem_align_const"]
const ALIGN: usize = intrinsics::align_of::<Self>();
/// `true` if this type requires no storage.
/// `false` if its [size](size_of) is greater than zero.
///
@ -1273,7 +1263,7 @@ pub trait SizedTypeProperties: Sized {
/// ```
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
const IS_ZST: bool = Self::SIZE == 0;
const IS_ZST: bool = size_of::<Self>() == 0;
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
@ -1285,7 +1275,7 @@ pub trait SizedTypeProperties: Sized {
/// which is never allowed for a single object.
#[doc(hidden)]
#[unstable(feature = "sized_type_properties", issue = "none")]
const MAX_SLICE_LEN: usize = match Self::SIZE {
const MAX_SLICE_LEN: usize = match size_of::<Self>() {
0 => usize::MAX,
n => (isize::MAX as usize) / n,
};

View file

@ -194,7 +194,10 @@ fn check_rvalue<'tcx>(
))
}
},
Rvalue::NullaryOp(NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _)
Rvalue::NullaryOp(
NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks,
_,
)
| Rvalue::ShallowInitBox(_, _) => Ok(()),
Rvalue::UnaryOp(_, operand) => {
let ty = operand.ty(body, cx.tcx);

View file

@ -2,20 +2,29 @@ error[E0391]: cycle detected when computing layout of `S<S<()>>`
|
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
note: cycle used when const-evaluating + checking `core::mem::SizedTypeProperties::SIZE`
--> RUSTLIB/core/src/mem/mod.rs:LL:CC
|
LL | const SIZE: usize = intrinsics::size_of::<Self>();
| ^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0080]: a cycle occurred during layout computation
error: post-monomorphization error: a cycle occurred during layout computation
--> RUSTLIB/core/src/mem/mod.rs:LL:CC
|
LL | const SIZE: usize = intrinsics::size_of::<Self>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `<S<S<()>> as std::mem::SizedTypeProperties>::SIZE` failed here
LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ post-monomorphization error occurred here
|
= note: BACKTRACE:
= note: inside `std::mem::size_of::<S<S<()>>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC
note: inside `foo::<S<()>>`
--> tests/fail/layout_cycle.rs:LL:CC
|
LL | mem::size_of::<S<T>>()
| ^^^^^^^^^^^^^^^^^^^^^^
note: inside `main`
--> tests/fail/layout_cycle.rs:LL:CC
|
LL | println!("{}", foo::<S<()>>());
| ^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.

View file

@ -25,7 +25,7 @@ trait Copy {}
impl<T> Copy for *mut T {}
#[rustc_intrinsic]
const fn size_of<T>() -> usize {
fn size_of<T>() -> usize {
loop {}
}
@ -40,7 +40,7 @@ unsafe fn catch_unwind(
#[no_mangle]
pub fn ptr_size() -> usize {
// CHECK: ret [[PTR_SIZE:.*]]
const { size_of::<*mut u8>() }
size_of::<*mut u8>()
}
// CHECK-LABEL: @test_catch_unwind

View file

@ -24,7 +24,7 @@ trait Copy {}
impl<T> Copy for *mut T {}
#[rustc_intrinsic]
const fn size_of<T>() -> usize {
fn size_of<T>() -> usize {
loop {}
}
#[rustc_intrinsic]
@ -38,7 +38,7 @@ unsafe fn catch_unwind(
#[no_mangle]
pub fn ptr_size() -> usize {
// CHECK: ret [[PTR_SIZE:.*]]
const { size_of::<*mut u8>() }
size_of::<*mut u8>()
}
// CHECK-LABEL: @test_catch_unwind

17
tests/crashes/114663.rs Normal file
View file

@ -0,0 +1,17 @@
//@ known-bug: #114663
//@ edition:2021
#![feature(generic_const_exprs)]
use core::fmt::Debug;
struct Inline<T>
where
[u8; ::core::mem::size_of::<T>() + 1]:,
{
_phantom: PhantomData<T>,
}
fn main() {
let dst = Inline::<dyn Debug>::new(0); // BANG!
}

View file

@ -1,7 +1,5 @@
//! Regression test for #119729
//@ known-bug: #119729
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
trait Size<const N: usize> {}
@ -12,7 +10,3 @@ struct A<T: Size<8> + ?Sized> {
}
fn foo(x: A<dyn Send>) {}
//~^ ERROR mismatched types
//~| ERROR the size for values of type `(dyn Send + 'static)` cannot be known at compilation time
fn main() {}

View file

@ -1,5 +1,4 @@
//! Regression test for #136175
//@ known-bug: #136175
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
@ -11,5 +10,4 @@ where
fn main() {
let x: A<dyn Trait>;
//~^ ERROR the size for values of type `dyn Trait` cannot be known at compilation time
}

View file

@ -4,45 +4,49 @@
fn main() -> () {
let mut _0: ();
let _1: std::boxed::Box<S>;
let mut _2: *mut u8;
let mut _3: std::boxed::Box<S>;
let _4: ();
let mut _2: usize;
let mut _3: usize;
let mut _4: *mut u8;
let mut _5: std::boxed::Box<S>;
+ let mut _6: &mut std::boxed::Box<S>;
+ let mut _7: ();
+ let mut _8: *const S;
let _6: ();
let mut _7: std::boxed::Box<S>;
+ let mut _8: &mut std::boxed::Box<S>;
+ let mut _9: ();
+ let mut _10: *const S;
scope 1 {
debug x => _1;
}
bb0: {
StorageLive(_1);
_2 = alloc::alloc::exchange_malloc(const <S as std::mem::SizedTypeProperties>::SIZE, const <S as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
_2 = SizeOf(S);
_3 = AlignOf(S);
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
}
bb1: {
StorageLive(_3);
_3 = ShallowInitBox(move _2, S);
(*_3) = S::new() -> [return: bb2, unwind: bb8];
StorageLive(_5);
_5 = ShallowInitBox(move _4, S);
(*_5) = S::new() -> [return: bb2, unwind: bb8];
}
bb2: {
_1 = move _3;
- drop(_3) -> [return: bb3, unwind continue];
_1 = move _5;
- drop(_5) -> [return: bb3, unwind continue];
+ goto -> bb3;
}
bb3: {
StorageDead(_3);
StorageLive(_4);
StorageLive(_5);
_5 = move _1;
_4 = std::mem::drop::<Box<S>>(move _5) -> [return: bb4, unwind: bb6];
StorageDead(_5);
StorageLive(_6);
StorageLive(_7);
_7 = move _1;
_6 = std::mem::drop::<Box<S>>(move _7) -> [return: bb4, unwind: bb6];
}
bb4: {
StorageDead(_5);
StorageDead(_4);
StorageDead(_7);
StorageDead(_6);
_0 = const ();
- drop(_1) -> [return: bb5, unwind continue];
+ goto -> bb5;
@ -54,7 +58,7 @@
}
bb6 (cleanup): {
- drop(_5) -> [return: bb7, unwind terminate(cleanup)];
- drop(_7) -> [return: bb7, unwind terminate(cleanup)];
+ goto -> bb7;
}
@ -64,7 +68,7 @@
}
bb8 (cleanup): {
- drop(_3) -> [return: bb9, unwind terminate(cleanup)];
- drop(_5) -> [return: bb9, unwind terminate(cleanup)];
+ goto -> bb12;
}
@ -73,8 +77,8 @@
+ }
+
+ bb10 (cleanup): {
+ _6 = &mut _3;
+ _7 = <Box<S> as Drop>::drop(move _6) -> [return: bb9, unwind terminate(cleanup)];
+ _8 = &mut _5;
+ _9 = <Box<S> as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)];
+ }
+
+ bb11 (cleanup): {
@ -82,7 +86,7 @@
+ }
+
+ bb12 (cleanup): {
+ _8 = copy ((_3.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
+ _10 = copy ((_5.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
+ goto -> bb11;
}
}

View file

@ -4,55 +4,63 @@ fn move_out_by_subslice() -> () {
let mut _0: ();
let _1: [std::boxed::Box<i32>; 2];
let mut _2: std::boxed::Box<i32>;
let mut _3: *mut u8;
let mut _4: std::boxed::Box<i32>;
let mut _5: std::boxed::Box<i32>;
let mut _6: *mut u8;
let mut _3: usize;
let mut _4: usize;
let mut _5: *mut u8;
let mut _6: std::boxed::Box<i32>;
let mut _7: std::boxed::Box<i32>;
let mut _8: usize;
let mut _9: usize;
let mut _10: *mut u8;
let mut _11: std::boxed::Box<i32>;
scope 1 {
debug a => _1;
let _8: [std::boxed::Box<i32>; 2];
let _12: [std::boxed::Box<i32>; 2];
scope 2 {
debug _y => _8;
debug _y => _12;
}
}
bb0: {
StorageLive(_1);
StorageLive(_2);
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind: bb13];
_3 = SizeOf(i32);
_4 = AlignOf(i32);
_5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13];
}
bb1: {
StorageLive(_4);
_4 = ShallowInitBox(move _3, i32);
(*_4) = const 1_i32;
_2 = move _4;
drop(_4) -> [return: bb2, unwind: bb12];
StorageLive(_6);
_6 = ShallowInitBox(move _5, i32);
(*_6) = const 1_i32;
_2 = move _6;
drop(_6) -> [return: bb2, unwind: bb12];
}
bb2: {
StorageDead(_4);
StorageLive(_5);
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb3, unwind: bb12];
StorageDead(_6);
StorageLive(_7);
_8 = SizeOf(i32);
_9 = AlignOf(i32);
_10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12];
}
bb3: {
StorageLive(_7);
_7 = ShallowInitBox(move _6, i32);
(*_7) = const 2_i32;
_5 = move _7;
drop(_7) -> [return: bb4, unwind: bb11];
StorageLive(_11);
_11 = ShallowInitBox(move _10, i32);
(*_11) = const 2_i32;
_7 = move _11;
drop(_11) -> [return: bb4, unwind: bb11];
}
bb4: {
StorageDead(_7);
_1 = [move _2, move _5];
drop(_5) -> [return: bb5, unwind: bb12];
StorageDead(_11);
_1 = [move _2, move _7];
drop(_7) -> [return: bb5, unwind: bb12];
}
bb5: {
StorageDead(_5);
StorageDead(_7);
drop(_2) -> [return: bb6, unwind: bb13];
}
@ -60,10 +68,10 @@ fn move_out_by_subslice() -> () {
StorageDead(_2);
FakeRead(ForLet(None), _1);
PlaceMention(_1);
StorageLive(_8);
_8 = move _1[0..2];
StorageLive(_12);
_12 = move _1[0..2];
_0 = const ();
drop(_8) -> [return: bb8, unwind: bb10];
drop(_12) -> [return: bb8, unwind: bb10];
}
bb7: {
@ -72,7 +80,7 @@ fn move_out_by_subslice() -> () {
}
bb8: {
StorageDead(_8);
StorageDead(_12);
drop(_1) -> [return: bb9, unwind: bb13];
}
@ -86,7 +94,7 @@ fn move_out_by_subslice() -> () {
}
bb11 (cleanup): {
drop(_5) -> [return: bb12, unwind terminate(cleanup)];
drop(_7) -> [return: bb12, unwind terminate(cleanup)];
}
bb12 (cleanup): {

View file

@ -4,55 +4,63 @@ fn move_out_from_end() -> () {
let mut _0: ();
let _1: [std::boxed::Box<i32>; 2];
let mut _2: std::boxed::Box<i32>;
let mut _3: *mut u8;
let mut _4: std::boxed::Box<i32>;
let mut _5: std::boxed::Box<i32>;
let mut _6: *mut u8;
let mut _3: usize;
let mut _4: usize;
let mut _5: *mut u8;
let mut _6: std::boxed::Box<i32>;
let mut _7: std::boxed::Box<i32>;
let mut _8: usize;
let mut _9: usize;
let mut _10: *mut u8;
let mut _11: std::boxed::Box<i32>;
scope 1 {
debug a => _1;
let _8: std::boxed::Box<i32>;
let _12: std::boxed::Box<i32>;
scope 2 {
debug _y => _8;
debug _y => _12;
}
}
bb0: {
StorageLive(_1);
StorageLive(_2);
_3 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind: bb13];
_3 = SizeOf(i32);
_4 = AlignOf(i32);
_5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13];
}
bb1: {
StorageLive(_4);
_4 = ShallowInitBox(move _3, i32);
(*_4) = const 1_i32;
_2 = move _4;
drop(_4) -> [return: bb2, unwind: bb12];
StorageLive(_6);
_6 = ShallowInitBox(move _5, i32);
(*_6) = const 1_i32;
_2 = move _6;
drop(_6) -> [return: bb2, unwind: bb12];
}
bb2: {
StorageDead(_4);
StorageLive(_5);
_6 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb3, unwind: bb12];
StorageDead(_6);
StorageLive(_7);
_8 = SizeOf(i32);
_9 = AlignOf(i32);
_10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12];
}
bb3: {
StorageLive(_7);
_7 = ShallowInitBox(move _6, i32);
(*_7) = const 2_i32;
_5 = move _7;
drop(_7) -> [return: bb4, unwind: bb11];
StorageLive(_11);
_11 = ShallowInitBox(move _10, i32);
(*_11) = const 2_i32;
_7 = move _11;
drop(_11) -> [return: bb4, unwind: bb11];
}
bb4: {
StorageDead(_7);
_1 = [move _2, move _5];
drop(_5) -> [return: bb5, unwind: bb12];
StorageDead(_11);
_1 = [move _2, move _7];
drop(_7) -> [return: bb5, unwind: bb12];
}
bb5: {
StorageDead(_5);
StorageDead(_7);
drop(_2) -> [return: bb6, unwind: bb13];
}
@ -60,10 +68,10 @@ fn move_out_from_end() -> () {
StorageDead(_2);
FakeRead(ForLet(None), _1);
PlaceMention(_1);
StorageLive(_8);
_8 = move _1[1 of 2];
StorageLive(_12);
_12 = move _1[1 of 2];
_0 = const ();
drop(_8) -> [return: bb8, unwind: bb10];
drop(_12) -> [return: bb8, unwind: bb10];
}
bb7: {
@ -72,7 +80,7 @@ fn move_out_from_end() -> () {
}
bb8: {
StorageDead(_8);
StorageDead(_12);
drop(_1) -> [return: bb9, unwind: bb13];
}
@ -86,7 +94,7 @@ fn move_out_from_end() -> () {
}
bb11 (cleanup): {
drop(_5) -> [return: bb12, unwind terminate(cleanup)];
drop(_7) -> [return: bb12, unwind terminate(cleanup)];
}
bb12 (cleanup): {

View file

@ -6,13 +6,15 @@
let _1: i32;
let mut _2: i32;
let mut _3: std::boxed::Box<i32>;
let mut _4: *mut u8;
let mut _5: std::boxed::Box<i32>;
let mut _6: *const i32;
let mut _7: std::ptr::NonNull<i32>;
let mut _8: std::ptr::Unique<i32>;
let mut _9: *const i32;
let mut _10: *const i32;
let mut _4: usize;
let mut _5: usize;
let mut _6: *mut u8;
let mut _7: std::boxed::Box<i32>;
let mut _8: *const i32;
let mut _9: std::ptr::NonNull<i32>;
let mut _10: std::ptr::Unique<i32>;
let mut _11: *const i32;
let mut _12: *const i32;
scope 1 {
debug x => _1;
}
@ -22,26 +24,31 @@
- StorageLive(_2);
+ nop;
StorageLive(_3);
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind unreachable];
- _4 = SizeOf(i32);
- _5 = AlignOf(i32);
- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind unreachable];
+ _4 = const 4_usize;
+ _5 = const 4_usize;
+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind unreachable];
}
bb1: {
StorageLive(_5);
- _6 = move _4 as *const i32 (Transmute);
- _7 = NonNull::<i32> { pointer: move _6 };
- _8 = Unique::<i32> { pointer: move _7, _marker: const PhantomData::<i32> };
+ _6 = copy _4 as *const i32 (PtrToPtr);
+ _7 = NonNull::<i32> { pointer: copy _6 };
+ _8 = Unique::<i32> { pointer: copy _7, _marker: const PhantomData::<i32> };
_5 = Box::<i32>(move _8, const std::alloc::Global);
- _9 = copy ((_5.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
- (*_9) = const 42_i32;
+ _9 = copy _6;
+ (*_6) = const 42_i32;
_3 = move _5;
StorageDead(_5);
_10 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
_2 = copy (*_10);
StorageLive(_7);
- _8 = move _6 as *const i32 (Transmute);
- _9 = NonNull::<i32> { pointer: move _8 };
- _10 = Unique::<i32> { pointer: move _9, _marker: const PhantomData::<i32> };
+ _8 = copy _6 as *const i32 (PtrToPtr);
+ _9 = NonNull::<i32> { pointer: copy _8 };
+ _10 = Unique::<i32> { pointer: copy _9, _marker: const PhantomData::<i32> };
_7 = Box::<i32>(move _10, const std::alloc::Global);
- _11 = copy ((_7.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
- (*_11) = const 42_i32;
+ _11 = copy _8;
+ (*_8) = const 42_i32;
_3 = move _7;
StorageDead(_7);
_12 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
_2 = copy (*_12);
- _1 = Add(move _2, const 0_i32);
- StorageDead(_2);
+ _1 = copy _2;

View file

@ -6,13 +6,15 @@
let _1: i32;
let mut _2: i32;
let mut _3: std::boxed::Box<i32>;
let mut _4: *mut u8;
let mut _5: std::boxed::Box<i32>;
let mut _6: *const i32;
let mut _7: std::ptr::NonNull<i32>;
let mut _8: std::ptr::Unique<i32>;
let mut _9: *const i32;
let mut _10: *const i32;
let mut _4: usize;
let mut _5: usize;
let mut _6: *mut u8;
let mut _7: std::boxed::Box<i32>;
let mut _8: *const i32;
let mut _9: std::ptr::NonNull<i32>;
let mut _10: std::ptr::Unique<i32>;
let mut _11: *const i32;
let mut _12: *const i32;
scope 1 {
debug x => _1;
}
@ -22,26 +24,31 @@
- StorageLive(_2);
+ nop;
StorageLive(_3);
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
- _4 = SizeOf(i32);
- _5 = AlignOf(i32);
- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind continue];
+ _4 = const 4_usize;
+ _5 = const 4_usize;
+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind continue];
}
bb1: {
StorageLive(_5);
- _6 = move _4 as *const i32 (Transmute);
- _7 = NonNull::<i32> { pointer: move _6 };
- _8 = Unique::<i32> { pointer: move _7, _marker: const PhantomData::<i32> };
+ _6 = copy _4 as *const i32 (PtrToPtr);
+ _7 = NonNull::<i32> { pointer: copy _6 };
+ _8 = Unique::<i32> { pointer: copy _7, _marker: const PhantomData::<i32> };
_5 = Box::<i32>(move _8, const std::alloc::Global);
- _9 = copy ((_5.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
- (*_9) = const 42_i32;
+ _9 = copy _6;
+ (*_6) = const 42_i32;
_3 = move _5;
StorageDead(_5);
_10 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
_2 = copy (*_10);
StorageLive(_7);
- _8 = move _6 as *const i32 (Transmute);
- _9 = NonNull::<i32> { pointer: move _8 };
- _10 = Unique::<i32> { pointer: move _9, _marker: const PhantomData::<i32> };
+ _8 = copy _6 as *const i32 (PtrToPtr);
+ _9 = NonNull::<i32> { pointer: copy _8 };
+ _10 = Unique::<i32> { pointer: copy _9, _marker: const PhantomData::<i32> };
_7 = Box::<i32>(move _10, const std::alloc::Global);
- _11 = copy ((_7.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
- (*_11) = const 42_i32;
+ _11 = copy _8;
+ (*_8) = const 42_i32;
_3 = move _7;
StorageDead(_7);
_12 = copy ((_3.0: std::ptr::Unique<i32>).0: std::ptr::NonNull<i32>) as *const i32 (Transmute);
_2 = copy (*_12);
- _1 = Add(move _2, const 0_i32);
- StorageDead(_2);
+ _1 = copy _2;

View file

@ -11,8 +11,6 @@
let mut _9: *const [()];
let mut _10: std::boxed::Box<()>;
let mut _11: *const ();
let mut _16: usize;
let mut _17: usize;
let mut _27: usize;
scope 1 {
debug vp_ctx => _1;
@ -37,10 +35,12 @@
}
}
scope 5 (inlined Box::<()>::new) {
let mut _12: *mut u8;
let mut _13: *const ();
let mut _14: std::ptr::NonNull<()>;
let mut _15: std::ptr::Unique<()>;
let mut _12: usize;
let mut _13: usize;
let mut _14: *mut u8;
let mut _15: *const ();
let mut _16: std::ptr::NonNull<()>;
let mut _17: std::ptr::Unique<()>;
scope 6 (inlined alloc::alloc::exchange_malloc) {
let _18: std::alloc::Layout;
let mut _19: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
@ -85,11 +85,11 @@
StorageLive(_14);
StorageLive(_15);
StorageLive(_16);
- _16 = const <() as std::mem::SizedTypeProperties>::SIZE;
+ _16 = const 0_usize;
StorageLive(_17);
- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN;
+ _17 = const 1_usize;
- _12 = SizeOf(());
- _13 = AlignOf(());
+ _12 = const 0_usize;
+ _13 = const 1_usize;
StorageLive(_18);
StorageLive(_20);
StorageLive(_21);
@ -120,7 +120,7 @@
- StorageLive(_26);
+ nop;
_26 = copy _21 as *mut [u8] (Transmute);
_12 = copy _26 as *mut u8 (PtrToPtr);
_14 = copy _26 as *mut u8 (PtrToPtr);
- StorageDead(_26);
+ nop;
StorageDead(_19);
@ -129,15 +129,15 @@
StorageDead(_21);
StorageDead(_20);
StorageDead(_18);
- _15 = copy _14 as *const () (PtrToPtr);
+ _15 = copy _26 as *const () (PtrToPtr);
_16 = NonNull::<()> { pointer: copy _15 };
_17 = Unique::<()> { pointer: copy _16, _marker: const PhantomData::<()> };
_3 = Box::<()>(move _17, const std::alloc::Global);
- (*_15) = move _4;
+ (*_15) = const ();
StorageDead(_17);
StorageDead(_16);
- _13 = copy _12 as *const () (PtrToPtr);
+ _13 = copy _26 as *const () (PtrToPtr);
_14 = NonNull::<()> { pointer: copy _13 };
_15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> };
_3 = Box::<()>(move _15, const std::alloc::Global);
- (*_13) = move _4;
+ (*_13) = const ();
StorageDead(_15);
StorageDead(_14);
StorageDead(_13);
@ -183,15 +183,15 @@
}
bb5: {
- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable];
- _24 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable];
+ _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable];
}
bb6: {
StorageDead(_23);
StorageLive(_25);
- _25 = copy _17 as std::ptr::Alignment (Transmute);
- _18 = Layout { size: copy _16, align: move _25 };
- _25 = copy _13 as std::ptr::Alignment (Transmute);
- _18 = Layout { size: copy _12, align: move _25 };
+ _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0);
+ _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }};
StorageDead(_25);

View file

@ -11,8 +11,6 @@
let mut _9: *const [()];
let mut _10: std::boxed::Box<()>;
let mut _11: *const ();
let mut _16: usize;
let mut _17: usize;
let mut _27: usize;
scope 1 {
debug vp_ctx => _1;
@ -37,10 +35,12 @@
}
}
scope 5 (inlined Box::<()>::new) {
let mut _12: *mut u8;
let mut _13: *const ();
let mut _14: std::ptr::NonNull<()>;
let mut _15: std::ptr::Unique<()>;
let mut _12: usize;
let mut _13: usize;
let mut _14: *mut u8;
let mut _15: *const ();
let mut _16: std::ptr::NonNull<()>;
let mut _17: std::ptr::Unique<()>;
scope 6 (inlined alloc::alloc::exchange_malloc) {
let _18: std::alloc::Layout;
let mut _19: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
@ -85,11 +85,11 @@
StorageLive(_14);
StorageLive(_15);
StorageLive(_16);
- _16 = const <() as std::mem::SizedTypeProperties>::SIZE;
+ _16 = const 0_usize;
StorageLive(_17);
- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN;
+ _17 = const 1_usize;
- _12 = SizeOf(());
- _13 = AlignOf(());
+ _12 = const 0_usize;
+ _13 = const 1_usize;
StorageLive(_18);
StorageLive(_20);
StorageLive(_21);
@ -120,7 +120,7 @@
- StorageLive(_26);
+ nop;
_26 = copy _21 as *mut [u8] (Transmute);
_12 = copy _26 as *mut u8 (PtrToPtr);
_14 = copy _26 as *mut u8 (PtrToPtr);
- StorageDead(_26);
+ nop;
StorageDead(_19);
@ -129,15 +129,15 @@
StorageDead(_21);
StorageDead(_20);
StorageDead(_18);
- _15 = copy _14 as *const () (PtrToPtr);
+ _15 = copy _26 as *const () (PtrToPtr);
_16 = NonNull::<()> { pointer: copy _15 };
_17 = Unique::<()> { pointer: copy _16, _marker: const PhantomData::<()> };
_3 = Box::<()>(move _17, const std::alloc::Global);
- (*_15) = move _4;
+ (*_15) = const ();
StorageDead(_17);
StorageDead(_16);
- _13 = copy _12 as *const () (PtrToPtr);
+ _13 = copy _26 as *const () (PtrToPtr);
_14 = NonNull::<()> { pointer: copy _13 };
_15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> };
_3 = Box::<()>(move _15, const std::alloc::Global);
- (*_13) = move _4;
+ (*_13) = const ();
StorageDead(_15);
StorageDead(_14);
StorageDead(_13);
@ -183,15 +183,15 @@
}
bb5: {
- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable];
- _24 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable];
+ _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable];
}
bb6: {
StorageDead(_23);
StorageLive(_25);
- _25 = copy _17 as std::ptr::Alignment (Transmute);
- _18 = Layout { size: copy _16, align: move _25 };
- _25 = copy _13 as std::ptr::Alignment (Transmute);
- _18 = Layout { size: copy _12, align: move _25 };
+ _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0);
+ _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }};
StorageDead(_25);

View file

@ -10,7 +10,7 @@
StorageLive(_2);
_2 = &raw const (*_1);
- _0 = std::intrinsics::align_of_val::<[T]>(move _2) -> [return: bb1, unwind unreachable];
+ _0 = const <T as std::mem::SizedTypeProperties>::ALIGN;
+ _0 = AlignOf(T);
+ goto -> bb1;
}

View file

@ -7,6 +7,6 @@
// EMIT_MIR align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff
pub fn of_val_slice<T>(slice: &[T]) -> usize {
// CHECK-LABEL: fn of_val_slice(_1: &[T])
// CHECK: _0 = const <T as std::mem::SizedTypeProperties>::ALIGN;
// CHECK: _0 = AlignOf(T);
unsafe { core::intrinsics::align_of_val(slice) }
}

View file

@ -3,45 +3,49 @@
fn test() -> Option<Box<u32>> {
let mut _0: std::option::Option<std::boxed::Box<u32>>;
let mut _1: std::boxed::Box<u32>;
let mut _2: *mut u8;
let mut _3: std::boxed::Box<u32>;
let mut _4: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _5: std::option::Option<u32>;
let mut _6: isize;
let _7: std::option::Option<std::convert::Infallible>;
let mut _8: !;
let mut _9: std::option::Option<std::convert::Infallible>;
let _10: u32;
let mut _2: usize;
let mut _3: usize;
let mut _4: *mut u8;
let mut _5: std::boxed::Box<u32>;
let mut _6: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _7: std::option::Option<u32>;
let mut _8: isize;
let _9: std::option::Option<std::convert::Infallible>;
let mut _10: !;
let mut _11: std::option::Option<std::convert::Infallible>;
let _12: u32;
scope 1 {
debug residual => _7;
debug residual => _9;
scope 2 {
}
}
scope 3 {
debug val => _10;
debug val => _12;
scope 4 {
}
}
bb0: {
StorageLive(_1);
_2 = alloc::alloc::exchange_malloc(const <u32 as std::mem::SizedTypeProperties>::SIZE, const <u32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind: bb13];
_2 = SizeOf(u32);
_3 = AlignOf(u32);
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind: bb13];
}
bb1: {
StorageLive(_3);
_3 = ShallowInitBox(move _2, u32);
StorageLive(_4);
StorageLive(_5);
_5 = Option::<u32>::None;
_4 = <Option<u32> as Try>::branch(move _5) -> [return: bb2, unwind: bb12];
_5 = ShallowInitBox(move _4, u32);
StorageLive(_6);
StorageLive(_7);
_7 = Option::<u32>::None;
_6 = <Option<u32> as Try>::branch(move _7) -> [return: bb2, unwind: bb12];
}
bb2: {
StorageDead(_5);
PlaceMention(_4);
_6 = discriminant(_4);
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3];
StorageDead(_7);
PlaceMention(_6);
_8 = discriminant(_6);
switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3];
}
bb3: {
@ -49,44 +53,44 @@ fn test() -> Option<Box<u32>> {
}
bb4: {
StorageLive(_10);
_10 = copy ((_4 as Continue).0: u32);
(*_3) = copy _10;
StorageDead(_10);
_1 = move _3;
drop(_3) -> [return: bb7, unwind: bb11];
StorageLive(_12);
_12 = copy ((_6 as Continue).0: u32);
(*_5) = copy _12;
StorageDead(_12);
_1 = move _5;
drop(_5) -> [return: bb7, unwind: bb11];
}
bb5: {
StorageLive(_7);
_7 = copy ((_4 as Break).0: std::option::Option<std::convert::Infallible>);
StorageLive(_9);
_9 = copy _7;
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _9) -> [return: bb6, unwind: bb12];
_9 = copy ((_6 as Break).0: std::option::Option<std::convert::Infallible>);
StorageLive(_11);
_11 = copy _9;
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _11) -> [return: bb6, unwind: bb12];
}
bb6: {
StorageDead(_11);
StorageDead(_9);
StorageDead(_7);
drop(_3) -> [return: bb9, unwind: bb13];
drop(_5) -> [return: bb9, unwind: bb13];
}
bb7: {
StorageDead(_3);
StorageDead(_5);
_0 = Option::<Box<u32>>::Some(move _1);
drop(_1) -> [return: bb8, unwind: bb13];
}
bb8: {
StorageDead(_1);
StorageDead(_4);
StorageDead(_6);
goto -> bb10;
}
bb9: {
StorageDead(_3);
StorageDead(_5);
StorageDead(_1);
StorageDead(_4);
StorageDead(_6);
goto -> bb10;
}
@ -99,7 +103,7 @@ fn test() -> Option<Box<u32>> {
}
bb12 (cleanup): {
drop(_3) -> [return: bb13, unwind terminate(cleanup)];
drop(_5) -> [return: bb13, unwind terminate(cleanup)];
}
bb13 (cleanup): {

View file

@ -3,45 +3,49 @@
fn test() -> Option<Box<u32>> {
let mut _0: std::option::Option<std::boxed::Box<u32>>;
let mut _1: std::boxed::Box<u32>;
let mut _2: *mut u8;
let mut _3: std::boxed::Box<u32>;
let mut _4: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _5: std::option::Option<u32>;
let mut _6: isize;
let _7: std::option::Option<std::convert::Infallible>;
let mut _8: !;
let mut _9: std::option::Option<std::convert::Infallible>;
let _10: u32;
let mut _2: usize;
let mut _3: usize;
let mut _4: *mut u8;
let mut _5: std::boxed::Box<u32>;
let mut _6: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>;
let mut _7: std::option::Option<u32>;
let mut _8: isize;
let _9: std::option::Option<std::convert::Infallible>;
let mut _10: !;
let mut _11: std::option::Option<std::convert::Infallible>;
let _12: u32;
scope 1 {
debug residual => _7;
debug residual => _9;
scope 2 {
}
}
scope 3 {
debug val => _10;
debug val => _12;
scope 4 {
}
}
bb0: {
StorageLive(_1);
_2 = alloc::alloc::exchange_malloc(const <u32 as std::mem::SizedTypeProperties>::SIZE, const <u32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
_2 = SizeOf(u32);
_3 = AlignOf(u32);
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
}
bb1: {
StorageLive(_3);
_3 = ShallowInitBox(move _2, u32);
StorageLive(_4);
StorageLive(_5);
_5 = Option::<u32>::None;
_4 = <Option<u32> as Try>::branch(move _5) -> [return: bb2, unwind: bb12];
_5 = ShallowInitBox(move _4, u32);
StorageLive(_6);
StorageLive(_7);
_7 = Option::<u32>::None;
_6 = <Option<u32> as Try>::branch(move _7) -> [return: bb2, unwind: bb12];
}
bb2: {
StorageDead(_5);
PlaceMention(_4);
_6 = discriminant(_4);
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3];
StorageDead(_7);
PlaceMention(_6);
_8 = discriminant(_6);
switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3];
}
bb3: {
@ -49,44 +53,44 @@ fn test() -> Option<Box<u32>> {
}
bb4: {
StorageLive(_10);
_10 = copy ((_4 as Continue).0: u32);
(*_3) = copy _10;
StorageDead(_10);
_1 = move _3;
drop(_3) -> [return: bb7, unwind: bb11];
StorageLive(_12);
_12 = copy ((_6 as Continue).0: u32);
(*_5) = copy _12;
StorageDead(_12);
_1 = move _5;
drop(_5) -> [return: bb7, unwind: bb11];
}
bb5: {
StorageLive(_7);
_7 = copy ((_4 as Break).0: std::option::Option<std::convert::Infallible>);
StorageLive(_9);
_9 = copy _7;
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _9) -> [return: bb6, unwind: bb12];
_9 = copy ((_6 as Break).0: std::option::Option<std::convert::Infallible>);
StorageLive(_11);
_11 = copy _9;
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _11) -> [return: bb6, unwind: bb12];
}
bb6: {
StorageDead(_11);
StorageDead(_9);
StorageDead(_7);
drop(_3) -> [return: bb9, unwind continue];
drop(_5) -> [return: bb9, unwind continue];
}
bb7: {
StorageDead(_3);
StorageDead(_5);
_0 = Option::<Box<u32>>::Some(move _1);
drop(_1) -> [return: bb8, unwind continue];
}
bb8: {
StorageDead(_1);
StorageDead(_4);
StorageDead(_6);
goto -> bb10;
}
bb9: {
StorageDead(_3);
StorageDead(_5);
StorageDead(_1);
StorageDead(_4);
StorageDead(_6);
goto -> bb10;
}
@ -99,7 +103,7 @@ fn test() -> Option<Box<u32>> {
}
bb12 (cleanup): {
drop(_3) -> [return: bb13, unwind terminate(cleanup)];
drop(_5) -> [return: bb13, unwind terminate(cleanup)];
}
bb13 (cleanup): {

View file

@ -0,0 +1,17 @@
- // MIR for `align_of` before LowerIntrinsics
+ // MIR for `align_of` after LowerIntrinsics
fn align_of() -> usize {
let mut _0: usize;
bb0: {
- _0 = std::intrinsics::align_of::<T>() -> [return: bb1, unwind unreachable];
+ _0 = AlignOf(T);
+ goto -> bb1;
}
bb1: {
return;
}
}

View file

@ -0,0 +1,17 @@
- // MIR for `align_of` before LowerIntrinsics
+ // MIR for `align_of` after LowerIntrinsics
fn align_of() -> usize {
let mut _0: usize;
bb0: {
- _0 = std::intrinsics::align_of::<T>() -> [return: bb1, unwind unreachable];
+ _0 = AlignOf(T);
+ goto -> bb1;
}
bb1: {
return;
}
}

View file

@ -3,21 +3,26 @@
fn non_const() -> usize {
let mut _0: usize;
let _1: unsafe fn() -> ! {std::intrinsics::unreachable};
let mut _2: !;
let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable};
let _1: fn() -> usize {std::intrinsics::size_of::<T>};
let mut _2: fn() -> usize {std::intrinsics::size_of::<T>};
scope 1 {
debug unreachable => _1;
debug size_of_t => _1;
}
bb0: {
StorageLive(_1);
_1 = std::intrinsics::unreachable;
_1 = std::intrinsics::size_of::<T>;
StorageLive(_2);
StorageLive(_3);
_3 = copy _1;
- _2 = move _3() -> unwind unreachable;
+ unreachable;
_2 = copy _1;
- _0 = move _2() -> [return: bb1, unwind unreachable];
+ _0 = SizeOf(T);
+ goto -> bb1;
}
bb1: {
StorageDead(_2);
StorageDead(_1);
return;
}
}

View file

@ -3,21 +3,26 @@
fn non_const() -> usize {
let mut _0: usize;
let _1: unsafe fn() -> ! {std::intrinsics::unreachable};
let mut _2: !;
let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable};
let _1: fn() -> usize {std::intrinsics::size_of::<T>};
let mut _2: fn() -> usize {std::intrinsics::size_of::<T>};
scope 1 {
debug unreachable => _1;
debug size_of_t => _1;
}
bb0: {
StorageLive(_1);
_1 = std::intrinsics::unreachable;
_1 = std::intrinsics::size_of::<T>;
StorageLive(_2);
StorageLive(_3);
_3 = copy _1;
- _2 = move _3() -> unwind unreachable;
+ unreachable;
_2 = copy _1;
- _0 = move _2() -> [return: bb1, unwind unreachable];
+ _0 = SizeOf(T);
+ goto -> bb1;
}
bb1: {
StorageDead(_2);
StorageDead(_1);
return;
}
}

View file

@ -40,6 +40,20 @@ pub unsafe fn unchecked(a: i32, b: i32, c: u32) {
let _l = core::intrinsics::unchecked_shr(a, c);
}
// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
pub fn size_of<T>() -> usize {
// CHECK-LABEL: fn size_of(
// CHECK: {{_.*}} = SizeOf(T);
core::intrinsics::size_of::<T>()
}
// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff
pub fn align_of<T>() -> usize {
// CHECK-LABEL: fn align_of(
// CHECK: {{_.*}} = AlignOf(T);
core::intrinsics::align_of::<T>()
}
// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
pub fn forget<T>(t: T) {
// CHECK-LABEL: fn forget(
@ -59,13 +73,11 @@ pub fn unreachable() -> ! {
// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
pub fn non_const<T>() -> usize {
// CHECK-LABEL: fn non_const(
// CHECK: _1 = std::intrinsics::unreachable;
// CHECK: unreachable;
// CHECK-NEXT: }
// CHECK: SizeOf(T);
// Check that lowering works with non-const operand as a func.
let unreachable = core::intrinsics::unreachable;
unsafe { unreachable() }
let size_of_t = core::intrinsics::size_of::<T>;
size_of_t()
}
// EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff

View file

@ -0,0 +1,17 @@
- // MIR for `size_of` before LowerIntrinsics
+ // MIR for `size_of` after LowerIntrinsics
fn size_of() -> usize {
let mut _0: usize;
bb0: {
- _0 = std::intrinsics::size_of::<T>() -> [return: bb1, unwind unreachable];
+ _0 = SizeOf(T);
+ goto -> bb1;
}
bb1: {
return;
}
}

View file

@ -0,0 +1,17 @@
- // MIR for `size_of` before LowerIntrinsics
+ // MIR for `size_of` after LowerIntrinsics
fn size_of() -> usize {
let mut _0: usize;
bb0: {
- _0 = std::intrinsics::size_of::<T>() -> [return: bb1, unwind unreachable];
+ _0 = SizeOf(T);
+ goto -> bb1;
}
bb1: {
return;
}
}

View file

@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
}
bb1: {
_6 = const <T as std::mem::SizedTypeProperties>::ALIGN;
_6 = AlignOf(T);
StorageLive(_7);
_7 = copy _6 as std::ptr::Alignment (Transmute);
_8 = move (_7.0: std::ptr::alignment::AlignmentEnum);

View file

@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
}
bb1: {
_6 = const <T as std::mem::SizedTypeProperties>::ALIGN;
_6 = AlignOf(T);
StorageLive(_7);
_7 = copy _6 as std::ptr::Alignment (Transmute);
_8 = move (_7.0: std::ptr::alignment::AlignmentEnum);

View file

@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
}
bb1: {
_6 = const <T as std::mem::SizedTypeProperties>::ALIGN;
_6 = AlignOf(T);
StorageLive(_7);
_7 = copy _6 as std::ptr::Alignment (Transmute);
_8 = move (_7.0: std::ptr::alignment::AlignmentEnum);

View file

@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
}
bb1: {
_6 = const <T as std::mem::SizedTypeProperties>::ALIGN;
_6 = AlignOf(T);
StorageLive(_7);
_7 = copy _6 as std::ptr::Alignment (Transmute);
_8 = move (_7.0: std::ptr::alignment::AlignmentEnum);

View file

@ -9,7 +9,7 @@ pub unsafe fn generic_in_place<T: Copy>(ptr: *mut Box<[T]>) {
// CHECK-LABEL: fn generic_in_place(_1: *mut Box<[T]>)
// CHECK: (inlined <Box<[T]> as Drop>::drop)
// CHECK: [[SIZE:_.+]] = std::intrinsics::size_of_val::<[T]>
// CHECK: [[ALIGN:_.+]] = const <T as std::mem::SizedTypeProperties>::ALIGN;
// CHECK: [[ALIGN:_.+]] = AlignOf(T);
// CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute);
// CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum);
// CHECK: [[D:_.+]] = discriminant([[C]]);

View file

@ -3,17 +3,17 @@
fn vec_move(_1: Vec<impl Sized>) -> () {
debug v => _1;
let mut _0: ();
let mut _21: std::vec::IntoIter<impl Sized>;
let mut _22: std::vec::IntoIter<impl Sized>;
let mut _23: &mut std::vec::IntoIter<impl Sized>;
let mut _24: std::option::Option<impl Sized>;
let mut _25: isize;
let _27: ();
let mut _23: std::vec::IntoIter<impl Sized>;
let mut _24: &mut std::vec::IntoIter<impl Sized>;
let mut _25: std::option::Option<impl Sized>;
let mut _26: isize;
let _28: ();
scope 1 {
debug iter => _22;
let _26: impl Sized;
debug iter => _23;
let _27: impl Sized;
scope 2 {
debug x => _26;
debug x => _27;
}
}
scope 3 (inlined <Vec<impl Sized> as IntoIterator>::into_iter) {
@ -24,16 +24,16 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
let mut _10: *mut impl Sized;
let mut _11: *const impl Sized;
let mut _12: usize;
let _28: &std::vec::Vec<impl Sized>;
let mut _29: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let mut _30: &alloc::raw_vec::RawVec<impl Sized>;
let mut _31: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let _32: &std::vec::Vec<impl Sized>;
let mut _33: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let _34: &std::vec::Vec<impl Sized>;
let mut _35: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let mut _36: &alloc::raw_vec::RawVec<impl Sized>;
let mut _37: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let _29: &std::vec::Vec<impl Sized>;
let mut _30: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let mut _31: &alloc::raw_vec::RawVec<impl Sized>;
let mut _32: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let _33: &std::vec::Vec<impl Sized>;
let mut _34: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let _35: &std::vec::Vec<impl Sized>;
let mut _36: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
let mut _37: &alloc::raw_vec::RawVec<impl Sized>;
let mut _38: &std::mem::ManuallyDrop<std::vec::Vec<impl Sized>>;
scope 4 {
debug me => _2;
scope 5 {
@ -46,33 +46,34 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
debug begin => _7;
scope 8 {
debug end => _11;
let _19: usize;
let _20: usize;
scope 9 {
debug cap => _19;
debug cap => _20;
}
scope 39 (inlined <ManuallyDrop<Vec<impl Sized>> as Deref>::deref) {
debug self => _37;
debug self => _38;
}
scope 40 (inlined alloc::raw_vec::RawVec::<impl Sized>::capacity) {
debug self => _36;
let mut _38: &alloc::raw_vec::RawVecInner;
debug self => _37;
let mut _19: usize;
let mut _39: &alloc::raw_vec::RawVecInner;
scope 41 (inlined std::mem::size_of::<impl Sized>) {
}
scope 42 (inlined alloc::raw_vec::RawVecInner::capacity) {
debug self => _38;
debug elem_size => const <impl Sized as std::mem::SizedTypeProperties>::SIZE;
let mut _20: core::num::niche_types::UsizeNoHighBit;
debug self => _39;
debug elem_size => _19;
let mut _21: core::num::niche_types::UsizeNoHighBit;
scope 43 (inlined core::num::niche_types::UsizeNoHighBit::as_inner) {
debug self => _20;
debug self => _21;
}
}
}
}
scope 25 (inlined <ManuallyDrop<Vec<impl Sized>> as Deref>::deref) {
debug self => _33;
debug self => _34;
}
scope 26 (inlined Vec::<impl Sized>::len) {
debug self => _32;
debug self => _33;
let mut _13: bool;
scope 27 {
}
@ -107,10 +108,10 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
}
scope 35 (inlined <ManuallyDrop<Vec<impl Sized>> as Deref>::deref) {
debug self => _35;
debug self => _36;
}
scope 36 (inlined Vec::<impl Sized>::len) {
debug self => _34;
debug self => _35;
let mut _9: bool;
scope 37 {
}
@ -125,10 +126,10 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
}
scope 17 (inlined <ManuallyDrop<Vec<impl Sized>> as Deref>::deref) {
debug self => _31;
debug self => _32;
}
scope 18 (inlined alloc::raw_vec::RawVec::<impl Sized>::non_null) {
debug self => _30;
debug self => _31;
scope 19 (inlined alloc::raw_vec::RawVecInner::non_null::<impl Sized>) {
let mut _4: std::ptr::NonNull<u8>;
scope 20 (inlined Unique::<u8>::cast::<impl Sized>) {
@ -144,10 +145,10 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
}
scope 11 (inlined <ManuallyDrop<Vec<impl Sized>> as Deref>::deref) {
debug self => _29;
debug self => _30;
}
scope 12 (inlined Vec::<impl Sized>::allocator) {
debug self => _28;
debug self => _29;
scope 13 (inlined alloc::raw_vec::RawVec::<impl Sized>::allocator) {
scope 14 (inlined alloc::raw_vec::RawVecInner::allocator) {
}
@ -166,23 +167,23 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
bb0: {
StorageLive(_21);
StorageLive(_22);
StorageLive(_6);
StorageLive(_7);
StorageLive(_11);
StorageLive(_19);
StorageLive(_20);
StorageLive(_5);
StorageLive(_4);
StorageLive(_17);
StorageLive(_2);
_2 = ManuallyDrop::<Vec<impl Sized>> { value: copy _1 };
StorageLive(_3);
// DBG: _29 = &_2;
// DBG: _28 = &(_2.0: std::vec::Vec<impl Sized>);
// DBG: _30 = &_2;
// DBG: _29 = &(_2.0: std::vec::Vec<impl Sized>);
_3 = &raw const ((((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global);
StorageDead(_3);
// DBG: _31 = &_2;
// DBG: _30 = &((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>);
// DBG: _32 = &_2;
// DBG: _31 = &((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>);
_4 = copy (((((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique<u8>).0: std::ptr::NonNull<u8>);
_5 = copy _4 as *const impl Sized (Transmute);
_6 = NonNull::<impl Sized> { pointer: copy _5 };
@ -193,8 +194,8 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
bb1: {
StorageLive(_10);
StorageLive(_8);
// DBG: _35 = &_2;
// DBG: _34 = &(_2.0: std::vec::Vec<impl Sized>);
// DBG: _36 = &_2;
// DBG: _35 = &(_2.0: std::vec::Vec<impl Sized>);
_8 = copy ((_2.0: std::vec::Vec<impl Sized>).1: usize);
StorageLive(_9);
_9 = Le(copy _8, const <impl Sized as std::mem::SizedTypeProperties>::MAX_SLICE_LEN);
@ -209,8 +210,8 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
bb2: {
StorageLive(_12);
// DBG: _33 = &_2;
// DBG: _32 = &(_2.0: std::vec::Vec<impl Sized>);
// DBG: _34 = &_2;
// DBG: _33 = &(_2.0: std::vec::Vec<impl Sized>);
_12 = copy ((_2.0: std::vec::Vec<impl Sized>).1: usize);
StorageLive(_13);
_13 = Le(copy _12, const <impl Sized as std::mem::SizedTypeProperties>::MAX_SLICE_LEN);
@ -238,69 +239,72 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
bb4: {
// DBG: _37 = &_2;
// DBG: _36 = &((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>);
// DBG: _38 = &(((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner);
switchInt(const <impl Sized as std::mem::SizedTypeProperties>::SIZE) -> [0: bb5, otherwise: bb6];
// DBG: _38 = &_2;
// DBG: _37 = &((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>);
// DBG: _39 = &(((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner);
StorageLive(_19);
_19 = SizeOf(impl Sized);
switchInt(move _19) -> [0: bb5, otherwise: bb6];
}
bb5: {
_19 = const usize::MAX;
_20 = const usize::MAX;
goto -> bb7;
}
bb6: {
StorageLive(_20);
_20 = copy ((((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit);
_19 = copy _20 as usize (Transmute);
StorageDead(_20);
StorageLive(_21);
_21 = copy ((((_2.0: std::vec::Vec<impl Sized>).0: alloc::raw_vec::RawVec<impl Sized>).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit);
_20 = copy _21 as usize (Transmute);
StorageDead(_21);
goto -> bb7;
}
bb7: {
_21 = std::vec::IntoIter::<impl Sized> { buf: copy _6, phantom: const ZeroSized: PhantomData<impl Sized>, cap: move _19, alloc: const ManuallyDrop::<std::alloc::Global> {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 };
StorageDead(_19);
_22 = std::vec::IntoIter::<impl Sized> { buf: copy _6, phantom: const ZeroSized: PhantomData<impl Sized>, cap: move _20, alloc: const ManuallyDrop::<std::alloc::Global> {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 };
StorageDead(_2);
StorageDead(_17);
StorageDead(_4);
StorageDead(_5);
StorageDead(_19);
StorageDead(_20);
StorageDead(_11);
StorageDead(_7);
StorageDead(_6);
StorageLive(_22);
_22 = move _21;
StorageLive(_23);
_23 = move _22;
goto -> bb8;
}
bb8: {
StorageLive(_24);
_23 = &mut _22;
_24 = <std::vec::IntoIter<impl Sized> as Iterator>::next(move _23) -> [return: bb9, unwind: bb15];
StorageLive(_25);
_24 = &mut _23;
_25 = <std::vec::IntoIter<impl Sized> as Iterator>::next(move _24) -> [return: bb9, unwind: bb15];
}
bb9: {
_25 = discriminant(_24);
switchInt(move _25) -> [0: bb10, 1: bb12, otherwise: bb14];
_26 = discriminant(_25);
switchInt(move _26) -> [0: bb10, 1: bb12, otherwise: bb14];
}
bb10: {
StorageDead(_24);
drop(_22) -> [return: bb11, unwind continue];
StorageDead(_25);
drop(_23) -> [return: bb11, unwind continue];
}
bb11: {
StorageDead(_23);
StorageDead(_22);
StorageDead(_21);
return;
}
bb12: {
_26 = move ((_24 as Some).0: impl Sized);
_27 = opaque::<impl Sized>(move _26) -> [return: bb13, unwind: bb15];
_27 = move ((_25 as Some).0: impl Sized);
_28 = opaque::<impl Sized>(move _27) -> [return: bb13, unwind: bb15];
}
bb13: {
StorageDead(_24);
StorageDead(_25);
goto -> bb8;
}
@ -309,7 +313,7 @@ fn vec_move(_1: Vec<impl Sized>) -> () {
}
bb15 (cleanup): {
drop(_22) -> [return: bb16, unwind terminate(cleanup)];
drop(_23) -> [return: bb16, unwind terminate(cleanup)];
}
bb16 (cleanup): {

View file

@ -90,13 +90,15 @@ fn generate_input(path: &str) -> std::io::Result<()> {
write!(
file,
r#"
// We would like to check intrinsic definition.
#![feature(core_intrinsics)]
static STATIC_STR: &str = "foo";
const CONST_U32: u32 = 0u32;
fn main() {{
let _c = core::char::from_u32(99);
let _v = Vec::<u8>::new();
let _i = std::mem::size_of::<u8>();
let _i = std::intrinsics::size_of::<u8>();
}}
extern "C" {{

View file

@ -1,4 +1,12 @@
//@ check-fail
//@ known-bug: #97477
//@ failure-status: 101
//@ normalize-stderr: "note: .*\n\n" -> ""
//@ normalize-stderr: "thread 'rustc'.*panicked.*\n" -> ""
//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
//@ rustc-env:RUST_BACKTRACE=0
// This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
@ -26,6 +34,4 @@ where
fn main() {
let dst = Inline::<dyn Debug>::new(0);
//~^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time
//~| ERROR the function or associated item `new` exists for struct `Inline<dyn Debug>`
}

View file

@ -1,42 +1,11 @@
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
--> $DIR/issue-80742.rs:28:15
|
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Debug`
note: required by an implicit `Sized` bound in `Inline`
--> $DIR/issue-80742.rs:10:15
|
LL | struct Inline<T>
| ^ required by the implicit `Sized` requirement on this type parameter in `Inline`
help: consider relaxing the implicit `Sized` restriction
|
LL | struct Inline<T: ?Sized>
| ++++++++
error: internal compiler error: compiler/rustc_const_eval/src/interpret/operator.rs:LL:CC: unsized type for `NullaryOp::SizeOf`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
--> $DIR/issue-80742.rs:28:36
|
LL | struct Inline<T>
| ---------------- function or associated item `new` not found for this struct
...
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
|
note: trait bound `dyn Debug: Sized` was not satisfied
--> $DIR/issue-80742.rs:18:6
|
LL | impl<T> Inline<T>
| ^ ---------
| |
| unsatisfied trait bound introduced here
help: consider relaxing the type parameter's implicit `Sized` bound
|
LL | impl<T: ?Sized> Inline<T>
| ++++++++
error: aborting due to 2 previous errors
Box<dyn Any>
query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Inline::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: aborting due to 1 previous error
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,38 +0,0 @@
error[E0308]: mismatched types
--> $DIR/size_of-dyn-trait-2.rs:14:11
|
LL | fn foo(x: A<dyn Send>) {}
| ^^^^^^^^^^^ expected `8`, found `{ std::mem::size_of::<T>() }`
|
= note: expected constant `8`
found constant `{ std::mem::size_of::<T>() }`
note: required by a bound in `A`
--> $DIR/size_of-dyn-trait-2.rs:10:13
|
LL | struct A<T: Size<8> + ?Sized> {
| ^^^^^^^ required by this bound in `A`
error[E0277]: the size for values of type `(dyn Send + 'static)` cannot be known at compilation time
--> $DIR/size_of-dyn-trait-2.rs:14:11
|
LL | fn foo(x: A<dyn Send>) {}
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Send + 'static)`
note: required for `(dyn Send + 'static)` to implement `Size<8>`
--> $DIR/size_of-dyn-trait-2.rs:8:16
|
LL | impl<T: Sized> Size<{ std::mem::size_of::<T>() }> for T {}
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required by a bound in `A`
--> $DIR/size_of-dyn-trait-2.rs:10:13
|
LL | struct A<T: Size<8> + ?Sized> {
| ^^^^^^^ required by this bound in `A`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,21 +0,0 @@
//! Regression test for #114663
//@ edition:2021
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
use core::fmt::Debug;
use core::marker::PhantomData;
struct Inline<T>
where
[u8; ::core::mem::size_of::<T>() + 1]:,
{
_phantom: PhantomData<T>,
}
fn main() {
let dst = Inline::<dyn Debug>::new(0);
//~^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time
//~| ERROR no function or associated item named `new` found for struct `Inline<T>`
}

View file

@ -1,30 +0,0 @@
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
--> $DIR/size_of-dyn-trait-3.rs:18:15
|
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Debug`
note: required by an implicit `Sized` bound in `Inline`
--> $DIR/size_of-dyn-trait-3.rs:10:15
|
LL | struct Inline<T>
| ^ required by the implicit `Sized` requirement on this type parameter in `Inline`
help: consider relaxing the implicit `Sized` restriction
|
LL | struct Inline<T: ?Sized>
| ++++++++
error[E0599]: no function or associated item named `new` found for struct `Inline<T>` in the current scope
--> $DIR/size_of-dyn-trait-3.rs:18:36
|
LL | struct Inline<T>
| ---------------- function or associated item `new` not found for this struct
...
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^ function or associated item not found in `Inline<dyn Debug>`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.

View file

@ -1,23 +0,0 @@
error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time
--> $DIR/size_of-dyn-trait.rs:13:12
|
LL | let x: A<dyn Trait>;
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Trait`
note: required by an implicit `Sized` bound in `A`
--> $DIR/size_of-dyn-trait.rs:8:10
|
LL | struct A<T>(T)
| ^ required by the implicit `Sized` requirement on this type parameter in `A`
help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box<T>`
--> $DIR/size_of-dyn-trait.rs:8:10
|
LL | struct A<T>(T)
| ^ - ...if indirection were used here: `Box<T>`
| |
| this could be changed to `T: ?Sized`...
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -5,11 +5,10 @@ LL | bytes: [u8; std::mem::size_of::<Foo>()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`...
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
note: ...which requires simplifying constant for the type system `core::mem::SizedTypeProperties::SIZE`...
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
note: ...which requires const-evaluating + checking `core::mem::SizedTypeProperties::SIZE`...
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
--> $DIR/const-size_of-cycle.rs:2:17
|
LL | bytes: [u8; std::mem::size_of::<Foo>()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `Foo`...
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...

View file

@ -1,4 +1,4 @@
//~? ERROR values of the type `[u8; usize::MAX]` are too big for the target architecture
//~ ERROR values of the type `[u8; usize::MAX]` are too big for the target architecture
// Make sure the compiler does not ICE when trying to generate the debuginfo name of a type that
// causes a layout error. See https://github.com/rust-lang/rust/issues/94961.

View file

@ -1,14 +1,4 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<Foo<u8> as std::mem::SizedTypeProperties>::SIZE` failed here
note: the above error was encountered while instantiating `fn std::mem::size_of::<Foo<u8>>`
--> $DIR/debuginfo-type-name-layout-ice-94961-1.rs:13:5
|
LL | std::mem::size_of::<Foo<u8>>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: values of the type `[u8; usize::MAX]` are too big for the target architecture
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,14 +1,4 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<Foo<u8> as std::mem::SizedTypeProperties>::SIZE` failed here
note: the above error was encountered while instantiating `fn std::mem::size_of::<Foo<u8>>`
--> $DIR/debuginfo-type-name-layout-ice-94961-2.rs:16:5
|
LL | std::mem::size_of::<Foo<u8>>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: values of the type `[u8; usize::MAX]` are too big for the target architecture
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,6 +1,5 @@
//@ run-pass
#![allow(dead_code)]
#![recursion_limit = "256"]
// Making sure that no overflow occurs.

View file

@ -2,6 +2,8 @@
#![feature(core_intrinsics, rustc_attrs)]
use std::intrinsics as rusti;
#[cfg(any(
target_os = "aix",
target_os = "android",
@ -21,12 +23,12 @@
mod m {
#[cfg(target_arch = "x86")]
pub fn main() {
assert_eq!(std::mem::align_of::<u64>(), 4);
assert_eq!(crate::rusti::align_of::<u64>(), 4);
}
#[cfg(not(target_arch = "x86"))]
pub fn main() {
assert_eq!(std::mem::align_of::<u64>(), 8);
assert_eq!(crate::rusti::align_of::<u64>(), 8);
}
}
@ -34,21 +36,21 @@ mod m {
mod m {
#[cfg(target_arch = "x86_64")]
pub fn main() {
assert_eq!(std::mem::align_of::<u64>(), 8);
assert_eq!(crate::rusti::align_of::<u64>(), 8);
}
}
#[cfg(target_os = "windows")]
mod m {
pub fn main() {
assert_eq!(std::mem::align_of::<u64>(), 8);
assert_eq!(crate::rusti::align_of::<u64>(), 8);
}
}
#[cfg(target_family = "wasm")]
mod m {
pub fn main() {
assert_eq!(std::mem::align_of::<u64>(), 8);
assert_eq!(crate::rusti::align_of::<u64>(), 8);
}
}

View file

@ -13,6 +13,6 @@ struct P2 {
}
static CHECK: () = assert!(align_of::<P2>() == 1);
//~? ERROR the type `MySlice<[bool]>` has an unknown layout
//~^ ERROR the type `MySlice<[bool]>` has an unknown layout
fn main() {}

View file

@ -19,9 +19,13 @@ LL | struct MySlice<T>(T);
| this could be changed to `T: ?Sized`...
error[E0080]: the type `MySlice<[bool]>` has an unknown layout
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
--> $DIR/invalid-unsized-in-always-sized-tail.rs:15:28
|
= note: evaluation of `<P2 as std::mem::SizedTypeProperties>::ALIGN` failed here
LL | static CHECK: () = assert!(align_of::<P2>() == 1);
| ^^^^^^^^^^^^^^^^ evaluation of `CHECK` failed inside this call
|
note: inside `std::mem::align_of::<P2>`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
error: aborting due to 2 previous errors

View file

@ -1,6 +1,6 @@
//@ build-fail
//~^ ERROR: cycle detected when computing layout of
//~? ERROR: a cycle occurred during layout computation
//~^ ERROR: a cycle occurred during layout computation
//~| ERROR: cycle detected when computing layout of
// Issue #111176 -- ensure that we do not emit ICE on layout cycles

View file

@ -2,22 +2,10 @@ error[E0391]: cycle detected when computing layout of `S<S<()>>`
|
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
note: cycle used when const-evaluating + checking `core::mem::SizedTypeProperties::SIZE`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0080]: a cycle occurred during layout computation
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<S<S<()>> as std::mem::SizedTypeProperties>::SIZE` failed here
note: the above error was encountered while instantiating `fn std::mem::size_of::<S<S<()>>>`
--> $DIR/layout-cycle.rs:26:5
|
LL | mem::size_of::<S<T>>()
| ^^^^^^^^^^^^^^^^^^^^^^
error: failed to get layout for S<S<()>>: a cycle occurred during layout computation
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.

View file

@ -1,19 +0,0 @@
error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here
error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::ALIGN` failed here
note: the above error was encountered while instantiating `fn Box::<[&usize; usize::MAX]>::new`
--> $DIR/issue-17913.rs:16:21
|
LL | let a: Box<_> = Box::new([&n; SIZE]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,19 +0,0 @@
error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here
error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::ALIGN` failed here
note: the above error was encountered while instantiating `fn Box::<[&usize; usize::MAX]>::new`
--> $DIR/issue-17913.rs:9:21
|
LL | let a: Box<_> = Box::new([&n; SIZE]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,7 +1,5 @@
//@ build-fail
//@ stderr-per-bitwidth
//@ normalize-stderr: "\[&usize; \d+\]" -> "[&usize; usize::MAX]"
//@ normalize-stderr: "\[&n; 0x[0-9A-F]+_usize\]" -> "[&n; SIZE]"
#[cfg(target_pointer_width = "64")]
fn main() {
@ -18,4 +16,3 @@ fn main() {
}
//~? ERROR are too big for the target architecture
//~? ERROR are too big for the target architecture

View file

@ -0,0 +1,5 @@
error: values of the type `[&usize; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
error: aborting due to 1 previous error

View file

@ -2,5 +2,5 @@
fn main() {
println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
//~? ERROR too big for the target architecture
//~^ ERROR too big for the target architecture
}

View file

@ -1,7 +1,11 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
--> $DIR/issue-55878.rs:4:26
|
= note: evaluation of `<[u8; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main` failed inside this call
|
note: inside `std::mem::size_of::<[u8; usize::MAX]>`
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
error: aborting due to 1 previous error

View file

@ -1,4 +1,4 @@
//~? ERROR values of the type `[u8; usize::MAX]` are too big for the target architecture
//~ ERROR
//@ build-fail
//@ ignore-32bit

View file

@ -1,14 +1,4 @@
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<S<u8> as std::mem::SizedTypeProperties>::SIZE` failed here
note: the above error was encountered while instantiating `fn std::mem::size_of::<S<u8>>`
--> $DIR/issue-75158-64.rs:11:5
|
LL | std::mem::size_of::<S<u8>>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: values of the type `[u8; usize::MAX]` are too big for the target architecture
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -26,6 +26,6 @@ type Byte = Option<Option<Option<Option< Option<Option<Option<Option<
>>>> >>>>;
fn main() {
//~? ERROR: queries overflow the depth limit!
//~^ ERROR: queries overflow the depth limit!
println!("{}", std::mem::size_of::<Byte>());
}

View file

@ -1,8 +1,11 @@
error: queries overflow the depth limit!
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
--> $DIR/query_depth.rs:28:1
|
LL | fn main() {
| ^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`)
= note: query depth increased by 64 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
= note: query depth increased by 65 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
error: aborting due to 1 previous error

View file

@ -6,6 +6,7 @@
#![feature(core_intrinsics, rustc_attrs)]
use std::mem;
use std::intrinsics;
// This is the type with the questionable alignment
#[derive(Debug)]
@ -33,12 +34,12 @@ pub fn main() {
// Send it through the shape code
let y = format!("{:?}", x);
println!("align inner = {:?}", mem::align_of::<Inner>());
println!("align inner = {:?}", intrinsics::align_of::<Inner>());
println!("size outer = {:?}", mem::size_of::<Outer>());
println!("y = {:?}", y);
// per clang/gcc the alignment of `inner` is 4 on x86.
assert_eq!(mem::align_of::<Inner>(), m::align());
assert_eq!(intrinsics::align_of::<Inner>(), m::align());
// per clang/gcc the size of `outer` should be 12
// because `inner`s alignment was 4.

View file

@ -7,6 +7,7 @@
#![feature(core_intrinsics, rustc_attrs)]
use std::mem;
use std::intrinsics;
// This is the type with the questionable alignment
#[derive(Debug)]
@ -83,12 +84,12 @@ pub fn main() {
let y = format!("{:?}", x);
println!("align inner = {:?}", mem::align_of::<Inner>());
println!("align inner = {:?}", intrinsics::align_of::<Inner>());
println!("size outer = {:?}", mem::size_of::<Outer>());
println!("y = {:?}", y);
// per clang/gcc the alignment of `Inner` is 4 on x86.
assert_eq!(mem::align_of::<Inner>(), m::m::align());
assert_eq!(intrinsics::align_of::<Inner>(), m::m::align());
// per clang/gcc the size of `Outer` should be 12
// because `Inner`s alignment was 4.