diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d1d0bff8fe06b..984a154853a98 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1046,6 +1046,16 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } + &Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => { + let trait_ref = + ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [ty]); + + self.prove_trait_ref( + trait_ref, + location.to_locations(), + ConstraintCategory::SizedBound, + ); + } &Rvalue::NullaryOp(NullOp::ContractChecks, _) => {} &Rvalue::NullaryOp(NullOp::UbChecks, _) => {} diff --git a/compiler/rustc_codegen_cranelift/example/example.rs b/compiler/rustc_codegen_cranelift/example/example.rs index 769d262b9ebb5..aeb38331edb02 100644 --- a/compiler/rustc_codegen_cranelift/example/example.rs +++ b/compiler/rustc_codegen_cranelift/example/example.rs @@ -72,6 +72,10 @@ 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 304d0d648561e..2f53bbf8b7934 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -6,7 +6,6 @@ extern_types, decl_macro, rustc_attrs, - rustc_private, transparent_unions, auto_traits, freeze_impls, @@ -595,7 +594,7 @@ impl, U: ?Sized> CoerceUnsized> for Box {} impl Box { pub fn new(val: T) -> Box { unsafe { - let size = size_of::(); + let size = intrinsics::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) @@ -647,11 +646,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub fn abort() -> !; #[rustc_intrinsic] - pub const fn size_of() -> usize; + pub fn size_of() -> usize; #[rustc_intrinsic] pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] - pub const fn align_of() -> usize; + pub fn align_of() -> usize; #[rustc_intrinsic] pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] @@ -716,23 +715,6 @@ impl Index for [T] { } } -pub const fn size_of() -> usize { - ::SIZE -} - -pub const fn align_of() -> usize { - ::ALIGN -} - -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 a9388814a7f59..86602c6b2a3fd 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 + size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8)); } unsafe { - puts(*((argv as usize + 2 * size_of::<*const u8>()) as *const *const i8)); + puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8)); } } @@ -213,8 +213,8 @@ fn main() { assert_eq!(intrinsics::size_of_val(a) as u8, 16); assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4); - assert_eq!(align_of::() as u8, 2); - assert_eq!(intrinsics::align_of_val(&a) as u8, align_of::<&str>() as u8); + assert_eq!(intrinsics::align_of::() as u8, 2); + assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8); let u8_needs_drop = const { intrinsics::needs_drop::() }; assert!(!u8_needs_drop); diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 7d50548b40262..c97218797107b 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -833,6 +833,8 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env())); let layout = fx.layout_of(fx.monomorphize(ty)); let val = match null_op { + NullOp::SizeOf => layout.size.bytes(), + NullOp::AlignOf => layout.align.bytes(), NullOp::OffsetOf(fields) => fx .tcx .offset_of_subfield( diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 640f7211dc994..0c626a9cd7817 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -611,6 +611,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let ty = self.monomorphize(ty); let layout = bx.cx().layout_of(ty); let val = match null_op { + mir::NullOp::SizeOf => { + assert!(bx.cx().type_is_sized(ty)); + let val = layout.size.bytes(); + bx.cx().const_usize(val) + } + mir::NullOp::AlignOf => { + assert!(bx.cx().type_is_sized(ty)); + let val = layout.align.bytes(); + bx.cx().const_usize(val) + } mir::NullOp::OffsetOf(fields) => { let val = bx .tcx() diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index ca173fe26c2f6..2c6dd5bd01f9c 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -646,7 +646,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { Rvalue::Cast(_, _, _) => {} Rvalue::NullaryOp( - NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, + NullOp::SizeOf + | NullOp::AlignOf + | NullOp::OffsetOf(_) + | NullOp::UbChecks + | NullOp::ContractChecks, _, ) => {} Rvalue::ShallowInitBox(_, _) => {} diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index bf5787c86bd55..4da2663319c34 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -414,6 +414,8 @@ fn report_eval_error<'tcx>( let (error, backtrace) = error.into_parts(); backtrace.print_backtrace(); + let instance = with_no_trimmed_paths!(cid.instance.to_string()); + super::report( ecx, error, @@ -428,7 +430,7 @@ fn report_eval_error<'tcx>( diag.subdiagnostic(frame); } // Add after the frame rendering above, as it adds its own `instance` args. - diag.arg("instance", with_no_trimmed_paths!(cid.instance.to_string())); + diag.arg("instance", instance); diag.arg("num_frames", num_frames); }, ) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index f0f06d469c1e6..fc7f1166af99a 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -156,24 +156,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let b_ty = self.read_type_id(&args[1])?; self.write_scalar(Scalar::from_bool(a_ty == b_ty), dest)?; } - sym::size_of => { - let tp_ty = instance.args.type_at(0); - let layout = self.layout_of(tp_ty)?; - if !layout.is_sized() { - span_bug!(self.cur_span(), "unsized type for `size_of`"); - } - let val = layout.size.bytes(); - self.write_scalar(Scalar::from_target_usize(val, self), dest)?; - } - sym::align_of => { - let tp_ty = instance.args.type_at(0); - let layout = self.layout_of(tp_ty)?; - if !layout.is_sized() { - span_bug!(self.cur_span(), "unsized type for `align_of`"); - } - let val = layout.align.bytes(); - self.write_scalar(Scalar::from_target_usize(val, self), dest)?; - } sym::variant_count => { let tp_ty = instance.args.type_at(0); let ty = match tp_ty.kind() { diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 58b90abf01295..f0819423aa0fa 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -517,6 +517,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let usize_layout = || self.layout_of(self.tcx.types.usize).unwrap(); interp_ok(match null_op { + SizeOf => { + if !layout.is_sized() { + span_bug!(self.cur_span(), "unsized type for `NullaryOp::SizeOf`"); + } + let val = layout.size.bytes(); + ImmTy::from_uint(val, usize_layout()) + } + AlignOf => { + if !layout.is_sized() { + span_bug!(self.cur_span(), "unsized type for `NullaryOp::AlignOf`"); + } + let val = layout.align.bytes(); + ImmTy::from_uint(val, usize_layout()) + } OffsetOf(fields) => { let val = self.tcx.offset_of_subfield(self.typing_env, layout, fields.iter()).bytes(); diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 9f7f4c7583412..311cf8f995c82 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -168,8 +168,6 @@ language_item_table! { MetaSized, sym::meta_sized, meta_sized_trait, Target::Trait, GenericRequirement::Exact(0); PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0); Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1); - AlignOf, sym::mem_align_const, align_const, Target::AssocConst, GenericRequirement::Exact(0); - SizeOf, sym::mem_size_const, size_const, Target::AssocConst, GenericRequirement::Exact(0); /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ"). StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None; Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 17d8eeee68bfd..60c2ef4d563e4 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1092,6 +1092,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { NullaryOp(ref op, ref t) => { let t = with_no_trimmed_paths!(format!("{}", t)); match op { + NullOp::SizeOf => write!(fmt, "SizeOf({t})"), + NullOp::AlignOf => write!(fmt, "AlignOf({t})"), NullOp::OffsetOf(fields) => write!(fmt, "OffsetOf({t}, {fields:?})"), NullOp::UbChecks => write!(fmt, "UbChecks()"), NullOp::ContractChecks => write!(fmt, "ContractChecks()"), diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 3cbb4b70b062a..91a528678901b 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -597,18 +597,6 @@ impl<'tcx> Operand<'tcx> { })) } - /// Convenience helper to make a constant that refers to the given `DefId` and args. Since this - /// is used to synthesize MIR, assumes `user_ty` is None. - pub fn unevaluated_constant( - tcx: TyCtxt<'tcx>, - def_id: DefId, - args: &[GenericArg<'tcx>], - span: Span, - ) -> Self { - let const_ = Const::from_unevaluated(tcx, def_id).instantiate(tcx, args); - Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ })) - } - pub fn is_move(&self) -> bool { matches!(self, Operand::Move(..)) } @@ -794,7 +782,9 @@ impl<'tcx> Rvalue<'tcx> { op.ty(tcx, arg_ty) } Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx), - Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => tcx.types.usize, + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => { + tcx.types.usize + } Rvalue::NullaryOp(NullOp::ContractChecks, _) | Rvalue::NullaryOp(NullOp::UbChecks, _) => tcx.types.bool, Rvalue::Aggregate(ref ak, ref ops) => match **ak { @@ -863,7 +853,7 @@ impl BorrowKind { impl<'tcx> NullOp<'tcx> { pub fn ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self { - NullOp::OffsetOf(_) => tcx.types.usize, + NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) => tcx.types.usize, NullOp::UbChecks | NullOp::ContractChecks => tcx.types.bool, } } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 9d99239546ae2..38f03cf4e8a00 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1563,6 +1563,10 @@ pub enum AggregateKind<'tcx> { #[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] pub enum NullOp<'tcx> { + /// Returns the size of a value of that type + SizeOf, + /// Returns the minimum alignment of a type + AlignOf, /// Returns the offset of a field OffsetOf(&'tcx List<(VariantIdx, FieldIdx)>), /// Returns whether we should perform some UB-checking at runtime. 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 552f8c66784ed..3a5839f2d404d 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -126,12 +126,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let tcx = this.tcx; let source_info = this.source_info(expr_span); - let size = tcx.require_lang_item(LangItem::SizeOf, expr_span); - let size = Operand::unevaluated_constant(tcx, size, &[value_ty.into()], expr_span); + let size = this.temp(tcx.types.usize, expr_span); + this.cfg.push_assign( + block, + source_info, + size, + Rvalue::NullaryOp(NullOp::SizeOf, value_ty), + ); - let align = tcx.require_lang_item(LangItem::AlignOf, expr_span); - let align = - Operand::unevaluated_constant(tcx, align, &[value_ty.into()], expr_span); + let align = this.temp(tcx.types.usize, expr_span); + this.cfg.push_assign( + block, + source_info, + align, + Rvalue::NullaryOp(NullOp::AlignOf, value_ty), + ); // malloc some memory of suitable size and align: let exchange_malloc = Operand::function_handle( @@ -148,8 +157,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { TerminatorKind::Call { func: exchange_malloc, args: [ - Spanned { node: size, span: DUMMY_SP }, - Spanned { node: align, span: DUMMY_SP }, + Spanned { node: Operand::Move(size), span: DUMMY_SP }, + Spanned { node: Operand::Move(align), span: DUMMY_SP }, ] .into(), destination: storage, diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index dd65f0699e97e..b45f8a724c69f 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -452,7 +452,11 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { | Rvalue::RawPtr(..) | Rvalue::Discriminant(..) | Rvalue::NullaryOp( - NullOp::OffsetOf(..) | NullOp::UbChecks | NullOp::ContractChecks, + NullOp::SizeOf + | NullOp::AlignOf + | NullOp::OffsetOf(..) + | NullOp::UbChecks + | NullOp::ContractChecks, _, ) => {} } diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index e06883dd0fd10..989787504b7b8 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -1,5 +1,4 @@ use rustc_abi::Align; -use rustc_hir::LangItem; use rustc_index::IndexVec; use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::visit::PlaceContext; @@ -60,9 +59,10 @@ fn insert_alignment_check<'tcx>( stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((addr, rvalue))))); // Get the alignment of the pointee - let align_def_id = tcx.require_lang_item(LangItem::AlignOf, source_info.span); let alignment = - Operand::unevaluated_constant(tcx, align_def_id, &[pointee_ty.into()], source_info.span); + local_decls.push(LocalDecl::with_source_info(tcx.types.usize, source_info)).into(); + let rvalue = Rvalue::NullaryOp(NullOp::AlignOf, pointee_ty); + stmts.push(Statement::new(source_info, StatementKind::Assign(Box::new((alignment, rvalue))))); // Subtract 1 from the alignment to get the alignment mask let alignment_mask = @@ -76,7 +76,7 @@ fn insert_alignment_check<'tcx>( source_info, StatementKind::Assign(Box::new(( alignment_mask, - Rvalue::BinaryOp(BinOp::Sub, Box::new((alignment.clone(), one))), + Rvalue::BinaryOp(BinOp::Sub, Box::new((Operand::Copy(alignment), one))), ))), )); @@ -141,7 +141,7 @@ fn insert_alignment_check<'tcx>( PointerCheck { cond: Operand::Copy(is_ok), assert_kind: Box::new(AssertKind::MisalignedPointerDereference { - required: alignment, + required: Operand::Copy(alignment), found: Operand::Copy(addr), }), } diff --git a/compiler/rustc_mir_transform/src/check_null.rs b/compiler/rustc_mir_transform/src/check_null.rs index c73b4d7db243f..e365d36580ad5 100644 --- a/compiler/rustc_mir_transform/src/check_null.rs +++ b/compiler/rustc_mir_transform/src/check_null.rs @@ -1,4 +1,3 @@ -use rustc_hir::LangItem; use rustc_index::IndexVec; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext}; use rustc_middle::mir::*; @@ -63,23 +62,35 @@ fn insert_null_check<'tcx>( Operand::Constant(Box::new(ConstOperand { span: source_info.span, user_ty: None, - const_: Const::from_bool(tcx, true), + const_: Const::Val(ConstValue::from_bool(true), tcx.types.bool), })) } // Other usages of null pointers only are UB if the pointee is not a ZST. _ => { - let size_of = tcx.require_lang_item(LangItem::SizeOf, source_info.span); - let size_of = - Operand::unevaluated_constant(tcx, size_of, &[pointee_ty.into()], source_info.span); + let 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 pointee_should_be_checked = + // Check that the pointee is not a ZST. + let is_pointee_not_zst = local_decls.push(LocalDecl::with_source_info(tcx.types.bool, source_info)).into(); - let rvalue = Rvalue::BinaryOp(BinOp::Ne, Box::new((size_of, zero.clone()))); stmts.push(Statement::new( source_info, - StatementKind::Assign(Box::new((pointee_should_be_checked, rvalue))), + StatementKind::Assign(Box::new(( + is_pointee_not_zst, + Rvalue::BinaryOp( + BinOp::Ne, + Box::new((Operand::Copy(sizeof_pointee), zero.clone())), + ), + ))), )); - Operand::Copy(pointee_should_be_checked.into()) + + // Pointer needs to be checked only if pointee is not a ZST. + Operand::Copy(is_pointee_not_zst) } }; diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 8bcda77f4bc32..fd5269d4ff8c8 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -466,6 +466,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { return ValueOrPlace::Value(FlatSet::Top); }; let val = match null_op { + NullOp::SizeOf if layout.is_sized() => layout.size.bytes(), + NullOp::AlignOf if layout.is_sized() => layout.align.bytes(), NullOp::OffsetOf(fields) => self .ecx .tcx diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 8eae80e235ccd..03073bb7cbdb0 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -670,7 +670,14 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> { } NullaryOp(null_op, arg_ty) => { let arg_layout = self.ecx.layout_of(arg_ty).ok()?; + if let NullOp::SizeOf | NullOp::AlignOf = null_op + && arg_layout.is_unsized() + { + return None; + } let val = match null_op { + NullOp::SizeOf => arg_layout.size.bytes(), + NullOp::AlignOf => arg_layout.align.bytes(), NullOp::OffsetOf(fields) => self .tcx .offset_of_subfield(self.typing_env(), arg_layout, fields.iter()) diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 932744e4fa25c..c83bd25c6636b 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -264,7 +264,6 @@ 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 @@ -273,16 +272,12 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> { && self.tcx.is_intrinsic(fn_def_id, sym::align_of_val) && let ty::Slice(elem_ty) = *generics.type_at(0).kind() { - let align_def_id = self.tcx.require_lang_item(LangItem::AlignOf, source_info.span); - let align_const = Operand::unevaluated_constant( - self.tcx, - align_def_id, - &[elem_ty.into()], - source_info.span, - ); statements.push(Statement::new( - source_info, - StatementKind::Assign(Box::new((*destination, Rvalue::Use(align_const)))), + terminator.source_info, + StatementKind::Assign(Box::new(( + *destination, + Rvalue::NullaryOp(NullOp::AlignOf, elem_ty), + ))), )); terminator.kind = TerminatorKind::Goto { target: *destination_block }; } diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 131e3943689b8..c67e875175fee 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -608,6 +608,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { NullaryOp(ref null_op, ty) => { let op_layout = self.ecx.layout_of(ty).ok()?; let val = match null_op { + NullOp::SizeOf => op_layout.size.bytes(), + NullOp::AlignOf => op_layout.align.bytes(), NullOp::OffsetOf(fields) => self .tcx .offset_of_subfield(self.typing_env, op_layout, fields.iter()) diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index ad7c52064a8ef..fc8092fd5832b 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -139,6 +139,23 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics { )); terminator.kind = TerminatorKind::Goto { target }; } + sym::size_of | sym::align_of => { + let target = target.unwrap(); + let tp_ty = generic_args.type_at(0); + let null_op = match intrinsic.name { + sym::size_of => NullOp::SizeOf, + sym::align_of => NullOp::AlignOf, + _ => bug!("unexpected intrinsic"), + }; + block.statements.push(Statement::new( + terminator.source_info, + StatementKind::Assign(Box::new(( + *destination, + Rvalue::NullaryOp(null_op, tp_ty), + ))), + )); + terminator.kind = TerminatorKind::Goto { target }; + } sym::read_via_copy => { let Ok([arg]) = take_array(args) else { span_bug!(terminator.source_info.span, "Wrong number of arguments"); diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 9204c221515c9..c7dc18a4a1343 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -450,6 +450,8 @@ 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 5a9018a62c574..bef81935bb8f7 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -1478,7 +1478,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { Rvalue::Repeat(_, _) | Rvalue::ThreadLocalRef(_) | Rvalue::RawPtr(_, _) - | Rvalue::NullaryOp(NullOp::UbChecks | NullOp::ContractChecks, _) + | Rvalue::NullaryOp( + NullOp::SizeOf | NullOp::AlignOf | NullOp::UbChecks | NullOp::ContractChecks, + _, + ) | Rvalue::Discriminant(_) => {} Rvalue::WrapUnsafeBinder(op, ty) => { diff --git a/compiler/rustc_public/src/mir/body.rs b/compiler/rustc_public/src/mir/body.rs index 1a939cbe8dba2..615a5a48d15b7 100644 --- a/compiler/rustc_public/src/mir/body.rs +++ b/compiler/rustc_public/src/mir/body.rs @@ -641,7 +641,9 @@ impl Rvalue { .discriminant_ty() .ok_or_else(|| error!("Expected a `RigidTy` but found: {place_ty:?}")) } - Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => Ok(Ty::usize_ty()), + Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => { + Ok(Ty::usize_ty()) + } Rvalue::NullaryOp(NullOp::ContractChecks, _) | Rvalue::NullaryOp(NullOp::UbChecks, _) => Ok(Ty::bool_ty()), Rvalue::Aggregate(ak, ops) => match *ak { @@ -1022,6 +1024,10 @@ pub enum CastKind { #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] pub enum NullOp { + /// Returns the size of a value of that type. + SizeOf, + /// Returns the minimum alignment of a type. + AlignOf, /// Returns the offset of a field. OffsetOf(Vec<(VariantIdx, FieldIdx)>), /// cfg!(ub_checks), but at codegen time diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index f850bc5f89b8a..392347ce345a0 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -323,6 +323,8 @@ impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> { ) -> Self::T { use rustc_middle::mir::NullOp::*; match self { + SizeOf => crate::mir::NullOp::SizeOf, + AlignOf => crate::mir::NullOp::AlignOf, OffsetOf(indices) => crate::mir::NullOp::OffsetOf( indices.iter().map(|idx| idx.stable(tables, cx)).collect(), ), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 223d818a2949b..38340f9bd7ec5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1387,13 +1387,11 @@ symbols! { maybe_uninit, maybe_uninit_uninit, maybe_uninit_zeroed, - mem_align_const, mem_align_of, mem_discriminant, mem_drop, mem_forget, mem_replace, - mem_size_const, mem_size_of, mem_size_of_val, mem_swap, diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 619e8a263db40..a537269284773 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 { - ::SIZE + intrinsics::size_of::() } /// 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 { - ::ALIGN + intrinsics::align_of::() } /// 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 { - ::ALIGN + intrinsics::align_of::() } /// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in @@ -1236,16 +1236,6 @@ pub const fn variant_count() -> 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. /// @@ -1273,7 +1263,7 @@ pub trait SizedTypeProperties: Sized { /// ``` #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] - const IS_ZST: bool = Self::SIZE == 0; + const IS_ZST: bool = size_of::() == 0; #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] @@ -1285,7 +1275,7 @@ pub trait SizedTypeProperties: Sized { /// which is never allowed for a single object. #[doc(hidden)] #[unstable(feature = "sized_type_properties", issue = "none")] - const MAX_SLICE_LEN: usize = match Self::SIZE { + const MAX_SLICE_LEN: usize = match size_of::() { 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 90ea2616890a4..7722bebdbbe0d 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,7 +194,10 @@ fn check_rvalue<'tcx>( )) } }, - Rvalue::NullaryOp(NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _) + Rvalue::NullaryOp( + NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, + _, + ) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, cx.tcx); diff --git a/src/tools/miri/tests/fail/layout_cycle.stderr b/src/tools/miri/tests/fail/layout_cycle.stderr index dae6934931228..c233f85063cc9 100644 --- a/src/tools/miri/tests/fail/layout_cycle.stderr +++ b/src/tools/miri/tests/fail/layout_cycle.stderr @@ -2,20 +2,29 @@ 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[E0080]: a cycle occurred during layout computation +error: post-monomorphization error: a cycle occurred during layout computation --> RUSTLIB/core/src/mem/mod.rs:LL:CC | -LL | const SIZE: usize = intrinsics::size_of::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `> as std::mem::SizedTypeProperties>::SIZE` failed here +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 error: aborting due to 2 previous errors -Some errors have detailed explanations: E0080, E0391. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs b/tests/codegen-llvm/emscripten-catch-unwind-js-eh.rs index dfe154c1c8314..f43869cf2189e 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] -const fn size_of() -> usize { +fn size_of() -> usize { loop {} } @@ -40,7 +40,7 @@ unsafe fn catch_unwind( #[no_mangle] pub fn ptr_size() -> usize { // CHECK: ret [[PTR_SIZE:.*]] - const { size_of::<*mut u8>() } + size_of::<*mut u8>() } // CHECK-LABEL: @test_catch_unwind diff --git a/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs b/tests/codegen-llvm/emscripten-catch-unwind-wasm-eh.rs index 88c95b088aaaa..b0750d52268ad 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] -const fn size_of() -> usize { +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:.*]] - const { size_of::<*mut u8>() } + size_of::<*mut u8>() } // CHECK-LABEL: @test_catch_unwind diff --git a/tests/crashes/114663.rs b/tests/crashes/114663.rs new file mode 100644 index 0000000000000..406371f12e460 --- /dev/null +++ b/tests/crashes/114663.rs @@ -0,0 +1,17 @@ +//@ 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/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs b/tests/crashes/119729.rs similarity index 52% rename from tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs rename to tests/crashes/119729.rs index ee5d65cf4b2ba..ed07c58e89fdf 100644 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.rs +++ b/tests/crashes/119729.rs @@ -1,7 +1,5 @@ -//! Regression test for #119729 - +//@ known-bug: #119729 #![feature(generic_const_exprs)] -#![allow(incomplete_features)] trait Size {} @@ -12,7 +10,3 @@ 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.rs b/tests/crashes/136175.rs similarity index 57% rename from tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.rs rename to tests/crashes/136175.rs index 34b4734f4772c..0b5f2fdaa922f 100644 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.rs +++ b/tests/crashes/136175.rs @@ -1,5 +1,4 @@ -//! Regression test for #136175 - +//@ known-bug: #136175 #![feature(generic_const_exprs)] #![allow(incomplete_features)] @@ -11,5 +10,4 @@ where fn main() { let x: A; - //~^ ERROR the size for values of type `dyn Trait` cannot be known at compilation time } diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.diff b/tests/mir-opt/box_expr.main.ElaborateDrops.diff index 4fa77cf82d819..827dc6ac7aefe 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.diff +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.diff @@ -4,45 +4,49 @@ fn main() -> () { let mut _0: (); let _1: std::boxed::Box; - let mut _2: *mut u8; - let mut _3: std::boxed::Box; - let _4: (); + let mut _2: usize; + let mut _3: usize; + let mut _4: *mut u8; let mut _5: std::boxed::Box; -+ let mut _6: &mut std::boxed::Box; -+ let mut _7: (); -+ let mut _8: *const S; + let _6: (); + let mut _7: std::boxed::Box; ++ let mut _8: &mut std::boxed::Box; ++ let mut _9: (); ++ let mut _10: *const S; scope 1 { debug x => _1; } bb0: { StorageLive(_1); - _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; + _2 = SizeOf(S); + _3 = AlignOf(S); + _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_3); - _3 = ShallowInitBox(move _2, S); - (*_3) = S::new() -> [return: bb2, unwind: bb8]; + StorageLive(_5); + _5 = ShallowInitBox(move _4, S); + (*_5) = S::new() -> [return: bb2, unwind: bb8]; } bb2: { - _1 = move _3; -- drop(_3) -> [return: bb3, unwind continue]; + _1 = move _5; +- drop(_5) -> [return: bb3, unwind continue]; + goto -> bb3; } bb3: { - StorageDead(_3); - StorageLive(_4); - StorageLive(_5); - _5 = move _1; - _4 = std::mem::drop::>(move _5) -> [return: bb4, unwind: bb6]; + StorageDead(_5); + StorageLive(_6); + StorageLive(_7); + _7 = move _1; + _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; } bb4: { - StorageDead(_5); - StorageDead(_4); + StorageDead(_7); + StorageDead(_6); _0 = const (); - drop(_1) -> [return: bb5, unwind continue]; + goto -> bb5; @@ -54,7 +58,7 @@ } bb6 (cleanup): { -- drop(_5) -> [return: bb7, unwind terminate(cleanup)]; +- drop(_7) -> [return: bb7, unwind terminate(cleanup)]; + goto -> bb7; } @@ -64,7 +68,7 @@ } bb8 (cleanup): { -- drop(_3) -> [return: bb9, unwind terminate(cleanup)]; +- drop(_5) -> [return: bb9, unwind terminate(cleanup)]; + goto -> bb12; } @@ -73,8 +77,8 @@ + } + + bb10 (cleanup): { -+ _6 = &mut _3; -+ _7 = as Drop>::drop(move _6) -> [return: bb9, unwind terminate(cleanup)]; ++ _8 = &mut _5; ++ _9 = as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)]; + } + + bb11 (cleanup): { @@ -82,7 +86,7 @@ + } + + bb12 (cleanup): { -+ _8 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); ++ _10 = copy ((_5.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 839bdeca86a88..6d3b2cf291038 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,55 +4,63 @@ fn move_out_by_subslice() -> () { let mut _0: (); let _1: [std::boxed::Box; 2]; let mut _2: 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 _3: usize; + let mut _4: usize; + let mut _5: *mut u8; + let mut _6: std::boxed::Box; 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 _8: [std::boxed::Box; 2]; + let _12: [std::boxed::Box; 2]; scope 2 { - debug _y => _8; + debug _y => _12; } } bb0: { StorageLive(_1); StorageLive(_2); - _3 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; + _3 = SizeOf(i32); + _4 = AlignOf(i32); + _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; } bb1: { - StorageLive(_4); - _4 = ShallowInitBox(move _3, i32); - (*_4) = const 1_i32; - _2 = move _4; - drop(_4) -> [return: bb2, unwind: bb12]; + StorageLive(_6); + _6 = ShallowInitBox(move _5, i32); + (*_6) = const 1_i32; + _2 = move _6; + drop(_6) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_4); - StorageLive(_5); - _6 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb3, unwind: bb12]; + StorageDead(_6); + StorageLive(_7); + _8 = SizeOf(i32); + _9 = AlignOf(i32); + _10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12]; } bb3: { - StorageLive(_7); - _7 = ShallowInitBox(move _6, i32); - (*_7) = const 2_i32; - _5 = move _7; - drop(_7) -> [return: bb4, unwind: bb11]; + StorageLive(_11); + _11 = ShallowInitBox(move _10, i32); + (*_11) = const 2_i32; + _7 = move _11; + drop(_11) -> [return: bb4, unwind: bb11]; } bb4: { - StorageDead(_7); - _1 = [move _2, move _5]; - drop(_5) -> [return: bb5, unwind: bb12]; + StorageDead(_11); + _1 = [move _2, move _7]; + drop(_7) -> [return: bb5, unwind: bb12]; } bb5: { - StorageDead(_5); + StorageDead(_7); drop(_2) -> [return: bb6, unwind: bb13]; } @@ -60,10 +68,10 @@ fn move_out_by_subslice() -> () { StorageDead(_2); FakeRead(ForLet(None), _1); PlaceMention(_1); - StorageLive(_8); - _8 = move _1[0..2]; + StorageLive(_12); + _12 = move _1[0..2]; _0 = const (); - drop(_8) -> [return: bb8, unwind: bb10]; + drop(_12) -> [return: bb8, unwind: bb10]; } bb7: { @@ -72,7 +80,7 @@ fn move_out_by_subslice() -> () { } bb8: { - StorageDead(_8); + StorageDead(_12); drop(_1) -> [return: bb9, unwind: bb13]; } @@ -86,7 +94,7 @@ fn move_out_by_subslice() -> () { } bb11 (cleanup): { - drop(_5) -> [return: bb12, unwind terminate(cleanup)]; + drop(_7) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { 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 7fda69c7500a3..003b90a912d25 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,55 +4,63 @@ fn move_out_from_end() -> () { let mut _0: (); let _1: [std::boxed::Box; 2]; let mut _2: 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 _3: usize; + let mut _4: usize; + let mut _5: *mut u8; + let mut _6: std::boxed::Box; 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 _8: std::boxed::Box; + let _12: std::boxed::Box; scope 2 { - debug _y => _8; + debug _y => _12; } } bb0: { StorageLive(_1); StorageLive(_2); - _3 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; + _3 = SizeOf(i32); + _4 = AlignOf(i32); + _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; } bb1: { - StorageLive(_4); - _4 = ShallowInitBox(move _3, i32); - (*_4) = const 1_i32; - _2 = move _4; - drop(_4) -> [return: bb2, unwind: bb12]; + StorageLive(_6); + _6 = ShallowInitBox(move _5, i32); + (*_6) = const 1_i32; + _2 = move _6; + drop(_6) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_4); - StorageLive(_5); - _6 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb3, unwind: bb12]; + StorageDead(_6); + StorageLive(_7); + _8 = SizeOf(i32); + _9 = AlignOf(i32); + _10 = alloc::alloc::exchange_malloc(move _8, move _9) -> [return: bb3, unwind: bb12]; } bb3: { - StorageLive(_7); - _7 = ShallowInitBox(move _6, i32); - (*_7) = const 2_i32; - _5 = move _7; - drop(_7) -> [return: bb4, unwind: bb11]; + StorageLive(_11); + _11 = ShallowInitBox(move _10, i32); + (*_11) = const 2_i32; + _7 = move _11; + drop(_11) -> [return: bb4, unwind: bb11]; } bb4: { - StorageDead(_7); - _1 = [move _2, move _5]; - drop(_5) -> [return: bb5, unwind: bb12]; + StorageDead(_11); + _1 = [move _2, move _7]; + drop(_7) -> [return: bb5, unwind: bb12]; } bb5: { - StorageDead(_5); + StorageDead(_7); drop(_2) -> [return: bb6, unwind: bb13]; } @@ -60,10 +68,10 @@ fn move_out_from_end() -> () { StorageDead(_2); FakeRead(ForLet(None), _1); PlaceMention(_1); - StorageLive(_8); - _8 = move _1[1 of 2]; + StorageLive(_12); + _12 = move _1[1 of 2]; _0 = const (); - drop(_8) -> [return: bb8, unwind: bb10]; + drop(_12) -> [return: bb8, unwind: bb10]; } bb7: { @@ -72,7 +80,7 @@ fn move_out_from_end() -> () { } bb8: { - StorageDead(_8); + StorageDead(_12); drop(_1) -> [return: bb9, unwind: bb13]; } @@ -86,7 +94,7 @@ fn move_out_from_end() -> () { } bb11 (cleanup): { - drop(_5) -> [return: bb12, unwind terminate(cleanup)]; + drop(_7) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { 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 95eaf18b4703b..16bae67cc9892 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,13 +6,15 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: *const i32; - let mut _7: std::ptr::NonNull; - let mut _8: std::ptr::Unique; - let mut _9: *const i32; - let mut _10: *const i32; + let mut _4: usize; + let mut _5: usize; + let mut _6: *mut u8; + let mut _7: std::boxed::Box; + let mut _8: *const i32; + let mut _9: std::ptr::NonNull; + let mut _10: std::ptr::Unique; + let mut _11: *const i32; + let mut _12: *const i32; scope 1 { debug x => _1; } @@ -22,26 +24,31 @@ - StorageLive(_2); + nop; StorageLive(_3); - _4 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind unreachable]; +- _4 = SizeOf(i32); +- _5 = AlignOf(i32); +- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind unreachable]; ++ _4 = const 4_usize; ++ _5 = const 4_usize; ++ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind unreachable]; } bb1: { - StorageLive(_5); -- _6 = move _4 as *const i32 (Transmute); -- _7 = NonNull:: { pointer: move _6 }; -- _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; -+ _6 = copy _4 as *const i32 (PtrToPtr); -+ _7 = NonNull:: { pointer: copy _6 }; -+ _8 = Unique:: { pointer: copy _7, _marker: const PhantomData:: }; - _5 = Box::(move _8, const std::alloc::Global); -- _9 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); -- (*_9) = const 42_i32; -+ _9 = copy _6; -+ (*_6) = const 42_i32; - _3 = move _5; - StorageDead(_5); - _10 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - _2 = copy (*_10); + StorageLive(_7); +- _8 = move _6 as *const i32 (Transmute); +- _9 = NonNull:: { pointer: move _8 }; +- _10 = Unique:: { pointer: move _9, _marker: const PhantomData:: }; ++ _8 = copy _6 as *const i32 (PtrToPtr); ++ _9 = NonNull:: { pointer: copy _8 }; ++ _10 = Unique:: { pointer: copy _9, _marker: const PhantomData:: }; + _7 = Box::(move _10, const std::alloc::Global); +- _11 = copy ((_7.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); +- (*_11) = const 42_i32; ++ _11 = copy _8; ++ (*_8) = const 42_i32; + _3 = move _7; + StorageDead(_7); + _12 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_12); - _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 6d8d3a0dcfe29..3fbf7a57a76f8 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,13 +6,15 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: *const i32; - let mut _7: std::ptr::NonNull; - let mut _8: std::ptr::Unique; - let mut _9: *const i32; - let mut _10: *const i32; + let mut _4: usize; + let mut _5: usize; + let mut _6: *mut u8; + let mut _7: std::boxed::Box; + let mut _8: *const i32; + let mut _9: std::ptr::NonNull; + let mut _10: std::ptr::Unique; + let mut _11: *const i32; + let mut _12: *const i32; scope 1 { debug x => _1; } @@ -22,26 +24,31 @@ - StorageLive(_2); + nop; StorageLive(_3); - _4 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; +- _4 = SizeOf(i32); +- _5 = AlignOf(i32); +- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind continue]; ++ _4 = const 4_usize; ++ _5 = const 4_usize; ++ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_5); -- _6 = move _4 as *const i32 (Transmute); -- _7 = NonNull:: { pointer: move _6 }; -- _8 = Unique:: { pointer: move _7, _marker: const PhantomData:: }; -+ _6 = copy _4 as *const i32 (PtrToPtr); -+ _7 = NonNull:: { pointer: copy _6 }; -+ _8 = Unique:: { pointer: copy _7, _marker: const PhantomData:: }; - _5 = Box::(move _8, const std::alloc::Global); -- _9 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); -- (*_9) = const 42_i32; -+ _9 = copy _6; -+ (*_6) = const 42_i32; - _3 = move _5; - StorageDead(_5); - _10 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); - _2 = copy (*_10); + StorageLive(_7); +- _8 = move _6 as *const i32 (Transmute); +- _9 = NonNull:: { pointer: move _8 }; +- _10 = Unique:: { pointer: move _9, _marker: const PhantomData:: }; ++ _8 = copy _6 as *const i32 (PtrToPtr); ++ _9 = NonNull:: { pointer: copy _8 }; ++ _10 = Unique:: { pointer: copy _9, _marker: const PhantomData:: }; + _7 = Box::(move _10, const std::alloc::Global); +- _11 = copy ((_7.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); +- (*_11) = const 42_i32; ++ _11 = copy _8; ++ (*_8) = const 42_i32; + _3 = move _7; + StorageDead(_7); + _12 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_12); - _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 38beb81e1ead2..f47e544385497 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,8 +11,6 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); - let mut _16: usize; - let mut _17: usize; let mut _27: usize; scope 1 { debug vp_ctx => _1; @@ -37,10 +35,12 @@ } } scope 5 (inlined Box::<()>::new) { - let mut _12: *mut u8; - let mut _13: *const (); - let mut _14: std::ptr::NonNull<()>; - let mut _15: std::ptr::Unique<()>; + let mut _12: usize; + let mut _13: usize; + let mut _14: *mut u8; + let mut _15: *const (); + let mut _16: std::ptr::NonNull<()>; + let mut _17: std::ptr::Unique<()>; scope 6 (inlined alloc::alloc::exchange_malloc) { let _18: std::alloc::Layout; let mut _19: std::result::Result, std::alloc::AllocError>; @@ -85,11 +85,11 @@ StorageLive(_14); StorageLive(_15); StorageLive(_16); -- _16 = const <() as std::mem::SizedTypeProperties>::SIZE; -+ _16 = const 0_usize; StorageLive(_17); -- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN; -+ _17 = const 1_usize; +- _12 = SizeOf(()); +- _13 = AlignOf(()); ++ _12 = const 0_usize; ++ _13 = const 1_usize; StorageLive(_18); StorageLive(_20); StorageLive(_21); @@ -120,7 +120,7 @@ - StorageLive(_26); + nop; _26 = copy _21 as *mut [u8] (Transmute); - _12 = copy _26 as *mut u8 (PtrToPtr); + _14 = copy _26 as *mut u8 (PtrToPtr); - StorageDead(_26); + nop; StorageDead(_19); @@ -129,15 +129,15 @@ StorageDead(_21); StorageDead(_20); StorageDead(_18); +- _15 = copy _14 as *const () (PtrToPtr); ++ _15 = copy _26 as *const () (PtrToPtr); + _16 = NonNull::<()> { pointer: copy _15 }; + _17 = Unique::<()> { pointer: copy _16, _marker: const PhantomData::<()> }; + _3 = Box::<()>(move _17, const std::alloc::Global); +- (*_15) = move _4; ++ (*_15) = const (); StorageDead(_17); StorageDead(_16); -- _13 = copy _12 as *const () (PtrToPtr); -+ _13 = copy _26 as *const () (PtrToPtr); - _14 = NonNull::<()> { pointer: copy _13 }; - _15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> }; - _3 = Box::<()>(move _15, const std::alloc::Global); -- (*_13) = move _4; -+ (*_13) = const (); StorageDead(_15); StorageDead(_14); StorageDead(_13); @@ -183,15 +183,15 @@ } bb5: { -- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable]; +- _24 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable]; + _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { StorageDead(_23); StorageLive(_25); -- _25 = copy _17 as std::ptr::Alignment (Transmute); -- _18 = Layout { size: copy _16, align: move _25 }; +- _25 = copy _13 as std::ptr::Alignment (Transmute); +- _18 = Layout { size: copy _12, align: move _25 }; + _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); + _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; StorageDead(_25); 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 047579cdb5094..fe88ff7a53e7d 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,8 +11,6 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); - let mut _16: usize; - let mut _17: usize; let mut _27: usize; scope 1 { debug vp_ctx => _1; @@ -37,10 +35,12 @@ } } scope 5 (inlined Box::<()>::new) { - let mut _12: *mut u8; - let mut _13: *const (); - let mut _14: std::ptr::NonNull<()>; - let mut _15: std::ptr::Unique<()>; + let mut _12: usize; + let mut _13: usize; + let mut _14: *mut u8; + let mut _15: *const (); + let mut _16: std::ptr::NonNull<()>; + let mut _17: std::ptr::Unique<()>; scope 6 (inlined alloc::alloc::exchange_malloc) { let _18: std::alloc::Layout; let mut _19: std::result::Result, std::alloc::AllocError>; @@ -85,11 +85,11 @@ StorageLive(_14); StorageLive(_15); StorageLive(_16); -- _16 = const <() as std::mem::SizedTypeProperties>::SIZE; -+ _16 = const 0_usize; StorageLive(_17); -- _17 = const <() as std::mem::SizedTypeProperties>::ALIGN; -+ _17 = const 1_usize; +- _12 = SizeOf(()); +- _13 = AlignOf(()); ++ _12 = const 0_usize; ++ _13 = const 1_usize; StorageLive(_18); StorageLive(_20); StorageLive(_21); @@ -120,7 +120,7 @@ - StorageLive(_26); + nop; _26 = copy _21 as *mut [u8] (Transmute); - _12 = copy _26 as *mut u8 (PtrToPtr); + _14 = copy _26 as *mut u8 (PtrToPtr); - StorageDead(_26); + nop; StorageDead(_19); @@ -129,15 +129,15 @@ StorageDead(_21); StorageDead(_20); StorageDead(_18); +- _15 = copy _14 as *const () (PtrToPtr); ++ _15 = copy _26 as *const () (PtrToPtr); + _16 = NonNull::<()> { pointer: copy _15 }; + _17 = Unique::<()> { pointer: copy _16, _marker: const PhantomData::<()> }; + _3 = Box::<()>(move _17, const std::alloc::Global); +- (*_15) = move _4; ++ (*_15) = const (); StorageDead(_17); StorageDead(_16); -- _13 = copy _12 as *const () (PtrToPtr); -+ _13 = copy _26 as *const () (PtrToPtr); - _14 = NonNull::<()> { pointer: copy _13 }; - _15 = Unique::<()> { pointer: copy _14, _marker: const PhantomData::<()> }; - _3 = Box::<()>(move _15, const std::alloc::Global); -- (*_13) = move _4; -+ (*_13) = const (); StorageDead(_15); StorageDead(_14); StorageDead(_13); @@ -183,15 +183,15 @@ } bb5: { -- _24 = Layout::from_size_align_unchecked::precondition_check(copy _16, copy _17) -> [return: bb6, unwind unreachable]; +- _24 = Layout::from_size_align_unchecked::precondition_check(copy _12, copy _13) -> [return: bb6, unwind unreachable]; + _24 = Layout::from_size_align_unchecked::precondition_check(const 0_usize, const 1_usize) -> [return: bb6, unwind unreachable]; } bb6: { StorageDead(_23); StorageLive(_25); -- _25 = copy _17 as std::ptr::Alignment (Transmute); -- _18 = Layout { size: copy _16, align: move _25 }; +- _25 = copy _13 as std::ptr::Alignment (Transmute); +- _18 = Layout { size: copy _12, align: move _25 }; + _25 = const std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0); + _18 = const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}; StorageDead(_25); 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 bbcc9012a25dd..042e19bf2aa18 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 = const ::ALIGN; ++ _0 = AlignOf(T); + goto -> bb1; } diff --git a/tests/mir-opt/instsimplify/align_of_slice.rs b/tests/mir-opt/instsimplify/align_of_slice.rs index 99a68e444fe5d..0af05cb6b0b02 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 = const ::ALIGN; + // CHECK: _0 = AlignOf(T); 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 c46549c5742f2..736a8bbca49c7 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,45 +3,49 @@ fn test() -> Option> { let mut _0: std::option::Option>; let mut _1: std::boxed::Box; - 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; + 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; scope 1 { - debug residual => _7; + debug residual => _9; scope 2 { } } scope 3 { - debug val => _10; + debug val => _12; scope 4 { } } bb0: { StorageLive(_1); - _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind: bb13]; + _2 = SizeOf(u32); + _3 = AlignOf(u32); + _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind: bb13]; } bb1: { - StorageLive(_3); - _3 = ShallowInitBox(move _2, u32); - StorageLive(_4); StorageLive(_5); - _5 = Option::::None; - _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb12]; + _5 = ShallowInitBox(move _4, u32); + StorageLive(_6); + StorageLive(_7); + _7 = Option::::None; + _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_5); - PlaceMention(_4); - _6 = discriminant(_4); - switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3]; + StorageDead(_7); + PlaceMention(_6); + _8 = discriminant(_6); + switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; } bb3: { @@ -49,44 +53,44 @@ fn test() -> Option> { } bb4: { - StorageLive(_10); - _10 = copy ((_4 as Continue).0: u32); - (*_3) = copy _10; - StorageDead(_10); - _1 = move _3; - drop(_3) -> [return: bb7, unwind: bb11]; + StorageLive(_12); + _12 = copy ((_6 as Continue).0: u32); + (*_5) = copy _12; + StorageDead(_12); + _1 = move _5; + drop(_5) -> [return: bb7, unwind: bb11]; } bb5: { - StorageLive(_7); - _7 = copy ((_4 as Break).0: std::option::Option); StorageLive(_9); - _9 = copy _7; - _0 = > as FromResidual>>::from_residual(move _9) -> [return: bb6, unwind: bb12]; + _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]; } bb6: { + StorageDead(_11); StorageDead(_9); - StorageDead(_7); - drop(_3) -> [return: bb9, unwind: bb13]; + drop(_5) -> [return: bb9, unwind: bb13]; } bb7: { - StorageDead(_3); + StorageDead(_5); _0 = Option::>::Some(move _1); drop(_1) -> [return: bb8, unwind: bb13]; } bb8: { StorageDead(_1); - StorageDead(_4); + StorageDead(_6); goto -> bb10; } bb9: { - StorageDead(_3); + StorageDead(_5); StorageDead(_1); - StorageDead(_4); + StorageDead(_6); goto -> bb10; } @@ -99,7 +103,7 @@ fn test() -> Option> { } bb12 (cleanup): { - drop(_3) -> [return: bb13, unwind terminate(cleanup)]; + drop(_5) -> [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 9f26debdbb6d6..1acb1ae20b698 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,45 +3,49 @@ fn test() -> Option> { let mut _0: std::option::Option>; let mut _1: std::boxed::Box; - 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; + 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; scope 1 { - debug residual => _7; + debug residual => _9; scope 2 { } } scope 3 { - debug val => _10; + debug val => _12; scope 4 { } } bb0: { StorageLive(_1); - _2 = alloc::alloc::exchange_malloc(const ::SIZE, const ::ALIGN) -> [return: bb1, unwind continue]; + _2 = SizeOf(u32); + _3 = AlignOf(u32); + _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_3); - _3 = ShallowInitBox(move _2, u32); - StorageLive(_4); StorageLive(_5); - _5 = Option::::None; - _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb12]; + _5 = ShallowInitBox(move _4, u32); + StorageLive(_6); + StorageLive(_7); + _7 = Option::::None; + _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; } bb2: { - StorageDead(_5); - PlaceMention(_4); - _6 = discriminant(_4); - switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb3]; + StorageDead(_7); + PlaceMention(_6); + _8 = discriminant(_6); + switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; } bb3: { @@ -49,44 +53,44 @@ fn test() -> Option> { } bb4: { - StorageLive(_10); - _10 = copy ((_4 as Continue).0: u32); - (*_3) = copy _10; - StorageDead(_10); - _1 = move _3; - drop(_3) -> [return: bb7, unwind: bb11]; + StorageLive(_12); + _12 = copy ((_6 as Continue).0: u32); + (*_5) = copy _12; + StorageDead(_12); + _1 = move _5; + drop(_5) -> [return: bb7, unwind: bb11]; } bb5: { - StorageLive(_7); - _7 = copy ((_4 as Break).0: std::option::Option); StorageLive(_9); - _9 = copy _7; - _0 = > as FromResidual>>::from_residual(move _9) -> [return: bb6, unwind: bb12]; + _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]; } bb6: { + StorageDead(_11); StorageDead(_9); - StorageDead(_7); - drop(_3) -> [return: bb9, unwind continue]; + drop(_5) -> [return: bb9, unwind continue]; } bb7: { - StorageDead(_3); + StorageDead(_5); _0 = Option::>::Some(move _1); drop(_1) -> [return: bb8, unwind continue]; } bb8: { StorageDead(_1); - StorageDead(_4); + StorageDead(_6); goto -> bb10; } bb9: { - StorageDead(_3); + StorageDead(_5); StorageDead(_1); - StorageDead(_4); + StorageDead(_6); goto -> bb10; } @@ -99,7 +103,7 @@ fn test() -> Option> { } bb12 (cleanup): { - drop(_3) -> [return: bb13, unwind terminate(cleanup)]; + drop(_5) -> [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 new file mode 100644 index 0000000000000..e61a3e8d73834 --- /dev/null +++ b/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-abort.diff @@ -0,0 +1,17 @@ +- // MIR for `align_of` before LowerIntrinsics ++ // MIR for `align_of` after LowerIntrinsics + + fn align_of() -> usize { + let mut _0: usize; + + bb0: { +- _0 = std::intrinsics::align_of::() -> [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 new file mode 100644 index 0000000000000..e61a3e8d73834 --- /dev/null +++ b/tests/mir-opt/lower_intrinsics.align_of.LowerIntrinsics.panic-unwind.diff @@ -0,0 +1,17 @@ +- // MIR for `align_of` before LowerIntrinsics ++ // MIR for `align_of` after LowerIntrinsics + + fn align_of() -> usize { + let mut _0: usize; + + bb0: { +- _0 = std::intrinsics::align_of::() -> [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 42b8ab3da66c1..5aa9869847680 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,21 +3,26 @@ fn non_const() -> usize { let mut _0: usize; - let _1: unsafe fn() -> ! {std::intrinsics::unreachable}; - let mut _2: !; - let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable}; + let _1: fn() -> usize {std::intrinsics::size_of::}; + let mut _2: fn() -> usize {std::intrinsics::size_of::}; scope 1 { - debug unreachable => _1; + debug size_of_t => _1; } bb0: { StorageLive(_1); - _1 = std::intrinsics::unreachable; + _1 = std::intrinsics::size_of::; StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = move _3() -> unwind unreachable; -+ unreachable; + _2 = copy _1; +- _0 = move _2() -> [return: bb1, unwind unreachable]; ++ _0 = SizeOf(T); ++ goto -> bb1; + } + + bb1: { + StorageDead(_2); + StorageDead(_1); + return; } } 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 42b8ab3da66c1..5aa9869847680 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,21 +3,26 @@ fn non_const() -> usize { let mut _0: usize; - let _1: unsafe fn() -> ! {std::intrinsics::unreachable}; - let mut _2: !; - let mut _3: unsafe fn() -> ! {std::intrinsics::unreachable}; + let _1: fn() -> usize {std::intrinsics::size_of::}; + let mut _2: fn() -> usize {std::intrinsics::size_of::}; scope 1 { - debug unreachable => _1; + debug size_of_t => _1; } bb0: { StorageLive(_1); - _1 = std::intrinsics::unreachable; + _1 = std::intrinsics::size_of::; StorageLive(_2); - StorageLive(_3); - _3 = copy _1; -- _2 = move _3() -> unwind unreachable; -+ unreachable; + _2 = copy _1; +- _0 = move _2() -> [return: bb1, unwind unreachable]; ++ _0 = SizeOf(T); ++ goto -> bb1; + } + + bb1: { + StorageDead(_2); + StorageDead(_1); + return; } } diff --git a/tests/mir-opt/lower_intrinsics.rs b/tests/mir-opt/lower_intrinsics.rs index 6b8c2a7902023..7729e502ad6b9 100644 --- a/tests/mir-opt/lower_intrinsics.rs +++ b/tests/mir-opt/lower_intrinsics.rs @@ -40,6 +40,20 @@ pub unsafe fn unchecked(a: i32, b: i32, c: u32) { let _l = core::intrinsics::unchecked_shr(a, c); } +// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff +pub fn size_of() -> 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( @@ -59,13 +73,11 @@ pub fn unreachable() -> ! { // EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff pub fn non_const() -> usize { // CHECK-LABEL: fn non_const( - // CHECK: _1 = std::intrinsics::unreachable; - // CHECK: unreachable; - // CHECK-NEXT: } + // CHECK: SizeOf(T); // Check that lowering works with non-const operand as a func. - let unreachable = core::intrinsics::unreachable; - unsafe { unreachable() } + let size_of_t = core::intrinsics::size_of::; + size_of_t() } // 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 new file mode 100644 index 0000000000000..a547bdf3737b9 --- /dev/null +++ b/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-abort.diff @@ -0,0 +1,17 @@ +- // MIR for `size_of` before LowerIntrinsics ++ // MIR for `size_of` after LowerIntrinsics + + fn size_of() -> usize { + let mut _0: usize; + + bb0: { +- _0 = std::intrinsics::size_of::() -> [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 new file mode 100644 index 0000000000000..a547bdf3737b9 --- /dev/null +++ b/tests/mir-opt/lower_intrinsics.size_of.LowerIntrinsics.panic-unwind.diff @@ -0,0 +1,17 @@ +- // MIR for `size_of` before LowerIntrinsics ++ // MIR for `size_of` after LowerIntrinsics + + fn size_of() -> usize { + let mut _0: usize; + + bb0: { +- _0 = std::intrinsics::size_of::() -> [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 791d6b71a6f78..ba6ce0ee5286f 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 = const ::ALIGN; + _6 = AlignOf(T); 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 791d6b71a6f78..ba6ce0ee5286f 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 = const ::ALIGN; + _6 = AlignOf(T); 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 791d6b71a6f78..ba6ce0ee5286f 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 = const ::ALIGN; + _6 = AlignOf(T); 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 791d6b71a6f78..ba6ce0ee5286f 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 = const ::ALIGN; + _6 = AlignOf(T); 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 83b10f8bd6888..9ceba9444b8da 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:_.+]] = const ::ALIGN; + // CHECK: [[ALIGN:_.+]] = AlignOf(T); // CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute); // CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum); // CHECK: [[D:_.+]] = discriminant([[C]]); 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 4260ec3eaedf1..66eb1bcfaa665 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: &mut std::vec::IntoIter; - let mut _24: std::option::Option; - let mut _25: isize; - let _27: (); + 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: (); scope 1 { - debug iter => _22; - let _26: impl Sized; + debug iter => _23; + let _27: impl Sized; scope 2 { - debug x => _26; + debug x => _27; } } scope 3 (inlined 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 _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>; + 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>; scope 4 { debug me => _2; scope 5 { @@ -46,33 +46,34 @@ fn vec_move(_1: Vec) -> () { debug begin => _7; scope 8 { debug end => _11; - let _19: usize; + let _20: usize; scope 9 { - debug cap => _19; + debug cap => _20; } scope 39 (inlined > as Deref>::deref) { - debug self => _37; + debug self => _38; } scope 40 (inlined alloc::raw_vec::RawVec::::capacity) { - debug self => _36; - let mut _38: &alloc::raw_vec::RawVecInner; + debug self => _37; + let mut _19: usize; + let mut _39: &alloc::raw_vec::RawVecInner; scope 41 (inlined std::mem::size_of::) { } scope 42 (inlined alloc::raw_vec::RawVecInner::capacity) { - debug self => _38; - debug elem_size => const ::SIZE; - let mut _20: core::num::niche_types::UsizeNoHighBit; + debug self => _39; + debug elem_size => _19; + let mut _21: core::num::niche_types::UsizeNoHighBit; scope 43 (inlined core::num::niche_types::UsizeNoHighBit::as_inner) { - debug self => _20; + debug self => _21; } } } } scope 25 (inlined > as Deref>::deref) { - debug self => _33; + debug self => _34; } scope 26 (inlined Vec::::len) { - debug self => _32; + debug self => _33; let mut _13: bool; scope 27 { } @@ -107,10 +108,10 @@ fn vec_move(_1: Vec) -> () { } } scope 35 (inlined > as Deref>::deref) { - debug self => _35; + debug self => _36; } scope 36 (inlined Vec::::len) { - debug self => _34; + debug self => _35; let mut _9: bool; scope 37 { } @@ -125,10 +126,10 @@ fn vec_move(_1: Vec) -> () { } } scope 17 (inlined > as Deref>::deref) { - debug self => _31; + debug self => _32; } scope 18 (inlined alloc::raw_vec::RawVec::::non_null) { - debug self => _30; + debug self => _31; scope 19 (inlined alloc::raw_vec::RawVecInner::non_null::) { let mut _4: std::ptr::NonNull; scope 20 (inlined Unique::::cast::) { @@ -144,10 +145,10 @@ fn vec_move(_1: Vec) -> () { } } scope 11 (inlined > as Deref>::deref) { - debug self => _29; + debug self => _30; } scope 12 (inlined Vec::::allocator) { - debug self => _28; + debug self => _29; scope 13 (inlined alloc::raw_vec::RawVec::::allocator) { scope 14 (inlined alloc::raw_vec::RawVecInner::allocator) { } @@ -166,23 +167,23 @@ fn vec_move(_1: Vec) -> () { } bb0: { - StorageLive(_21); + StorageLive(_22); StorageLive(_6); StorageLive(_7); StorageLive(_11); - StorageLive(_19); + StorageLive(_20); StorageLive(_5); StorageLive(_4); StorageLive(_17); StorageLive(_2); _2 = ManuallyDrop::> { value: copy _1 }; StorageLive(_3); - // DBG: _29 = &_2; - // DBG: _28 = &(_2.0: std::vec::Vec); + // DBG: _30 = &_2; + // DBG: _29 = &(_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: _31 = &_2; - // DBG: _30 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + // DBG: _32 = &_2; + // DBG: _31 = &((_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 }; @@ -193,8 +194,8 @@ fn vec_move(_1: Vec) -> () { bb1: { StorageLive(_10); StorageLive(_8); - // DBG: _35 = &_2; - // DBG: _34 = &(_2.0: std::vec::Vec); + // DBG: _36 = &_2; + // DBG: _35 = &(_2.0: std::vec::Vec); _8 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_9); _9 = Le(copy _8, const ::MAX_SLICE_LEN); @@ -209,8 +210,8 @@ fn vec_move(_1: Vec) -> () { bb2: { StorageLive(_12); - // DBG: _33 = &_2; - // DBG: _32 = &(_2.0: std::vec::Vec); + // DBG: _34 = &_2; + // DBG: _33 = &(_2.0: std::vec::Vec); _12 = copy ((_2.0: std::vec::Vec).1: usize); StorageLive(_13); _13 = Le(copy _12, const ::MAX_SLICE_LEN); @@ -238,69 +239,72 @@ fn vec_move(_1: Vec) -> () { } bb4: { - // 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]; + // 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]; } bb5: { - _19 = const usize::MAX; + _20 = const usize::MAX; goto -> bb7; } bb6: { - 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); + 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); goto -> bb7; } bb7: { - _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(_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 }; StorageDead(_2); StorageDead(_17); StorageDead(_4); StorageDead(_5); - StorageDead(_19); + StorageDead(_20); StorageDead(_11); StorageDead(_7); StorageDead(_6); - StorageLive(_22); - _22 = move _21; + StorageLive(_23); + _23 = move _22; goto -> bb8; } bb8: { - StorageLive(_24); - _23 = &mut _22; - _24 = as Iterator>::next(move _23) -> [return: bb9, unwind: bb15]; + StorageLive(_25); + _24 = &mut _23; + _25 = as Iterator>::next(move _24) -> [return: bb9, unwind: bb15]; } bb9: { - _25 = discriminant(_24); - switchInt(move _25) -> [0: bb10, 1: bb12, otherwise: bb14]; + _26 = discriminant(_25); + switchInt(move _26) -> [0: bb10, 1: bb12, otherwise: bb14]; } bb10: { - StorageDead(_24); - drop(_22) -> [return: bb11, unwind continue]; + StorageDead(_25); + drop(_23) -> [return: bb11, unwind continue]; } bb11: { + StorageDead(_23); StorageDead(_22); - StorageDead(_21); return; } bb12: { - _26 = move ((_24 as Some).0: impl Sized); - _27 = opaque::(move _26) -> [return: bb13, unwind: bb15]; + _27 = move ((_25 as Some).0: impl Sized); + _28 = opaque::(move _27) -> [return: bb13, unwind: bb15]; } bb13: { - StorageDead(_24); + StorageDead(_25); goto -> bb8; } @@ -309,7 +313,7 @@ fn vec_move(_1: Vec) -> () { } bb15 (cleanup): { - drop(_22) -> [return: bb16, unwind terminate(cleanup)]; + drop(_23) -> [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 4a45bb6daa5f4..176a9d79ef111 100644 --- a/tests/ui-fulldeps/rustc_public/check_def_ty.rs +++ b/tests/ui-fulldeps/rustc_public/check_def_ty.rs @@ -90,13 +90,15 @@ fn generate_input(path: &str) -> std::io::Result<()> { write!( file, r#" + // We would like to check intrinsic definition. + #![feature(core_intrinsics)] static STATIC_STR: &str = "foo"; const CONST_U32: u32 = 0u32; fn main() {{ let _c = core::char::from_u32(99); let _v = Vec::::new(); - let _i = std::mem::size_of::(); + let _i = std::intrinsics::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 0d392902be871..ac4d9fc0f4f42 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.rs @@ -1,4 +1,12 @@ //@ check-fail +//@ known-bug: #97477 +//@ failure-status: 101 +//@ normalize-stderr: "note: .*\n\n" -> "" +//@ normalize-stderr: "thread 'rustc'.*panicked.*\n" -> "" +//@ normalize-stderr: "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " +//@ rustc-env:RUST_BACKTRACE=0 + +// This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place #![allow(incomplete_features)] #![feature(generic_const_exprs)] @@ -26,6 +34,4 @@ where fn main() { let dst = Inline::::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 ac1bfc8d7a1b9..07fd231cb7ae9 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-80742.stderr @@ -1,42 +1,11 @@ -error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/issue-80742.rs:28:15 - | -LL | let dst = Inline::::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: internal compiler error: compiler/rustc_const_eval/src/interpret/operator.rs:LL:CC: unsized type for `NullaryOp::SizeOf` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -error[E0599]: the function or associated item `new` exists for struct `Inline`, 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 - | ++++++++ -error: aborting due to 2 previous errors +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 -Some errors have detailed explanations: E0277, E0599. -For more information about an error, try `rustc --explain E0277`. 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 deleted file mode 100644 index 71fea4df163d1..0000000000000 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-2.stderr +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index afb086a41305b..0000000000000 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! Regression test for #114663 -//@ edition:2021 - -#![feature(generic_const_exprs)] -#![allow(incomplete_features)] - -use core::fmt::Debug; -use core::marker::PhantomData; - -struct Inline -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 deleted file mode 100644 index bcc253ed96705..0000000000000 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait-3.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/size_of-dyn-trait-3.rs:18:15 - | -LL | let dst = Inline::::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/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr b/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr deleted file mode 100644 index 4669a2f1ce7df..0000000000000 --- a/tests/ui/const-generics/generic_const_exprs/size_of-dyn-trait.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time - --> $DIR/size_of-dyn-trait.rs:13:12 - | -LL | let x: A; - | ^^^^^^^^^^^^ 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 01aa5e726b451..b127f83d8853c 100644 --- a/tests/ui/consts/const-size_of-cycle.stderr +++ b/tests/ui/consts/const-size_of-cycle.stderr @@ -5,11 +5,10 @@ LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`... - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: ...which requires simplifying constant for the type system `core::mem::SizedTypeProperties::SIZE`... - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL -note: ...which requires const-evaluating + checking `core::mem::SizedTypeProperties::SIZE`... - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + --> $DIR/const-size_of-cycle.rs:2:17 + | +LL | bytes: [u8; std::mem::size_of::()] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = 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 771656a2c462b..7f85cbf227aef 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 73e1578242675..a3772e509ed67 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,14 +1,4 @@ -error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of ` 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: values of the type `[u8; usize::MAX]` are too big for the target architecture error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0080`. 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 4ce1e2e407e9d..a3772e509ed67 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,14 +1,4 @@ -error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of ` 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: values of the type `[u8; usize::MAX]` are too big for the target architecture error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/generics/issue-32498.rs b/tests/ui/generics/issue-32498.rs index 871914f0b36e1..b7685ac733605 100644 --- a/tests/ui/generics/issue-32498.rs +++ b/tests/ui/generics/issue-32498.rs @@ -1,6 +1,5 @@ //@ 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 5fee6b0b39783..904da71c306b0 100644 --- a/tests/ui/intrinsics/intrinsic-alignment.rs +++ b/tests/ui/intrinsics/intrinsic-alignment.rs @@ -2,6 +2,8 @@ #![feature(core_intrinsics, rustc_attrs)] +use std::intrinsics as rusti; + #[cfg(any( target_os = "aix", target_os = "android", @@ -21,12 +23,12 @@ mod m { #[cfg(target_arch = "x86")] pub fn main() { - assert_eq!(std::mem::align_of::(), 4); + assert_eq!(crate::rusti::align_of::(), 4); } #[cfg(not(target_arch = "x86"))] pub fn main() { - assert_eq!(std::mem::align_of::(), 8); + assert_eq!(crate::rusti::align_of::(), 8); } } @@ -34,21 +36,21 @@ mod m { mod m { #[cfg(target_arch = "x86_64")] pub fn main() { - assert_eq!(std::mem::align_of::(), 8); + assert_eq!(crate::rusti::align_of::(), 8); } } #[cfg(target_os = "windows")] mod m { pub fn main() { - assert_eq!(std::mem::align_of::(), 8); + assert_eq!(crate::rusti::align_of::(), 8); } } #[cfg(target_family = "wasm")] mod m { pub fn main() { - assert_eq!(std::mem::align_of::(), 8); + assert_eq!(crate::rusti::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 31d70c1dd9ec0..8da2bb385ef25 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 b08e37dbd7472..5f6a6099ba23e 100644 --- a/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr +++ b/tests/ui/layout/invalid-unsized-in-always-sized-tail.stderr @@ -19,9 +19,13 @@ LL | struct MySlice(T); | this could be changed to `T: ?Sized`... error[E0080]: the type `MySlice<[bool]>` has an unknown layout - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + --> $DIR/invalid-unsized-in-always-sized-tail.rs:15:28 + | +LL | static CHECK: () = assert!(align_of::() == 1); + | ^^^^^^^^^^^^^^^^ evaluation of `CHECK` failed inside this call | - = note: evaluation of `::ALIGN` failed here +note: inside `std::mem::align_of::` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL error: aborting due to 2 previous errors diff --git a/tests/ui/layout/layout-cycle.rs b/tests/ui/layout/layout-cycle.rs index b38bd52c6ade9..3c930def43b2b 100644 --- a/tests/ui/layout/layout-cycle.rs +++ b/tests/ui/layout/layout-cycle.rs @@ -1,6 +1,6 @@ //@ build-fail -//~^ ERROR: cycle detected when computing layout of -//~? ERROR: a cycle occurred during layout computation +//~^ ERROR: a cycle occurred during layout computation +//~| ERROR: cycle detected when computing layout of // Issue #111176 -- ensure that we do not emit ICE on layout cycles diff --git a/tests/ui/layout/layout-cycle.stderr b/tests/ui/layout/layout-cycle.stderr index e05ff614567c4..a3cdb7edcc232 100644 --- a/tests/ui/layout/layout-cycle.stderr +++ b/tests/ui/layout/layout-cycle.stderr @@ -2,22 +2,10 @@ 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[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: failed to get layout for S>: a cycle occurred during layout computation error: aborting due to 2 previous errors -Some errors have detailed explanations: E0080, E0391. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/limits/issue-17913.32bit.stderr b/tests/ui/limits/issue-17913.32bit.stderr deleted file mode 100644 index 1311822d0d0c4..0000000000000 --- a/tests/ui/limits/issue-17913.32bit.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here - -error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::ALIGN` failed here - -note: the above error was encountered while instantiating `fn Box::<[&usize; usize::MAX]>::new` - --> $DIR/issue-17913.rs:16:21 - | -LL | let a: Box<_> = Box::new([&n; SIZE]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.64bit.stderr b/tests/ui/limits/issue-17913.64bit.stderr deleted file mode 100644 index b0481ee99378c..0000000000000 --- a/tests/ui/limits/issue-17913.64bit.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here - -error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of `<[&usize; usize::MAX] as std::mem::SizedTypeProperties>::ALIGN` failed here - -note: the above error was encountered while instantiating `fn Box::<[&usize; usize::MAX]>::new` - --> $DIR/issue-17913.rs:9:21 - | -LL | let a: Box<_> = Box::new([&n; SIZE]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/limits/issue-17913.rs b/tests/ui/limits/issue-17913.rs index d804b64ab330e..85deab4bc4c74 100644 --- a/tests/ui/limits/issue-17913.rs +++ b/tests/ui/limits/issue-17913.rs @@ -1,7 +1,5 @@ //@ build-fail -//@ stderr-per-bitwidth //@ normalize-stderr: "\[&usize; \d+\]" -> "[&usize; usize::MAX]" -//@ normalize-stderr: "\[&n; 0x[0-9A-F]+_usize\]" -> "[&n; SIZE]" #[cfg(target_pointer_width = "64")] fn main() { @@ -18,4 +16,3 @@ fn main() { } //~? ERROR are too big for the target architecture -//~? ERROR are too big for the target architecture diff --git a/tests/ui/limits/issue-17913.stderr b/tests/ui/limits/issue-17913.stderr new file mode 100644 index 0000000000000..e9c3c14e18143 --- /dev/null +++ b/tests/ui/limits/issue-17913.stderr @@ -0,0 +1,5 @@ +error: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + +error: aborting due to 1 previous error + diff --git a/tests/ui/limits/issue-55878.rs b/tests/ui/limits/issue-55878.rs index 10fa1dd06d64d..9e75f00a408f9 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 994e43854f825..a529efa2ad063 100644 --- a/tests/ui/limits/issue-55878.stderr +++ b/tests/ui/limits/issue-55878.stderr @@ -1,7 +1,11 @@ error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + --> $DIR/issue-55878.rs:4:26 + | +LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main` failed inside this call | - = note: evaluation of `<[u8; usize::MAX] as std::mem::SizedTypeProperties>::SIZE` failed here +note: inside `std::mem::size_of::<[u8; usize::MAX]>` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/limits/issue-75158-64.rs b/tests/ui/limits/issue-75158-64.rs index a49195bb3dc1a..b294b147a91a2 100644 --- a/tests/ui/limits/issue-75158-64.rs +++ b/tests/ui/limits/issue-75158-64.rs @@ -1,4 +1,4 @@ -//~? ERROR values of the type `[u8; usize::MAX]` are too big for the target architecture +//~ ERROR //@ build-fail //@ ignore-32bit diff --git a/tests/ui/limits/issue-75158-64.stderr b/tests/ui/limits/issue-75158-64.stderr index bab0e1b777c28..a3772e509ed67 100644 --- a/tests/ui/limits/issue-75158-64.stderr +++ b/tests/ui/limits/issue-75158-64.stderr @@ -1,14 +1,4 @@ -error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | - = note: evaluation of ` 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: values of the type `[u8; usize::MAX]` are too big for the target architecture error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/query-system/query_depth.rs b/tests/ui/query-system/query_depth.rs index da6bafa51ab24..29514b58e2422 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 abb6365765f09..f738b01ed6ca7 100644 --- a/tests/ui/query-system/query_depth.stderr +++ b/tests/ui/query-system/query_depth.stderr @@ -1,8 +1,11 @@ error: queries overflow the depth limit! - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + --> $DIR/query_depth.rs:28:1 + | +LL | fn main() { + | ^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`) - = note: query depth increased by 64 when computing layout of `core::option::Option>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + = note: query depth increased by 65 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 058f06732b927..b18cd11198e8d 100644 --- a/tests/ui/structs-enums/rec-align-u32.rs +++ b/tests/ui/structs-enums/rec-align-u32.rs @@ -6,6 +6,7 @@ #![feature(core_intrinsics, rustc_attrs)] use std::mem; +use std::intrinsics; // This is the type with the questionable alignment #[derive(Debug)] @@ -33,12 +34,12 @@ pub fn main() { // Send it through the shape code let y = format!("{:?}", x); - println!("align inner = {:?}", mem::align_of::()); + println!("align inner = {:?}", intrinsics::align_of::()); println!("size outer = {:?}", mem::size_of::()); println!("y = {:?}", y); // per clang/gcc the alignment of `inner` is 4 on x86. - assert_eq!(mem::align_of::(), m::align()); + assert_eq!(intrinsics::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 41b196dc5c222..df219892d7374 100644 --- a/tests/ui/structs-enums/rec-align-u64.rs +++ b/tests/ui/structs-enums/rec-align-u64.rs @@ -7,6 +7,7 @@ #![feature(core_intrinsics, rustc_attrs)] use std::mem; +use std::intrinsics; // This is the type with the questionable alignment #[derive(Debug)] @@ -83,12 +84,12 @@ pub fn main() { let y = format!("{:?}", x); - println!("align inner = {:?}", mem::align_of::()); + println!("align inner = {:?}", intrinsics::align_of::()); println!("size outer = {:?}", mem::size_of::()); println!("y = {:?}", y); // per clang/gcc the alignment of `Inner` is 4 on x86. - assert_eq!(mem::align_of::(), m::m::align()); + assert_eq!(intrinsics::align_of::(), m::m::align()); // per clang/gcc the size of `Outer` should be 12 // because `Inner`s alignment was 4.