diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 984a154853a98..d1d0bff8fe06b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1046,16 +1046,6 @@ 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, _) => {} diff --git a/compiler/rustc_codegen_cranelift/example/example.rs b/compiler/rustc_codegen_cranelift/example/example.rs index aeb38331edb02..769d262b9ebb5 100644 --- a/compiler/rustc_codegen_cranelift/example/example.rs +++ b/compiler/rustc_codegen_cranelift/example/example.rs @@ -72,10 +72,6 @@ pub fn debug_tuple() -> DebugTuple { DebugTuple(()) } -pub fn size_of() -> usize { - intrinsics::size_of::() -} - pub fn use_size_of() -> usize { size_of::() } diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 2f53bbf8b7934..dff9f92c5bd47 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -6,6 +6,7 @@ extern_types, decl_macro, rustc_attrs, + rustc_private, transparent_unions, auto_traits, freeze_impls, @@ -594,7 +595,7 @@ impl, U: ?Sized> CoerceUnsized> for Box {} impl Box { pub fn new(val: T) -> Box { unsafe { - let size = intrinsics::size_of::(); + let size = size_of::(); 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) @@ -646,11 +647,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub fn abort() -> !; #[rustc_intrinsic] - pub fn size_of() -> usize; + pub const fn size_of() -> usize; #[rustc_intrinsic] pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] - pub fn align_of() -> usize; + pub const fn align_of() -> usize; #[rustc_intrinsic] pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] @@ -715,6 +716,23 @@ impl Index for [T] { } } +pub const fn size_of() -> usize { + const { intrinsics::size_of::() } +} + +pub const fn align_of() -> usize { + const { intrinsics::align_of::() } +} + +trait SizedTypeProperties: Sized { + #[lang = "mem_size_const"] + const SIZE: usize = intrinsics::size_of::(); + + #[lang = "mem_align_const"] + const ALIGN: usize = intrinsics::align_of::(); +} +impl SizedTypeProperties for T {} + extern "C" { type VaListImpl; } diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs index 86602c6b2a3fd..a9388814a7f59 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs @@ -109,10 +109,10 @@ fn start( puts(*argv as *const i8); } unsafe { - puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + size_of::<*const u8>()) as *const *const i8)); } unsafe { - puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + 2 * 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!(intrinsics::align_of::() as u8, 2); - assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8); + assert_eq!(align_of::() as u8, 2); + assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8); let u8_needs_drop = const { intrinsics::needs_drop::() }; assert!(!u8_needs_drop); diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 7e99eb09b91ab..435ec319cd94f 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -840,8 +840,6 @@ 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( diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 7a6cb2a51e317..53e08e3146adc 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -611,16 +611,6 @@ 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() diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 2c6dd5bd01f9c..ca173fe26c2f6 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -646,11 +646,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { Rvalue::Cast(_, _, _) => {} Rvalue::NullaryOp( - NullOp::SizeOf - | NullOp::AlignOf - | NullOp::OffsetOf(_) - | NullOp::UbChecks - | NullOp::ContractChecks, + NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _, ) => {} Rvalue::ShallowInitBox(_, _) => {} diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index fc7f1166af99a..f0f06d469c1e6 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -156,6 +156,24 @@ 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() { diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index f0819423aa0fa..58b90abf01295 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -517,20 +517,6 @@ 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(); diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 311cf8f995c82..9f7f4c7583412 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -168,6 +168,8 @@ 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); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 60c2ef4d563e4..17d8eeee68bfd 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1092,8 +1092,6 @@ 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()"), diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 91a528678901b..50814862b2ff4 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -782,9 +782,7 @@ 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::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => { - tcx.types.usize - } + Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => tcx.types.usize, Rvalue::NullaryOp(NullOp::ContractChecks, _) | Rvalue::NullaryOp(NullOp::UbChecks, _) => tcx.types.bool, Rvalue::Aggregate(ref ak, ref ops) => match **ak { @@ -853,7 +851,7 @@ impl BorrowKind { impl<'tcx> NullOp<'tcx> { pub fn ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self { - NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) => tcx.types.usize, + NullOp::OffsetOf(_) => tcx.types.usize, NullOp::UbChecks | NullOp::ContractChecks => tcx.types.bool, } } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 6f616b5403c64..3135b217ec117 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1559,10 +1559,6 @@ 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. diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 3a5839f2d404d..ae7d3ae96c744 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -126,21 +126,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let tcx = this.tcx; let source_info = this.source_info(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 size = tcx.require_lang_item(LangItem::SizeOf, expr_span); + let size = Const::from_unevaluated(tcx, size).instantiate(tcx, &[value_ty.into()]); + let size = Operand::Constant(Box::new(ConstOperand { + span: expr_span, + user_ty: None, + const_: size, + })); - let align = this.temp(tcx.types.usize, expr_span); - this.cfg.push_assign( - block, - source_info, - align, - Rvalue::NullaryOp(NullOp::AlignOf, value_ty), - ); + let align = tcx.require_lang_item(LangItem::AlignOf, expr_span); + let align = + Const::from_unevaluated(tcx, align).instantiate(tcx, &[value_ty.into()]); + let align = Operand::Constant(Box::new(ConstOperand { + span: expr_span, + user_ty: None, + const_: align, + })); // malloc some memory of suitable size and align: let exchange_malloc = Operand::function_handle( @@ -157,8 +158,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { TerminatorKind::Call { func: exchange_malloc, args: [ - Spanned { node: Operand::Move(size), span: DUMMY_SP }, - Spanned { node: Operand::Move(align), span: DUMMY_SP }, + Spanned { node: size, span: DUMMY_SP }, + Spanned { node: align, span: DUMMY_SP }, ] .into(), destination: storage, diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index c60713cea0300..e96af9b3791b3 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -411,11 +411,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { | Rvalue::RawPtr(..) | Rvalue::Discriminant(..) | Rvalue::NullaryOp( - NullOp::SizeOf - | NullOp::AlignOf - | NullOp::OffsetOf(..) - | NullOp::UbChecks - | NullOp::ContractChecks, + NullOp::OffsetOf(..) | NullOp::UbChecks | NullOp::ContractChecks, _, ) => {} } diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index 989787504b7b8..bbd647aa54eeb 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -1,4 +1,5 @@ use rustc_abi::Align; +use rustc_hir::LangItem; use rustc_index::IndexVec; use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::visit::PlaceContext; @@ -59,10 +60,14 @@ fn insert_alignment_check<'tcx>( stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((addr, rvalue))))); // Get the alignment of the pointee - let alignment = - 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))))); + let align_def_id = tcx.require_lang_item(LangItem::AlignOf, source_info.span); + let align_const = + Const::from_unevaluated(tcx, align_def_id).instantiate(tcx, &[pointee_ty.into()]); + let alignment = Operand::Constant(Box::new(ConstOperand { + span: source_info.span, + user_ty: None, + const_: align_const, + })); // Subtract 1 from the alignment to get the alignment mask let alignment_mask = @@ -76,7 +81,7 @@ fn insert_alignment_check<'tcx>( source_info, StatementKind::Assign(Box::new(( alignment_mask, - Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(alignment), one))), + Rvalue::BinaryOp(BinOp::Sub, Box::new((alignment.clone(), one))), ))), )); @@ -141,7 +146,7 @@ fn insert_alignment_check<'tcx>( PointerCheck { cond: Operand::Copy(is_ok), assert_kind: Box::new(AssertKind::MisalignedPointerDereference { - required: Operand::Copy(alignment), + required: alignment, found: Operand::Copy(addr), }), } diff --git a/compiler/rustc_mir_transform/src/check_null.rs b/compiler/rustc_mir_transform/src/check_null.rs index e365d36580ad5..1cdcd556da680 100644 --- a/compiler/rustc_mir_transform/src/check_null.rs +++ b/compiler/rustc_mir_transform/src/check_null.rs @@ -1,3 +1,4 @@ +use rustc_hir::LangItem; use rustc_index::IndexVec; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext}; use rustc_middle::mir::*; @@ -62,35 +63,27 @@ fn insert_null_check<'tcx>( Operand::Constant(Box::new(ConstOperand { span: source_info.span, user_ty: None, - const_: Const::Val(ConstValue::from_bool(true), tcx.types.bool), + const_: Const::from_bool(tcx, true), })) } // Other usages of null pointers only are UB if the pointee is not a ZST. _ => { - 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((sizeof_pointee, rvalue))), - )); + let size_of = tcx.require_lang_item(LangItem::SizeOf, source_info.span); + let size_of = Operand::Constant(Box::new(ConstOperand { + span: source_info.span, + user_ty: None, + const_: Const::from_unevaluated(tcx, size_of) + .instantiate(tcx, &[pointee_ty.into()]), + })); - // Check that the pointee is not a ZST. - let is_pointee_not_zst = + 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()))); 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())), - ), - ))), + StatementKind::Assign(Box::new((pointee_should_be_checked, rvalue))), )); - - // Pointer needs to be checked only if pointee is not a ZST. - Operand::Copy(is_pointee_not_zst) + Operand::Copy(pointee_should_be_checked.into()) } }; diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index aae86a43127d9..88d5209b67b76 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -466,8 +466,6 @@ 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 diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index bdf53f45feacb..0ab8356ed8354 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -670,14 +670,7 @@ 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()) diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index c83bd25c6636b..fea5b7cee9c5c 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -264,6 +264,7 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { terminator: &mut Terminator<'tcx>, statements: &mut Vec>, ) { + let source_info = terminator.source_info; if let TerminatorKind::Call { func, args, destination, target: Some(destination_block), .. } = &terminator.kind @@ -272,12 +273,17 @@ 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 = Const::from_unevaluated(self.tcx, align_def_id) + .instantiate(self.tcx, &[elem_ty.into()]); + let align_const = Operand::Constant(Box::new(ConstOperand { + span: source_info.span, + user_ty: None, + const_: align_const, + })); statements.push(Statement::new( - terminator.source_info, - StatementKind::Assign(Box::new(( - *destination, - Rvalue::NullaryOp(NullOp::AlignOf, elem_ty), - ))), + source_info, + StatementKind::Assign(Box::new((*destination, Rvalue::Use(align_const)))), )); terminator.kind = TerminatorKind::Goto { target: *destination_block }; } diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index c67e875175fee..131e3943689b8 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -608,8 +608,6 @@ 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()) diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index fc8092fd5832b..ad7c52064a8ef 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -139,23 +139,6 @@ 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"); diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index c7dc18a4a1343..9204c221515c9 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -450,8 +450,6 @@ impl<'tcx> Validator<'_, 'tcx> { } Rvalue::NullaryOp(op, _) => match op { - NullOp::SizeOf => {} - NullOp::AlignOf => {} NullOp::OffsetOf(_) => {} NullOp::UbChecks => {} NullOp::ContractChecks => {} diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 2945298c3fdda..34da9ed162d50 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -1391,10 +1391,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { Rvalue::Repeat(_, _) | Rvalue::ThreadLocalRef(_) | Rvalue::RawPtr(_, _) - | Rvalue::NullaryOp( - NullOp::SizeOf | NullOp::AlignOf | NullOp::UbChecks | NullOp::ContractChecks, - _, - ) + | Rvalue::NullaryOp(NullOp::UbChecks | NullOp::ContractChecks, _) | Rvalue::Discriminant(_) => {} Rvalue::WrapUnsafeBinder(op, ty) => { diff --git a/compiler/rustc_public/src/mir/body.rs b/compiler/rustc_public/src/mir/body.rs index 615a5a48d15b7..1a939cbe8dba2 100644 --- a/compiler/rustc_public/src/mir/body.rs +++ b/compiler/rustc_public/src/mir/body.rs @@ -641,9 +641,7 @@ impl Rvalue { .discriminant_ty() .ok_or_else(|| error!("Expected a `RigidTy` but found: {place_ty:?}")) } - Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => { - Ok(Ty::usize_ty()) - } + Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => Ok(Ty::usize_ty()), Rvalue::NullaryOp(NullOp::ContractChecks, _) | Rvalue::NullaryOp(NullOp::UbChecks, _) => Ok(Ty::bool_ty()), Rvalue::Aggregate(ak, ops) => match *ak { @@ -1024,10 +1022,6 @@ 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 diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index 392347ce345a0..f850bc5f89b8a 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -323,8 +323,6 @@ 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(), ), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index ef72c478951b8..6cbeda7eae5db 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1387,11 +1387,13 @@ 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, diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index a537269284773..619e8a263db40 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -333,7 +333,7 @@ pub fn forget_unsized(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() -> usize { - intrinsics::size_of::() + ::SIZE } /// Returns the size of the pointed-to value in bytes. @@ -441,7 +441,7 @@ pub const unsafe fn size_of_val_raw(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() -> usize { - intrinsics::align_of::() + ::ALIGN } /// 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(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() -> usize { - intrinsics::align_of::() + ::ALIGN } /// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in @@ -1236,6 +1236,16 @@ pub const fn variant_count() -> 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::(); + + #[doc(hidden)] + #[unstable(feature = "sized_type_properties", issue = "none")] + #[lang = "mem_align_const"] + const ALIGN: usize = intrinsics::align_of::(); + /// `true` if this type requires no storage. /// `false` if its [size](size_of) is greater than zero. /// @@ -1263,7 +1273,7 @@ pub trait SizedTypeProperties: Sized { /// ``` #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] - const IS_ZST: bool = size_of::() == 0; + const IS_ZST: bool = Self::SIZE == 0; #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] @@ -1275,7 +1285,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 size_of::() { + const MAX_SLICE_LEN: usize = match Self::SIZE { 0 => usize::MAX, n => (isize::MAX as usize) / n, }; diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 7722bebdbbe0d..90ea2616890a4 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -194,10 +194,7 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp( - NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, - _, - ) + Rvalue::NullaryOp(NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, cx.tcx); diff --git a/src/tools/miri/tests/fail/layout_cycle.stderr b/src/tools/miri/tests/fail/layout_cycle.stderr index c233f85063cc9..dae6934931228 100644 --- a/src/tools/miri/tests/fail/layout_cycle.stderr +++ b/src/tools/miri/tests/fail/layout_cycle.stderr @@ -2,29 +2,20 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `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::(); + | ^^^^^^^^^^^^^^^^^ = 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: post-monomorphization error: a cycle occurred during layout computation +error[E0080]: a cycle occurred during layout computation --> RUSTLIB/core/src/mem/mod.rs:LL:CC | -LL | intrinsics::size_of::() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ post-monomorphization error occurred here - | - = note: BACKTRACE: - = note: inside `std::mem::size_of::>>` at RUSTLIB/core/src/mem/mod.rs:LL:CC -note: inside `foo::>` - --> tests/fail/layout_cycle.rs:LL:CC - | -LL | mem::size_of::>() - | ^^^^^^^^^^^^^^^^^^^^^^ -note: inside `main` - --> tests/fail/layout_cycle.rs:LL:CC - | -LL | println!("{}", foo::>()); - | ^^^^^^^^^^^^^^ - -note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace +LL | const SIZE: usize = intrinsics::size_of::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `> as std::mem::SizedTypeProperties>::SIZE` failed here error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0391`. +Some errors have detailed explanations: E0080, E0391. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs b/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs index f43869cf2189e..dfe154c1c8314 100644 --- a/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs +++ b/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs @@ -25,7 +25,7 @@ trait Copy {} impl Copy for *mut T {} #[rustc_intrinsic] -fn size_of() -> usize { +const fn size_of() -> usize { loop {} } @@ -40,7 +40,7 @@ unsafe fn catch_unwind( #[no_mangle] pub fn ptr_size() -> usize { // CHECK: ret [[PTR_SIZE:.*]] - size_of::<*mut u8>() + const { size_of::<*mut u8>() } } // CHECK-LABEL: @test_catch_unwind diff --git a/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs b/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs index b0750d52268ad..88c95b088aaaa 100644 --- a/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs +++ b/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs @@ -24,7 +24,7 @@ trait Copy {} impl Copy for *mut T {} #[rustc_intrinsic] -fn size_of() -> usize { +const fn size_of() -> usize { loop {} } #[rustc_intrinsic] @@ -38,7 +38,7 @@ unsafe fn catch_unwind( #[no_mangle] pub fn ptr_size() -> usize { // CHECK: ret [[PTR_SIZE:.*]] - size_of::<*mut u8>() + const { size_of::<*mut u8>() } } // CHECK-LABEL: @test_catch_unwind diff --git a/tests/crashes/114663.rs b/tests/crashes/114663.rs deleted file mode 100644 index 406371f12e460..0000000000000 --- a/tests/crashes/114663.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ known-bug: #114663 -//@ edition:2021 - -#![feature(generic_const_exprs)] - -use core::fmt::Debug; - -struct Inline -where - [u8; ::core::mem::size_of::() + 1]:, -{ - _phantom: PhantomData, -} - -fn main() { - let dst = Inline::::new(0); // BANG! -} diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.diff b/tests/mir-opt/box_expr.main.ElaborateDrops.diff index 827dc6ac7aefe..4fa77cf82d819 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.diff +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.diff @@ -4,49 +4,45 @@ fn main() -> () { let mut _0: (); let _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; + let mut _2: *mut u8; + let mut _3: std::boxed::Box; + let _4: (); let mut _5: std::boxed::Box; - let _6: (); - let mut _7: std::boxed::Box; -+ let mut _8: &mut std::boxed::Box; -+ let mut _9: (); -+ let mut _10: *const S; ++ let mut _6: &mut std::boxed::Box; ++ let mut _7: (); ++ let mut _8: *const S; scope 1 { debug x => _1; } bb0: { StorageLive(_1); - _2 = SizeOf(S); - _3 = AlignOf(S); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; + _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, S); - (*_5) = S::new() -> [return: bb2, unwind: bb8]; + StorageLive(_3); + _3 = ShallowInitBox(move _2, S); + (*_3) = S::new() -> [return: bb2, unwind: bb8]; } bb2: { - _1 = move _5; -- drop(_5) -> [return: bb3, unwind continue]; + _1 = move _3; +- drop(_3) -> [return: bb3, unwind continue]; + goto -> bb3; } bb3: { - StorageDead(_5); - StorageLive(_6); - StorageLive(_7); - _7 = move _1; - _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; + StorageDead(_3); + StorageLive(_4); + StorageLive(_5); + _5 = move _1; + _4 = std::mem::drop::>(move _5) -> [return: bb4, unwind: bb6]; } bb4: { - StorageDead(_7); - StorageDead(_6); + StorageDead(_5); + StorageDead(_4); _0 = const (); - drop(_1) -> [return: bb5, unwind continue]; + goto -> bb5; @@ -58,7 +54,7 @@ } bb6 (cleanup): { -- drop(_7) -> [return: bb7, unwind terminate(cleanup)]; +- drop(_5) -> [return: bb7, unwind terminate(cleanup)]; + goto -> bb7; } @@ -68,7 +64,7 @@ } bb8 (cleanup): { -- drop(_5) -> [return: bb9, unwind terminate(cleanup)]; +- drop(_3) -> [return: bb9, unwind terminate(cleanup)]; + goto -> bb12; } @@ -77,8 +73,8 @@ + } + + bb10 (cleanup): { -+ _8 = &mut _5; -+ _9 = as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)]; ++ _6 = &mut _3; ++ _7 = as Drop>::drop(move _6) -> [return: bb9, unwind terminate(cleanup)]; + } + + bb11 (cleanup): { @@ -86,7 +82,7 @@ + } + + bb12 (cleanup): { -+ _10 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); ++ _8 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); + goto -> bb11; } } diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir index 6d3b2cf291038..839bdeca86a88 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir @@ -4,63 +4,55 @@ fn move_out_by_subslice() -> () { let mut _0: (); let _1: [std::boxed::Box; 2]; let mut _2: std::boxed::Box; - let mut _3: usize; - let mut _4: usize; - let mut _5: *mut u8; - let mut _6: std::boxed::Box; + let mut _3: *mut u8; + let mut _4: std::boxed::Box; + let mut _5: std::boxed::Box; + let mut _6: *mut u8; let mut _7: std::boxed::Box; - let mut _8: usize; - let mut _9: usize; - let mut _10: *mut u8; - let mut _11: std::boxed::Box; scope 1 { debug a => _1; - let _12: [std::boxed::Box; 2]; + let _8: [std::boxed::Box; 2]; scope 2 { - debug _y => _12; + debug _y => _8; } } bb0: { StorageLive(_1); StorageLive(_2); - _3 = SizeOf(i32); - _4 = AlignOf(i32); - _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; + _3 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; } bb1: { - StorageLive(_6); - _6 = ShallowInitBox(move _5, i32); - (*_6) = const 1_i32; - _2 = move _6; - drop(_6) -> [return: bb2, unwind: bb12]; + StorageLive(_4); + _4 = ShallowInitBox(move _3, i32); + (*_4) = const 1_i32; + _2 = move _4; + drop(_4) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_6); - StorageLive(_7); - _8 = SizeOf(i32); - _9 = AlignOf(i32); - _10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12]; + StorageDead(_4); + StorageLive(_5); + _6 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb3, unwind: bb12]; } bb3: { - StorageLive(_11); - _11 = ShallowInitBox(move _10, i32); - (*_11) = const 2_i32; - _7 = move _11; - drop(_11) -> [return: bb4, unwind: bb11]; + StorageLive(_7); + _7 = ShallowInitBox(move _6, i32); + (*_7) = const 2_i32; + _5 = move _7; + drop(_7) -> [return: bb4, unwind: bb11]; } bb4: { - StorageDead(_11); - _1 = [move _2, move _7]; - drop(_7) -> [return: bb5, unwind: bb12]; + StorageDead(_7); + _1 = [move _2, move _5]; + drop(_5) -> [return: bb5, unwind: bb12]; } bb5: { - StorageDead(_7); + StorageDead(_5); drop(_2) -> [return: bb6, unwind: bb13]; } @@ -68,10 +60,10 @@ fn move_out_by_subslice() -> () { StorageDead(_2); FakeRead(ForLet(None), _1); PlaceMention(_1); - StorageLive(_12); - _12 = move _1[0..2]; + StorageLive(_8); + _8 = move _1[0..2]; _0 = const (); - drop(_12) -> [return: bb8, unwind: bb10]; + drop(_8) -> [return: bb8, unwind: bb10]; } bb7: { @@ -80,7 +72,7 @@ fn move_out_by_subslice() -> () { } bb8: { - StorageDead(_12); + StorageDead(_8); drop(_1) -> [return: bb9, unwind: bb13]; } @@ -94,7 +86,7 @@ fn move_out_by_subslice() -> () { } bb11 (cleanup): { - drop(_7) -> [return: bb12, unwind terminate(cleanup)]; + drop(_5) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir index 003b90a912d25..7fda69c7500a3 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir @@ -4,63 +4,55 @@ fn move_out_from_end() -> () { let mut _0: (); let _1: [std::boxed::Box; 2]; let mut _2: std::boxed::Box; - let mut _3: usize; - let mut _4: usize; - let mut _5: *mut u8; - let mut _6: std::boxed::Box; + let mut _3: *mut u8; + let mut _4: std::boxed::Box; + let mut _5: std::boxed::Box; + let mut _6: *mut u8; let mut _7: std::boxed::Box; - let mut _8: usize; - let mut _9: usize; - let mut _10: *mut u8; - let mut _11: std::boxed::Box; scope 1 { debug a => _1; - let _12: std::boxed::Box; + let _8: std::boxed::Box; scope 2 { - debug _y => _12; + debug _y => _8; } } bb0: { StorageLive(_1); StorageLive(_2); - _3 = SizeOf(i32); - _4 = AlignOf(i32); - _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; + _3 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; } bb1: { - StorageLive(_6); - _6 = ShallowInitBox(move _5, i32); - (*_6) = const 1_i32; - _2 = move _6; - drop(_6) -> [return: bb2, unwind: bb12]; + StorageLive(_4); + _4 = ShallowInitBox(move _3, i32); + (*_4) = const 1_i32; + _2 = move _4; + drop(_4) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_6); - StorageLive(_7); - _8 = SizeOf(i32); - _9 = AlignOf(i32); - _10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12]; + StorageDead(_4); + StorageLive(_5); + _6 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb3, unwind: bb12]; } bb3: { - StorageLive(_11); - _11 = ShallowInitBox(move _10, i32); - (*_11) = const 2_i32; - _7 = move _11; - drop(_11) -> [return: bb4, unwind: bb11]; + StorageLive(_7); + _7 = ShallowInitBox(move _6, i32); + (*_7) = const 2_i32; + _5 = move _7; + drop(_7) -> [return: bb4, unwind: bb11]; } bb4: { - StorageDead(_11); - _1 = [move _2, move _7]; - drop(_7) -> [return: bb5, unwind: bb12]; + StorageDead(_7); + _1 = [move _2, move _5]; + drop(_5) -> [return: bb5, unwind: bb12]; } bb5: { - StorageDead(_7); + StorageDead(_5); drop(_2) -> [return: bb6, unwind: bb13]; } @@ -68,10 +60,10 @@ fn move_out_from_end() -> () { StorageDead(_2); FakeRead(ForLet(None), _1); PlaceMention(_1); - StorageLive(_12); - _12 = move _1[1 of 2]; + StorageLive(_8); + _8 = move _1[1 of 2]; _0 = const (); - drop(_12) -> [return: bb8, unwind: bb10]; + drop(_8) -> [return: bb8, unwind: bb10]; } bb7: { @@ -80,7 +72,7 @@ fn move_out_from_end() -> () { } bb8: { - StorageDead(_12); + StorageDead(_8); drop(_1) -> [return: bb9, unwind: bb13]; } @@ -94,7 +86,7 @@ fn move_out_from_end() -> () { } bb11 (cleanup): { - drop(_7) -> [return: bb12, unwind terminate(cleanup)]; + drop(_5) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff index f43c0cca9ad28..234a60a669560 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff @@ -6,12 +6,10 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: usize; - let mut _5: usize; - let mut _6: *mut u8; - let mut _7: std::boxed::Box; - let mut _8: *const i32; - let mut _9: *const i32; + let mut _4: *mut u8; + let mut _5: std::boxed::Box; + let mut _6: *const i32; + let mut _7: *const i32; scope 1 { debug x => _1; } @@ -21,23 +19,18 @@ - StorageLive(_2); + nop; StorageLive(_3); -- _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]; + _4 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind unreachable]; } bb1: { - StorageLive(_7); - _7 = ShallowInitBox(move _6, i32); - _8 = copy ((_7.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - (*_8) = const 42_i32; - _3 = move _7; - StorageDead(_7); - _9 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - _2 = copy (*_9); + StorageLive(_5); + _5 = ShallowInitBox(move _4, i32); + _6 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + (*_6) = const 42_i32; + _3 = move _5; + StorageDead(_5); + _7 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_7); - _1 = Add(move _2, const 0_i32); - StorageDead(_2); + _1 = copy _2; diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff index 2c903b6d85349..05eaf0b4ef413 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff @@ -6,12 +6,10 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: usize; - let mut _5: usize; - let mut _6: *mut u8; - let mut _7: std::boxed::Box; - let mut _8: *const i32; - let mut _9: *const i32; + let mut _4: *mut u8; + let mut _5: std::boxed::Box; + let mut _6: *const i32; + let mut _7: *const i32; scope 1 { debug x => _1; } @@ -21,23 +19,18 @@ - StorageLive(_2); + nop; StorageLive(_3); -- _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]; + _4 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_7); - _7 = ShallowInitBox(move _6, i32); - _8 = copy ((_7.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - (*_8) = const 42_i32; - _3 = move _7; - StorageDead(_7); - _9 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - _2 = copy (*_9); + StorageLive(_5); + _5 = ShallowInitBox(move _4, i32); + _6 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + (*_6) = const 42_i32; + _3 = move _5; + StorageDead(_5); + _7 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_7); - _1 = Add(move _2, const 0_i32); - StorageDead(_2); + _1 = copy _2; diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff index 5d7343a15bbea..f34e12eae6b3e 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff @@ -11,6 +11,8 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); + let mut _14: usize; + let mut _15: usize; let mut _25: usize; scope 1 { debug vp_ctx => _1; @@ -35,10 +37,8 @@ } } scope 5 (inlined Box::<()>::new) { - let mut _12: usize; - let mut _13: usize; - let mut _14: *mut u8; - let mut _15: *const (); + let mut _12: *mut u8; + let mut _13: *const (); scope 6 (inlined alloc::alloc::exchange_malloc) { let _16: std::alloc::Layout; let mut _17: std::result::Result, std::alloc::AllocError>; @@ -81,11 +81,11 @@ StorageLive(_12); StorageLive(_13); StorageLive(_14); +- _14 = const <() as std::mem::SizedTypeProperties>::SIZE; ++ _14 = const 0_usize; StorageLive(_15); -- _12 = SizeOf(()); -- _13 = AlignOf(()); -+ _12 = const 0_usize; -+ _13 = const 1_usize; +- _15 = const <() as std::mem::SizedTypeProperties>::ALIGN; ++ _15 = const 1_usize; StorageLive(_16); StorageLive(_18); StorageLive(_19); @@ -115,7 +115,7 @@ _19 = copy ((_17 as Ok).0: std::ptr::NonNull<[u8]>); StorageLive(_24); _24 = copy _19 as *mut [u8] (Transmute); - _14 = copy _24 as *mut u8 (PtrToPtr); + _12 = copy _24 as *mut u8 (PtrToPtr); StorageDead(_24); StorageDead(_17); StorageDead(_22); @@ -123,12 +123,12 @@ StorageDead(_19); StorageDead(_18); StorageDead(_16); - _3 = ShallowInitBox(copy _14, ()); - _15 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); -- (*_15) = move _4; -+ (*_15) = const (); StorageDead(_15); StorageDead(_14); + _3 = ShallowInitBox(copy _12, ()); + _13 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); +- (*_13) = move _4; ++ (*_13) = const (); StorageDead(_13); StorageDead(_12); StorageDead(_4); @@ -172,15 +172,15 @@ } bb5: { -- _22 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable]; +- _22 = Layout::from_size_align_unchecked::precondition_check(copy _14, copy _15) -> [return: bb6, unwind unreachable]; + _22 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { StorageDead(_21); StorageLive(_23); -- _23 = copy _13 as std::ptr::Alignment (Transmute); -- _16 = Layout { size: copy _12, align: move _23 }; +- _23 = copy _15 as std::ptr::Alignment (Transmute); +- _16 = Layout { size: copy _14, align: move _23 }; + _23 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); + _16 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; StorageDead(_23); diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff index ba5fe287b8e1c..d91bd4048efc1 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff @@ -11,6 +11,8 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); + let mut _14: usize; + let mut _15: usize; let mut _25: usize; scope 1 { debug vp_ctx => _1; @@ -35,10 +37,8 @@ } } scope 5 (inlined Box::<()>::new) { - let mut _12: usize; - let mut _13: usize; - let mut _14: *mut u8; - let mut _15: *const (); + let mut _12: *mut u8; + let mut _13: *const (); scope 6 (inlined alloc::alloc::exchange_malloc) { let _16: std::alloc::Layout; let mut _17: std::result::Result, std::alloc::AllocError>; @@ -81,11 +81,11 @@ StorageLive(_12); StorageLive(_13); StorageLive(_14); +- _14 = const <() as std::mem::SizedTypeProperties>::SIZE; ++ _14 = const 0_usize; StorageLive(_15); -- _12 = SizeOf(()); -- _13 = AlignOf(()); -+ _12 = const 0_usize; -+ _13 = const 1_usize; +- _15 = const <() as std::mem::SizedTypeProperties>::ALIGN; ++ _15 = const 1_usize; StorageLive(_16); StorageLive(_18); StorageLive(_19); @@ -115,7 +115,7 @@ _19 = copy ((_17 as Ok).0: std::ptr::NonNull<[u8]>); StorageLive(_24); _24 = copy _19 as *mut [u8] (Transmute); - _14 = copy _24 as *mut u8 (PtrToPtr); + _12 = copy _24 as *mut u8 (PtrToPtr); StorageDead(_24); StorageDead(_17); StorageDead(_22); @@ -123,12 +123,12 @@ StorageDead(_19); StorageDead(_18); StorageDead(_16); - _3 = ShallowInitBox(copy _14, ()); - _15 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); -- (*_15) = move _4; -+ (*_15) = const (); StorageDead(_15); StorageDead(_14); + _3 = ShallowInitBox(copy _12, ()); + _13 = copy ((_3.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); +- (*_13) = move _4; ++ (*_13) = const (); StorageDead(_13); StorageDead(_12); StorageDead(_4); @@ -172,15 +172,15 @@ } bb5: { -- _22 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable]; +- _22 = Layout::from_size_align_unchecked::precondition_check(copy _14, copy _15) -> [return: bb6, unwind unreachable]; + _22 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { StorageDead(_21); StorageLive(_23); -- _23 = copy _13 as std::ptr::Alignment (Transmute); -- _16 = Layout { size: copy _12, align: move _23 }; +- _23 = copy _15 as std::ptr::Alignment (Transmute); +- _16 = Layout { size: copy _14, align: move _23 }; + _23 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); + _16 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; StorageDead(_23); diff --git a/tests/mir-opt/instsimplify/align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff b/tests/mir-opt/instsimplify/align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff index 042e19bf2aa18..bbcc9012a25dd 100644 --- a/tests/mir-opt/instsimplify/align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff +++ b/tests/mir-opt/instsimplify/align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff @@ -10,7 +10,7 @@ StorageLive(_2); _2 = &raw const (*_1); - _0 = std::intrinsics::align_of_val::<[T]>(move _2) -> [return: bb1, unwind unreachable]; -+ _0 = AlignOf(T); ++ _0 = const ::ALIGN; + goto -> bb1; } diff --git a/tests/mir-opt/instsimplify/align_of_slice.rs b/tests/mir-opt/instsimplify/align_of_slice.rs index 0af05cb6b0b02..99a68e444fe5d 100644 --- a/tests/mir-opt/instsimplify/align_of_slice.rs +++ b/tests/mir-opt/instsimplify/align_of_slice.rs @@ -7,6 +7,6 @@ // EMIT_MIR align_of_slice.of_val_slice.InstSimplify-after-simplifycfg.diff pub fn of_val_slice(slice: &[T]) -> usize { // CHECK-LABEL: fn of_val_slice(_1: &[T]) - // CHECK: _0 = AlignOf(T); + // CHECK: _0 = const ::ALIGN; unsafe { core::intrinsics::align_of_val(slice) } } diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir index 736a8bbca49c7..c46549c5742f2 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir @@ -3,49 +3,45 @@ fn test() -> Option> { let mut _0: std::option::Option>; let mut _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: std::ops::ControlFlow, u32>; - let mut _7: std::option::Option; - let mut _8: isize; - let _9: std::option::Option; - let mut _10: !; - let mut _11: std::option::Option; - let _12: u32; + let mut _2: *mut u8; + let mut _3: std::boxed::Box; + let mut _4: std::ops::ControlFlow, u32>; + let mut _5: std::option::Option; + let mut _6: isize; + let _7: std::option::Option; + let mut _8: !; + let mut _9: std::option::Option; + let _10: u32; scope 1 { - debug residual => _9; + debug residual => _7; scope 2 { } } scope 3 { - debug val => _12; + debug val => _10; scope 4 { } } bb0: { StorageLive(_1); - _2 = SizeOf(u32); - _3 = AlignOf(u32); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind: bb13]; + _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; } bb1: { + StorageLive(_3); + _3 = ShallowInitBox(move _2, u32); + StorageLive(_4); StorageLive(_5); - _5 = ShallowInitBox(move _4, u32); - StorageLive(_6); - StorageLive(_7); - _7 = Option::::None; - _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; + _5 = Option::::None; + _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_7); - PlaceMention(_6); - _8 = discriminant(_6); - switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; + StorageDead(_5); + PlaceMention(_4); + _6 = discriminant(_4); + switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3]; } bb3: { @@ -53,44 +49,44 @@ fn test() -> Option> { } bb4: { - StorageLive(_12); - _12 = copy ((_6 as Continue).0: u32); - (*_5) = copy _12; - StorageDead(_12); - _1 = move _5; - drop(_5) -> [return: bb7, unwind: bb11]; + StorageLive(_10); + _10 = copy ((_4 as Continue).0: u32); + (*_3) = copy _10; + StorageDead(_10); + _1 = move _3; + drop(_3) -> [return: bb7, unwind: bb11]; } bb5: { + StorageLive(_7); + _7 = copy ((_4 as Break).0: std::option::Option); StorageLive(_9); - _9 = copy ((_6 as Break).0: std::option::Option); - StorageLive(_11); - _11 = copy _9; - _0 = > as FromResidual>>::from_residual(move _11) -> [return: bb6, unwind: bb12]; + _9 = copy _7; + _0 = > as FromResidual>>::from_residual(move _9) -> [return: bb6, unwind: bb12]; } bb6: { - StorageDead(_11); StorageDead(_9); - drop(_5) -> [return: bb9, unwind: bb13]; + StorageDead(_7); + drop(_3) -> [return: bb9, unwind: bb13]; } bb7: { - StorageDead(_5); + StorageDead(_3); _0 = Option::>::Some(move _1); drop(_1) -> [return: bb8, unwind: bb13]; } bb8: { StorageDead(_1); - StorageDead(_6); + StorageDead(_4); goto -> bb10; } bb9: { - StorageDead(_5); + StorageDead(_3); StorageDead(_1); - StorageDead(_6); + StorageDead(_4); goto -> bb10; } @@ -103,7 +99,7 @@ fn test() -> Option> { } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate(cleanup)]; + drop(_3) -> [return: bb13, unwind terminate(cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir index 1acb1ae20b698..9f26debdbb6d6 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir @@ -3,49 +3,45 @@ fn test() -> Option> { let mut _0: std::option::Option>; let mut _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: std::ops::ControlFlow, u32>; - let mut _7: std::option::Option; - let mut _8: isize; - let _9: std::option::Option; - let mut _10: !; - let mut _11: std::option::Option; - let _12: u32; + let mut _2: *mut u8; + let mut _3: std::boxed::Box; + let mut _4: std::ops::ControlFlow, u32>; + let mut _5: std::option::Option; + let mut _6: isize; + let _7: std::option::Option; + let mut _8: !; + let mut _9: std::option::Option; + let _10: u32; scope 1 { - debug residual => _9; + debug residual => _7; scope 2 { } } scope 3 { - debug val => _12; + debug val => _10; scope 4 { } } bb0: { StorageLive(_1); - _2 = SizeOf(u32); - _3 = AlignOf(u32); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; + _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; } bb1: { + StorageLive(_3); + _3 = ShallowInitBox(move _2, u32); + StorageLive(_4); StorageLive(_5); - _5 = ShallowInitBox(move _4, u32); - StorageLive(_6); - StorageLive(_7); - _7 = Option::::None; - _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; + _5 = Option::::None; + _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_7); - PlaceMention(_6); - _8 = discriminant(_6); - switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; + StorageDead(_5); + PlaceMention(_4); + _6 = discriminant(_4); + switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3]; } bb3: { @@ -53,44 +49,44 @@ fn test() -> Option> { } bb4: { - StorageLive(_12); - _12 = copy ((_6 as Continue).0: u32); - (*_5) = copy _12; - StorageDead(_12); - _1 = move _5; - drop(_5) -> [return: bb7, unwind: bb11]; + StorageLive(_10); + _10 = copy ((_4 as Continue).0: u32); + (*_3) = copy _10; + StorageDead(_10); + _1 = move _3; + drop(_3) -> [return: bb7, unwind: bb11]; } bb5: { + StorageLive(_7); + _7 = copy ((_4 as Break).0: std::option::Option); StorageLive(_9); - _9 = copy ((_6 as Break).0: std::option::Option); - StorageLive(_11); - _11 = copy _9; - _0 = > as FromResidual>>::from_residual(move _11) -> [return: bb6, unwind: bb12]; + _9 = copy _7; + _0 = > as FromResidual>>::from_residual(move _9) -> [return: bb6, unwind: bb12]; } bb6: { - StorageDead(_11); StorageDead(_9); - drop(_5) -> [return: bb9, unwind continue]; + StorageDead(_7); + drop(_3) -> [return: bb9, unwind continue]; } bb7: { - StorageDead(_5); + StorageDead(_3); _0 = Option::>::Some(move _1); drop(_1) -> [return: bb8, unwind continue]; } bb8: { StorageDead(_1); - StorageDead(_6); + StorageDead(_4); goto -> bb10; } bb9: { - StorageDead(_5); + StorageDead(_3); StorageDead(_1); - StorageDead(_6); + StorageDead(_4); goto -> bb10; } @@ -103,7 +99,7 @@ fn test() -> Option> { } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate(cleanup)]; + drop(_3) -> [return: bb13, unwind terminate(cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-abort.diff deleted file mode 100644 index e61a3e8d73834..0000000000000 --- a/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-abort.diff +++ /dev/null @@ -1,17 +0,0 @@ -- // 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::() -> [return: bb1, unwind unreachable]; -+ _0 = AlignOf(T); -+ goto -> bb1; - } - - bb1: { - return; - } - } - diff --git a/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-unwind.diff deleted file mode 100644 index e61a3e8d73834..0000000000000 --- a/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-unwind.diff +++ /dev/null @@ -1,17 +0,0 @@ -- // 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::() -> [return: bb1, unwind unreachable]; -+ _0 = AlignOf(T); -+ goto -> bb1; - } - - bb1: { - return; - } - } - diff --git a/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-abort.diff index 5aa9869847680..42b8ab3da66c1 100644 --- a/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-abort.diff +++ b/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-abort.diff @@ -3,26 +3,21 @@ fn non_const() -> usize { let mut _0: usize; - let _1: fn() -> usize {std::intrinsics::size_of::}; - let mut _2: fn() -> usize {std::intrinsics::size_of::}; + let _1: unsafe fn() -> ! {std::intrinsics::unreachable}; + let mut _2: !; + let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable}; scope 1 { - debug size_of_t => _1; + debug unreachable => _1; } bb0: { StorageLive(_1); - _1 = std::intrinsics::size_of::; + _1 = std::intrinsics::unreachable; StorageLive(_2); - _2 = copy _1; -- _0 = move _2() -> [return: bb1, unwind unreachable]; -+ _0 = SizeOf(T); -+ goto -> bb1; - } - - bb1: { - StorageDead(_2); - StorageDead(_1); - return; + StorageLive(_3); + _3 = copy _1; +- _2 = move _3() -> unwind unreachable; ++ unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-unwind.diff index 5aa9869847680..42b8ab3da66c1 100644 --- a/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-unwind.diff +++ b/tests/mir-opt/lower_intrinsics.non_const.LowerIntrinsics.panic-unwind.diff @@ -3,26 +3,21 @@ fn non_const() -> usize { let mut _0: usize; - let _1: fn() -> usize {std::intrinsics::size_of::}; - let mut _2: fn() -> usize {std::intrinsics::size_of::}; + let _1: unsafe fn() -> ! {std::intrinsics::unreachable}; + let mut _2: !; + let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable}; scope 1 { - debug size_of_t => _1; + debug unreachable => _1; } bb0: { StorageLive(_1); - _1 = std::intrinsics::size_of::; + _1 = std::intrinsics::unreachable; StorageLive(_2); - _2 = copy _1; -- _0 = move _2() -> [return: bb1, unwind unreachable]; -+ _0 = SizeOf(T); -+ goto -> bb1; - } - - bb1: { - StorageDead(_2); - StorageDead(_1); - return; + StorageLive(_3); + _3 = copy _1; +- _2 = move _3() -> unwind unreachable; ++ unreachable; } } diff --git a/tests/mir-opt/lower_intrinsics.rs b/tests/mir-opt/lower_intrinsics.rs index 7729e502ad6b9..6b8c2a7902023 100644 --- a/tests/mir-opt/lower_intrinsics.rs +++ b/tests/mir-opt/lower_intrinsics.rs @@ -40,20 +40,6 @@ 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() -> usize { - // CHECK-LABEL: fn size_of( - // CHECK: {{_.*}} = SizeOf(T); - core::intrinsics::size_of::() -} - -// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff -pub fn align_of() -> usize { - // CHECK-LABEL: fn align_of( - // CHECK: {{_.*}} = AlignOf(T); - core::intrinsics::align_of::() -} - // EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff pub fn forget(t: T) { // CHECK-LABEL: fn forget( @@ -73,11 +59,13 @@ pub fn unreachable() -> ! { // EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff pub fn non_const() -> usize { // CHECK-LABEL: fn non_const( - // CHECK: SizeOf(T); + // CHECK: _1 = std::intrinsics::unreachable; + // CHECK: unreachable; + // CHECK-NEXT: } // Check that lowering works with non-const operand as a func. - let size_of_t = core::intrinsics::size_of::; - size_of_t() + let unreachable = core::intrinsics::unreachable; + unsafe { unreachable() } } // EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff diff --git a/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-abort.diff b/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-abort.diff deleted file mode 100644 index a547bdf3737b9..0000000000000 --- a/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-abort.diff +++ /dev/null @@ -1,17 +0,0 @@ -- // 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::() -> [return: bb1, unwind unreachable]; -+ _0 = SizeOf(T); -+ goto -> bb1; - } - - bb1: { - return; - } - } - diff --git a/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-unwind.diff b/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-unwind.diff deleted file mode 100644 index a547bdf3737b9..0000000000000 --- a/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-unwind.diff +++ /dev/null @@ -1,17 +0,0 @@ -- // 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::() -> [return: bb1, unwind unreachable]; -+ _0 = SizeOf(T); -+ goto -> bb1; - } - - bb1: { - return; - } - } - diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir index ba6ce0ee5286f..791d6b71a6f78 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir @@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb1: { - _6 = AlignOf(T); + _6 = const ::ALIGN; StorageLive(_7); _7 = copy _6 as std::ptr::Alignment (Transmute); _8 = move (_7.0: std::ptr::alignment::AlignmentEnum); diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir index ba6ce0ee5286f..791d6b71a6f78 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir @@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb1: { - _6 = AlignOf(T); + _6 = const ::ALIGN; StorageLive(_7); _7 = copy _6 as std::ptr::Alignment (Transmute); _8 = move (_7.0: std::ptr::alignment::AlignmentEnum); diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir index ba6ce0ee5286f..791d6b71a6f78 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir @@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb1: { - _6 = AlignOf(T); + _6 = const ::ALIGN; StorageLive(_7); _7 = copy _6 as std::ptr::Alignment (Transmute); _8 = move (_7.0: std::ptr::alignment::AlignmentEnum); diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir index ba6ce0ee5286f..791d6b71a6f78 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir @@ -73,7 +73,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { } bb1: { - _6 = AlignOf(T); + _6 = const ::ALIGN; StorageLive(_7); _7 = copy _6 as std::ptr::Alignment (Transmute); _8 = move (_7.0: std::ptr::alignment::AlignmentEnum); diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.rs b/tests/mir-opt/pre-codegen/drop_boxed_slice.rs index 9ceba9444b8da..83b10f8bd6888 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.rs +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.rs @@ -9,7 +9,7 @@ pub unsafe fn generic_in_place(ptr: *mut Box<[T]>) { // CHECK-LABEL: fn generic_in_place(_1: *mut Box<[T]>) // CHECK: (inlined as Drop>::drop) // CHECK: [[SIZE:_.+]] = std::intrinsics::size_of_val::<[T]> - // CHECK: [[ALIGN:_.+]] = AlignOf(T); + // CHECK: [[ALIGN:_.+]] = const ::ALIGN; // CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute); // CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum); // CHECK: [[D:_.+]] = discriminant([[C]]); diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index 66eb1bcfaa665..4260ec3eaedf1 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -3,17 +3,17 @@ fn vec_move(_1: Vec) -> () { debug v => _1; let mut _0: (); + let mut _21: std::vec::IntoIter; let mut _22: std::vec::IntoIter; - let mut _23: std::vec::IntoIter; - let mut _24: &mut std::vec::IntoIter; - let mut _25: std::option::Option; - let mut _26: isize; - let _28: (); + let mut _23: &mut std::vec::IntoIter; + let mut _24: std::option::Option; + let mut _25: isize; + let _27: (); scope 1 { - debug iter => _23; - let _27: impl Sized; + debug iter => _22; + let _26: impl Sized; scope 2 { - debug x => _27; + debug x => _26; } } scope 3 (inlined as IntoIterator>::into_iter) { @@ -24,16 +24,16 @@ fn vec_move(_1: Vec) -> () { let mut _10: *mut impl Sized; let mut _11: *const impl Sized; let mut _12: usize; - let _29: &std::vec::Vec; - let mut _30: &std::mem::ManuallyDrop>; - let mut _31: &alloc::raw_vec::RawVec; - let mut _32: &std::mem::ManuallyDrop>; - let _33: &std::vec::Vec; - let mut _34: &std::mem::ManuallyDrop>; - let _35: &std::vec::Vec; - let mut _36: &std::mem::ManuallyDrop>; - let mut _37: &alloc::raw_vec::RawVec; - let mut _38: &std::mem::ManuallyDrop>; + let _28: &std::vec::Vec; + let mut _29: &std::mem::ManuallyDrop>; + let mut _30: &alloc::raw_vec::RawVec; + let mut _31: &std::mem::ManuallyDrop>; + let _32: &std::vec::Vec; + let mut _33: &std::mem::ManuallyDrop>; + let _34: &std::vec::Vec; + let mut _35: &std::mem::ManuallyDrop>; + let mut _36: &alloc::raw_vec::RawVec; + let mut _37: &std::mem::ManuallyDrop>; scope 4 { debug me => _2; scope 5 { @@ -46,34 +46,33 @@ fn vec_move(_1: Vec) -> () { debug begin => _7; scope 8 { debug end => _11; - let _20: usize; + let _19: usize; scope 9 { - debug cap => _20; + debug cap => _19; } scope 39 (inlined > as Deref>::deref) { - debug self => _38; + debug self => _37; } scope 40 (inlined alloc::raw_vec::RawVec::::capacity) { - debug self => _37; - let mut _19: usize; - let mut _39: &alloc::raw_vec::RawVecInner; + debug self => _36; + let mut _38: &alloc::raw_vec::RawVecInner; scope 41 (inlined std::mem::size_of::) { } scope 42 (inlined alloc::raw_vec::RawVecInner::capacity) { - debug self => _39; - debug elem_size => _19; - let mut _21: core::num::niche_types::UsizeNoHighBit; + debug self => _38; + debug elem_size => const ::SIZE; + let mut _20: core::num::niche_types::UsizeNoHighBit; scope 43 (inlined core::num::niche_types::UsizeNoHighBit::as_inner) { - debug self => _21; + debug self => _20; } } } } scope 25 (inlined > as Deref>::deref) { - debug self => _34; + debug self => _33; } scope 26 (inlined Vec::::len) { - debug self => _33; + debug self => _32; let mut _13: bool; scope 27 { } @@ -108,10 +107,10 @@ fn vec_move(_1: Vec) -> () { } } scope 35 (inlined > as Deref>::deref) { - debug self => _36; + debug self => _35; } scope 36 (inlined Vec::::len) { - debug self => _35; + debug self => _34; let mut _9: bool; scope 37 { } @@ -126,10 +125,10 @@ fn vec_move(_1: Vec) -> () { } } scope 17 (inlined > as Deref>::deref) { - debug self => _32; + debug self => _31; } scope 18 (inlined alloc::raw_vec::RawVec::::non_null) { - debug self => _31; + debug self => _30; scope 19 (inlined alloc::raw_vec::RawVecInner::non_null::) { let mut _4: std::ptr::NonNull; scope 20 (inlined Unique::::cast::) { @@ -145,10 +144,10 @@ fn vec_move(_1: Vec) -> () { } } scope 11 (inlined > as Deref>::deref) { - debug self => _30; + debug self => _29; } scope 12 (inlined Vec::::allocator) { - debug self => _29; + debug self => _28; scope 13 (inlined alloc::raw_vec::RawVec::::allocator) { scope 14 (inlined alloc::raw_vec::RawVecInner::allocator) { } @@ -167,23 +166,23 @@ fn vec_move(_1: Vec) -> () { } bb0: { - StorageLive(_22); + StorageLive(_21); StorageLive(_6); StorageLive(_7); StorageLive(_11); - StorageLive(_20); + StorageLive(_19); StorageLive(_5); StorageLive(_4); StorageLive(_17); StorageLive(_2); _2 = ManuallyDrop::> { value: copy _1 }; StorageLive(_3); - // DBG: _30 = &_2; - // DBG: _29 = &(_2.0: std::vec::Vec); + // DBG: _29 = &_2; + // DBG: _28 = &(_2.0: std::vec::Vec); _3 = &raw const ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global); StorageDead(_3); - // DBG: _32 = &_2; - // DBG: _31 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + // DBG: _31 = &_2; + // DBG: _30 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); _4 = copy (((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); _5 = copy _4 as *const impl Sized (Transmute); _6 = NonNull:: { pointer: copy _5 }; @@ -194,8 +193,8 @@ fn vec_move(_1: Vec) -> () { bb1: { StorageLive(_10); StorageLive(_8); - // DBG: _36 = &_2; - // DBG: _35 = &(_2.0: std::vec::Vec); + // DBG: _35 = &_2; + // DBG: _34 = &(_2.0: std::vec::Vec); _8 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_9); _9 = Le(copy _8, const ::MAX_SLICE_LEN); @@ -210,8 +209,8 @@ fn vec_move(_1: Vec) -> () { bb2: { StorageLive(_12); - // DBG: _34 = &_2; - // DBG: _33 = &(_2.0: std::vec::Vec); + // DBG: _33 = &_2; + // DBG: _32 = &(_2.0: std::vec::Vec); _12 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_13); _13 = Le(copy _12, const ::MAX_SLICE_LEN); @@ -239,72 +238,69 @@ fn vec_move(_1: Vec) -> () { } bb4: { - // DBG: _38 = &_2; - // DBG: _37 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); - // DBG: _39 = &(((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); - StorageLive(_19); - _19 = SizeOf(impl Sized); - switchInt(move _19) -> [0: bb5, otherwise: bb6]; + // DBG: _37 = &_2; + // DBG: _36 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + // DBG: _38 = &(((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); + switchInt(const ::SIZE) -> [0: bb5, otherwise: bb6]; } bb5: { - _20 = const usize::MAX; + _19 = const usize::MAX; goto -> bb7; } bb6: { - StorageLive(_21); - _21 = copy ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit); - _20 = copy _21 as usize (Transmute); - StorageDead(_21); + StorageLive(_20); + _20 = copy ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: core::num::niche_types::UsizeNoHighBit); + _19 = copy _20 as usize (Transmute); + StorageDead(_20); goto -> bb7; } bb7: { - StorageDead(_19); - _22 = std::vec::IntoIter:: { buf: copy _6, phantom: const ZeroSized: PhantomData, cap: move _20, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 }; + _21 = std::vec::IntoIter:: { buf: copy _6, phantom: const ZeroSized: PhantomData, cap: move _19, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: copy _6, end: copy _11 }; StorageDead(_2); StorageDead(_17); StorageDead(_4); StorageDead(_5); - StorageDead(_20); + StorageDead(_19); StorageDead(_11); StorageDead(_7); StorageDead(_6); - StorageLive(_23); - _23 = move _22; + StorageLive(_22); + _22 = move _21; goto -> bb8; } bb8: { - StorageLive(_25); - _24 = &mut _23; - _25 = as Iterator>::next(move _24) -> [return: bb9, unwind: bb15]; + StorageLive(_24); + _23 = &mut _22; + _24 = as Iterator>::next(move _23) -> [return: bb9, unwind: bb15]; } bb9: { - _26 = discriminant(_25); - switchInt(move _26) -> [0: bb10, 1: bb12, otherwise: bb14]; + _25 = discriminant(_24); + switchInt(move _25) -> [0: bb10, 1: bb12, otherwise: bb14]; } bb10: { - StorageDead(_25); - drop(_23) -> [return: bb11, unwind continue]; + StorageDead(_24); + drop(_22) -> [return: bb11, unwind continue]; } bb11: { - StorageDead(_23); StorageDead(_22); + StorageDead(_21); return; } bb12: { - _27 = move ((_25 as Some).0: impl Sized); - _28 = opaque::(move _27) -> [return: bb13, unwind: bb15]; + _26 = move ((_24 as Some).0: impl Sized); + _27 = opaque::(move _26) -> [return: bb13, unwind: bb15]; } bb13: { - StorageDead(_25); + StorageDead(_24); goto -> bb8; } @@ -313,7 +309,7 @@ fn vec_move(_1: Vec) -> () { } bb15 (cleanup): { - drop(_23) -> [return: bb16, unwind terminate(cleanup)]; + drop(_22) -> [return: bb16, unwind terminate(cleanup)]; } bb16 (cleanup): { diff --git a/tests/ui-fulldeps/rustc_public/check_def_ty.rs b/tests/ui-fulldeps/rustc_public/check_def_ty.rs index 176a9d79ef111..4a45bb6daa5f4 100644 --- a/tests/ui-fulldeps/rustc_public/check_def_ty.rs +++ b/tests/ui-fulldeps/rustc_public/check_def_ty.rs @@ -90,15 +90,13 @@ 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::::new(); - let _i = std::intrinsics::size_of::(); + let _i = std::mem::size_of::(); }} extern "C" {{ diff --git a/tests/ui/const-generics/generic_const_exprs/issue-80742.rs b/tests/ui/const-generics/generic_const_exprs/issue-80742.rs index ac4d9fc0f4f42..0d392902be871 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.rs @@ -1,12 +1,4 @@ //@ 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)] @@ -34,4 +26,6 @@ where fn main() { let dst = Inline::::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` } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr b/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr index 07fd231cb7ae9..ac1bfc8d7a1b9 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr @@ -1,11 +1,42 @@ -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[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::::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 + | ^ required by the implicit `Sized` requirement on this type parameter in `Inline` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct Inline + | ++++++++ +error[E0599]: the function or associated item `new` exists for struct `Inline`, but its trait bounds were not satisfied + --> $DIR/issue-80742.rs:28:36 + | +LL | struct Inline + | ---------------- function or associated item `new` not found for this struct +... +LL | let dst = Inline::::new(0); + | ^^^ function or associated item cannot be called on `Inline` due to unsatisfied trait bounds + | +note: trait bound `dyn Debug: Sized` was not satisfied + --> $DIR/issue-80742.rs:18:6 + | +LL | impl Inline + | ^ --------- + | | + | unsatisfied trait bound introduced here +help: consider relaxing the type parameter's implicit `Sized` bound + | +LL | impl Inline + | ++++++++ -Box -query stack during panic: -#0 [eval_to_allocation_raw] const-evaluating + checking `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 +error: aborting due to 2 previous errors +Some errors have detailed explanations: E0277, E0599. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/crashes/119729.rs b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs similarity index 52% rename from tests/crashes/119729.rs rename to tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs index ed07c58e89fdf..ee5d65cf4b2ba 100644 --- a/tests/crashes/119729.rs +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs @@ -1,5 +1,7 @@ -//@ known-bug: #119729 +//! Regression test for #119729 + #![feature(generic_const_exprs)] +#![allow(incomplete_features)] trait Size {} @@ -10,3 +12,7 @@ struct A + ?Sized> { } fn foo(x: A) {} +//~^ ERROR mismatched types +//~| ERROR the size for values of type `(dyn Send + 'static)` cannot be known at compilation time + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.stderr b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.stderr new file mode 100644 index 0000000000000..71fea4df163d1 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.stderr @@ -0,0 +1,38 @@ +error[E0308]: mismatched types + --> $DIR/size_of-dyn-trait-2.rs:14:11 + | +LL | fn foo(x: A) {} + | ^^^^^^^^^^^ expected `8`, found `{ std::mem::size_of::() }` + | + = note: expected constant `8` + found constant `{ std::mem::size_of::() }` +note: required by a bound in `A` + --> $DIR/size_of-dyn-trait-2.rs:10:13 + | +LL | struct A + ?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) {} + | ^^^^^^^^^^^ 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 Size<{ std::mem::size_of::() }> 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 + ?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`. diff --git a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.rs b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.rs new file mode 100644 index 0000000000000..afb086a41305b --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.rs @@ -0,0 +1,21 @@ +//! Regression test for #114663 +//@ edition:2021 + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +use core::fmt::Debug; +use core::marker::PhantomData; + +struct Inline +where + [u8; ::core::mem::size_of::() + 1]:, +{ + _phantom: PhantomData, +} + +fn main() { + let dst = Inline::::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` +} diff --git a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.stderr b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.stderr new file mode 100644 index 0000000000000..bcc253ed96705 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.stderr @@ -0,0 +1,30 @@ +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::::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 + | ^ required by the implicit `Sized` requirement on this type parameter in `Inline` +help: consider relaxing the implicit `Sized` restriction + | +LL | struct Inline + | ++++++++ + +error[E0599]: no function or associated item named `new` found for struct `Inline` in the current scope + --> $DIR/size_of-dyn-trait-3.rs:18:36 + | +LL | struct Inline + | ---------------- function or associated item `new` not found for this struct +... +LL | let dst = Inline::::new(0); + | ^^^ function or associated item not found in `Inline` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0599. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/crashes/136175.rs b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.rs similarity index 57% rename from tests/crashes/136175.rs rename to tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.rs index 0b5f2fdaa922f..34b4734f4772c 100644 --- a/tests/crashes/136175.rs +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.rs @@ -1,4 +1,5 @@ -//@ known-bug: #136175 +//! Regression test for #136175 + #![feature(generic_const_exprs)] #![allow(incomplete_features)] @@ -10,4 +11,5 @@ where fn main() { let x: A; + //~^ ERROR the size for values of type `dyn Trait` cannot be known at compilation time } diff --git a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr new file mode 100644 index 0000000000000..4669a2f1ce7df --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr @@ -0,0 +1,23 @@ +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; + | ^^^^^^^^^^^^ 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) + | ^ 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` + --> $DIR/size_of-dyn-trait.rs:8:10 + | +LL | struct A(T) + | ^ - ...if indirection were used here: `Box` + | | + | this could be changed to `T: ?Sized`... + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/const-size_of-cycle.stderr b/tests/ui/consts/const-size_of-cycle.stderr index b127f83d8853c..01aa5e726b451 100644 --- a/tests/ui/consts/const-size_of-cycle.stderr +++ b/tests/ui/consts/const-size_of-cycle.stderr @@ -5,10 +5,11 @@ LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... - --> $DIR/const-size_of-cycle.rs:2:17 - | -LL | bytes: [u8; std::mem::size_of::()] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + --> $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 = note: ...which requires computing layout of `Foo`... = note: ...which requires computing layout of `[u8; std::mem::size_of::()]`... note: ...which requires normalizing `[u8; std::mem::size_of::()]`... diff --git a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.rs b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.rs index 7f85cbf227aef..771656a2c462b 100644 --- a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.rs +++ b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.rs @@ -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. diff --git a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.stderr b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.stderr index a3772e509ed67..73e1578242675 100644 --- a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.stderr +++ b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-1.stderr @@ -1,4 +1,14 @@ -error: values of the type `[u8; usize::MAX]` are too big for the target architecture +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 ` as std::mem::SizedTypeProperties>::SIZE` failed here + +note: the above error was encountered while instantiating `fn std::mem::size_of::>` + --> $DIR/debuginfo-type-name-layout-ice-94961-1.rs:13:5 + | +LL | std::mem::size_of::>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-2.stderr b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-2.stderr index a3772e509ed67..4ce1e2e407e9d 100644 --- a/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-2.stderr +++ b/tests/ui/debuginfo/debuginfo-type-name-layout-ice-94961-2.stderr @@ -1,4 +1,14 @@ -error: values of the type `[u8; usize::MAX]` are too big for the target architecture +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 ` as std::mem::SizedTypeProperties>::SIZE` failed here + +note: the above error was encountered while instantiating `fn std::mem::size_of::>` + --> $DIR/debuginfo-type-name-layout-ice-94961-2.rs:16:5 + | +LL | std::mem::size_of::>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/generics/issue-32498.rs b/tests/ui/generics/issue-32498.rs index b7685ac733605..871914f0b36e1 100644 --- a/tests/ui/generics/issue-32498.rs +++ b/tests/ui/generics/issue-32498.rs @@ -1,5 +1,6 @@ //@ run-pass #![allow(dead_code)] +#![recursion_limit = "256"] // Making sure that no overflow occurs. diff --git a/tests/ui/intrinsics/intrinsic-alignment.rs b/tests/ui/intrinsics/intrinsic-alignment.rs index 904da71c306b0..5fee6b0b39783 100644 --- a/tests/ui/intrinsics/intrinsic-alignment.rs +++ b/tests/ui/intrinsics/intrinsic-alignment.rs @@ -2,8 +2,6 @@ #![feature(core_intrinsics, rustc_attrs)] -use std::intrinsics as rusti; - #[cfg(any( target_os = "aix", target_os = "android", @@ -23,12 +21,12 @@ use std::intrinsics as rusti; mod m { #[cfg(target_arch = "x86")] pub fn main() { - assert_eq!(crate::rusti::align_of::(), 4); + assert_eq!(std::mem::align_of::(), 4); } #[cfg(not(target_arch = "x86"))] pub fn main() { - assert_eq!(crate::rusti::align_of::(), 8); + assert_eq!(std::mem::align_of::(), 8); } } @@ -36,21 +34,21 @@ mod m { mod m { #[cfg(target_arch = "x86_64")] pub fn main() { - assert_eq!(crate::rusti::align_of::(), 8); + assert_eq!(std::mem::align_of::(), 8); } } #[cfg(target_os = "windows")] mod m { pub fn main() { - assert_eq!(crate::rusti::align_of::(), 8); + assert_eq!(std::mem::align_of::(), 8); } } #[cfg(target_family = "wasm")] mod m { pub fn main() { - assert_eq!(crate::rusti::align_of::(), 8); + assert_eq!(std::mem::align_of::(), 8); } } diff --git a/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs b/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs index 8da2bb385ef25..31d70c1dd9ec0 100644 --- a/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs +++ b/tests/ui/layout/invalid-unsized-in-always-sized-tail.rs @@ -13,6 +13,6 @@ struct P2 { } static CHECK: () = assert!(align_of::() == 1); -//~^ ERROR the type `MySlice<[bool]>` has an unknown layout +//~? ERROR the type `MySlice<[bool]>` has an unknown layout fn main() {} diff --git a/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr b/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr index 5f6a6099ba23e..b08e37dbd7472 100644 --- a/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr +++ b/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr @@ -19,13 +19,9 @@ LL | struct MySlice(T); | this could be changed to `T: ?Sized`... error[E0080]: the type `MySlice<[bool]>` has an unknown layout - --> $DIR/invalid-unsized-in-always-sized-tail.rs:15:28 - | -LL | static CHECK: () = assert!(align_of::() == 1); - | ^^^^^^^^^^^^^^^^ evaluation of `CHECK` failed inside this call - | -note: inside `std::mem::align_of::` --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | + = note: evaluation of `::ALIGN` failed here error: aborting due to 2 previous errors diff --git a/tests/ui/layout/layout-cycle.rs b/tests/ui/layout/layout-cycle.rs index 3c930def43b2b..b38bd52c6ade9 100644 --- a/tests/ui/layout/layout-cycle.rs +++ b/tests/ui/layout/layout-cycle.rs @@ -1,6 +1,6 @@ //@ build-fail -//~^ ERROR: a cycle occurred during layout computation -//~| ERROR: cycle detected when computing layout of +//~^ ERROR: cycle detected when computing layout of +//~? ERROR: a cycle occurred during layout computation // Issue #111176 -- ensure that we do not emit ICE on layout cycles diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr index a3cdb7edcc232..e05ff614567c4 100644 --- a/tests/ui/layout/layout-cycle.stderr +++ b/tests/ui/layout/layout-cycle.stderr @@ -2,10 +2,22 @@ error[E0391]: cycle detected when computing layout of `S>` | = note: ...which requires computing layout of ` as Tr>::I`... = note: ...which again requires computing layout of `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: failed to get layout for S>: a cycle occurred during layout computation +error[E0080]: a cycle occurred during layout computation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | + = note: evaluation of `> as std::mem::SizedTypeProperties>::SIZE` failed here + +note: the above error was encountered while instantiating `fn std::mem::size_of::>>` + --> $DIR/layout-cycle.rs:26:5 + | +LL | mem::size_of::>() + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0391`. +Some errors have detailed explanations: E0080, E0391. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.rs b/tests/ui/limits/issue-17913.rs index 85deab4bc4c74..1c67243ce8a1a 100644 --- a/tests/ui/limits/issue-17913.rs +++ b/tests/ui/limits/issue-17913.rs @@ -1,5 +1,6 @@ //@ build-fail //@ normalize-stderr: "\[&usize; \d+\]" -> "[&usize; usize::MAX]" +//@ normalize-stderr: "\[&n; 0x[0-9A-F]+_usize\]" -> "[&n; SIZE]" #[cfg(target_pointer_width = "64")] fn main() { @@ -16,3 +17,4 @@ fn main() { } //~? ERROR are too big for the target architecture +//~? ERROR are too big for the target architecture diff --git a/tests/ui/limits/issue-17913.stderr b/tests/ui/limits/issue-17913.stderr index e9c3c14e18143..aabd6bcade2e7 100644 --- a/tests/ui/limits/issue-17913.stderr +++ b/tests/ui/limits/issue-17913.stderr @@ -1,5 +1,19 @@ -error: values of the type `[&usize; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/alloc/src/boxed.rs:LL:COL +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: aborting due to 1 previous error +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:8: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`. diff --git a/tests/ui/limits/issue-55878.rs b/tests/ui/limits/issue-55878.rs index 9e75f00a408f9..10fa1dd06d64d 100644 --- a/tests/ui/limits/issue-55878.rs +++ b/tests/ui/limits/issue-55878.rs @@ -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 } diff --git a/tests/ui/limits/issue-55878.stderr b/tests/ui/limits/issue-55878.stderr index a529efa2ad063..994e43854f825 100644 --- a/tests/ui/limits/issue-55878.stderr +++ b/tests/ui/limits/issue-55878.stderr @@ -1,11 +1,7 @@ error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture - --> $DIR/issue-55878.rs:4:26 - | -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 + | + = note: evaluation of `<[u8; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here error: aborting due to 1 previous error diff --git a/tests/ui/limits/issue-75158-64.rs b/tests/ui/limits/issue-75158-64.rs index b294b147a91a2..a49195bb3dc1a 100644 --- a/tests/ui/limits/issue-75158-64.rs +++ b/tests/ui/limits/issue-75158-64.rs @@ -1,4 +1,4 @@ -//~ ERROR +//~? ERROR values of the type `[u8; usize::MAX]` are too big for the target architecture //@ build-fail //@ ignore-32bit diff --git a/tests/ui/limits/issue-75158-64.stderr b/tests/ui/limits/issue-75158-64.stderr index a3772e509ed67..bab0e1b777c28 100644 --- a/tests/ui/limits/issue-75158-64.stderr +++ b/tests/ui/limits/issue-75158-64.stderr @@ -1,4 +1,14 @@ -error: values of the type `[u8; usize::MAX]` are too big for the target architecture +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 ` as std::mem::SizedTypeProperties>::SIZE` failed here + +note: the above error was encountered while instantiating `fn std::mem::size_of::>` + --> $DIR/issue-75158-64.rs:11:5 + | +LL | std::mem::size_of::>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/query-system/query_depth.rs b/tests/ui/query-system/query_depth.rs index 29514b58e2422..da6bafa51ab24 100644 --- a/tests/ui/query-system/query_depth.rs +++ b/tests/ui/query-system/query_depth.rs @@ -26,6 +26,6 @@ type Byte = Option>>> >>>>; fn main() { -//~^ ERROR: queries overflow the depth limit! +//~? ERROR: queries overflow the depth limit! println!("{}", std::mem::size_of::()); } diff --git a/tests/ui/query-system/query_depth.stderr b/tests/ui/query-system/query_depth.stderr index f738b01ed6ca7..abb6365765f09 100644 --- a/tests/ui/query-system/query_depth.stderr +++ b/tests/ui/query-system/query_depth.stderr @@ -1,11 +1,8 @@ error: queries overflow the depth limit! - --> $DIR/query_depth.rs:28:1 - | -LL | fn main() { - | ^^^^^^^^^ + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`) - = note: query depth increased by 65 when computing layout of `core::option::Option>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + = note: query depth increased by 64 when computing layout of `core::option::Option>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` error: aborting due to 1 previous error diff --git a/tests/ui/structs-enums/rec-align-u32.rs b/tests/ui/structs-enums/rec-align-u32.rs index b18cd11198e8d..058f06732b927 100644 --- a/tests/ui/structs-enums/rec-align-u32.rs +++ b/tests/ui/structs-enums/rec-align-u32.rs @@ -6,7 +6,6 @@ #![feature(core_intrinsics, rustc_attrs)] use std::mem; -use std::intrinsics; // This is the type with the questionable alignment #[derive(Debug)] @@ -34,12 +33,12 @@ pub fn main() { // Send it through the shape code let y = format!("{:?}", x); - println!("align inner = {:?}", intrinsics::align_of::()); + println!("align inner = {:?}", mem::align_of::()); println!("size outer = {:?}", mem::size_of::()); println!("y = {:?}", y); // per clang/gcc the alignment of `inner` is 4 on x86. - assert_eq!(intrinsics::align_of::(), m::align()); + assert_eq!(mem::align_of::(), m::align()); // per clang/gcc the size of `outer` should be 12 // because `inner`s alignment was 4. diff --git a/tests/ui/structs-enums/rec-align-u64.rs b/tests/ui/structs-enums/rec-align-u64.rs index df219892d7374..41b196dc5c222 100644 --- a/tests/ui/structs-enums/rec-align-u64.rs +++ b/tests/ui/structs-enums/rec-align-u64.rs @@ -7,7 +7,6 @@ #![feature(core_intrinsics, rustc_attrs)] use std::mem; -use std::intrinsics; // This is the type with the questionable alignment #[derive(Debug)] @@ -84,12 +83,12 @@ pub fn main() { let y = format!("{:?}", x); - println!("align inner = {:?}", intrinsics::align_of::()); + println!("align inner = {:?}", mem::align_of::()); println!("size outer = {:?}", mem::size_of::()); println!("y = {:?}", y); // per clang/gcc the alignment of `Inner` is 4 on x86. - assert_eq!(intrinsics::align_of::(), m::m::align()); + assert_eq!(mem::align_of::(), m::m::align()); // per clang/gcc the size of `Outer` should be 12 // because `Inner`s alignment was 4.