diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index a57689a45b67b..1e55e887ca146 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1533,8 +1533,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { Rvalue::Use(operand) | Rvalue::Repeat(operand, _) | Rvalue::UnaryOp(_ /*un_op*/, operand) - | Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) - | Rvalue::ShallowInitBox(operand, _ /*ty*/) => { + | Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) => { self.consume_operand(location, (operand, span), state) } diff --git a/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs b/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs index 722b59f145d9d..f2b5ca0208f52 100644 --- a/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs +++ b/compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs @@ -297,8 +297,9 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> { Rvalue::Use(operand) | Rvalue::Repeat(operand, _) | Rvalue::UnaryOp(_ /*un_op*/, operand) - | Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) - | Rvalue::ShallowInitBox(operand, _ /*ty*/) => self.consume_operand(location, operand), + | Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) => { + self.consume_operand(location, operand) + } &Rvalue::Discriminant(place) => { self.access_place( diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 984a154853a98..d049bebe6aa7e 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1059,17 +1059,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { &Rvalue::NullaryOp(NullOp::ContractChecks, _) => {} &Rvalue::NullaryOp(NullOp::UbChecks, _) => {} - Rvalue::ShallowInitBox(_operand, 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::Cast(cast_kind, op, ty) => { match *cast_kind { CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, coercion_source) => { @@ -2211,7 +2200,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { | Rvalue::Ref(..) | Rvalue::RawPtr(..) | Rvalue::Cast(..) - | Rvalue::ShallowInitBox(..) | Rvalue::BinaryOp(..) | Rvalue::NullaryOp(..) | Rvalue::CopyForDeref(..) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 2f53bbf8b7934..2d7fa745a2809 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -619,11 +619,6 @@ impl Deref for Box { } } -#[lang = "exchange_malloc"] -unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size) -} - #[lang = "drop"] pub trait Drop { fn drop(&mut self); diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index c97218797107b..ecad760a05735 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -917,7 +917,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: lval.write_cvalue_transmute(fx, operand); } Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in codegen"), - Rvalue::ShallowInitBox(..) => bug!("`ShallowInitBox` in codegen"), } } StatementKind::StorageLive(_) diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 9dfb12be24363..8d5bd83cc66ce 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -628,11 +628,6 @@ impl Deref for Box { } } -#[lang = "exchange_malloc"] -unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size) -} - #[lang = "drop"] pub trait Drop { fn drop(&mut self); diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 0c626a9cd7817..ea4c25e5c0ddb 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -731,7 +731,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { OperandRef { val: operand.val, layout } } mir::Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in codegen"), - mir::Rvalue::ShallowInitBox(..) => bug!("`ShallowInitBox` in codegen"), } } diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 2c6dd5bd01f9c..502f83e35acb0 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -653,7 +653,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { | NullOp::ContractChecks, _, ) => {} - Rvalue::ShallowInitBox(_, _) => {} Rvalue::UnaryOp(op, operand) => { let ty = operand.ty(self.body, self.tcx); @@ -853,7 +852,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } // This can be called on stable via the `vec!` macro. - if tcx.is_lang_item(callee, LangItem::ExchangeMalloc) { + if tcx.is_diagnostic_item(sym::box_new, callee) { self.check_op(ops::HeapAllocation); // Allow this call, skip all the checks below. return; diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 5b65f1726f6c2..65e06f98f695b 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -239,8 +239,7 @@ where Rvalue::Use(operand) | Rvalue::Repeat(operand, _) | Rvalue::UnaryOp(_, operand) - | Rvalue::Cast(_, operand, _) - | Rvalue::ShallowInitBox(operand, _) => in_operand::(cx, in_local, operand), + | Rvalue::Cast(_, operand, _) => in_operand::(cx, in_local, operand), Rvalue::BinaryOp(_, box (lhs, rhs)) => { in_operand::(cx, in_local, lhs) || in_operand::(cx, in_local, rhs) diff --git a/compiler/rustc_const_eval/src/check_consts/resolver.rs b/compiler/rustc_const_eval/src/check_consts/resolver.rs index 664dda8701a63..7ca7922464204 100644 --- a/compiler/rustc_const_eval/src/check_consts/resolver.rs +++ b/compiler/rustc_const_eval/src/check_consts/resolver.rs @@ -192,7 +192,6 @@ where } mir::Rvalue::Cast(..) - | mir::Rvalue::ShallowInitBox(..) | mir::Rvalue::Use(..) | mir::Rvalue::CopyForDeref(..) | mir::Rvalue::ThreadLocalRef(..) diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 1766bbe92480a..1b80b2e7cdfa9 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -255,12 +255,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { self.write_immediate(*val, &dest)?; } - ShallowInitBox(ref operand, _) => { - let src = self.eval_operand(operand, None)?; - let v = self.read_immediate(&src)?; - self.write_immediate(*v, &dest)?; - } - Cast(cast_kind, ref operand, cast_ty) => { let src = self.eval_operand(operand, None)?; let cast_ty = diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 311cf8f995c82..2ffa87b1d080f 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -330,7 +330,6 @@ language_item_table! { FormatPlaceholder, sym::format_placeholder, format_placeholder, Target::Struct, GenericRequirement::None; FormatUnsafeArg, sym::format_unsafe_arg, format_unsafe_arg, Target::Struct, GenericRequirement::None; - ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None; DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None; diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 60c2ef4d563e4..9fbe1331e6c38 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1239,10 +1239,6 @@ impl<'tcx> Debug for Rvalue<'tcx> { } } - ShallowInitBox(ref place, ref ty) => { - with_no_trimmed_paths!(write!(fmt, "ShallowInitBox({place:?}, {ty})")) - } - WrapUnsafeBinder(ref op, ty) => { with_no_trimmed_paths!(write!(fmt, "wrap_binder!({op:?}; {ty})")) } diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 91a528678901b..25b726fc67e99 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -708,11 +708,6 @@ impl<'tcx> ConstOperand<'tcx> { /////////////////////////////////////////////////////////////////////////// // Rvalues -pub enum RvalueInitializationState { - Shallow, - Deep, -} - impl<'tcx> Rvalue<'tcx> { /// Returns true if rvalue can be safely removed when the result is unused. #[inline] @@ -748,7 +743,6 @@ impl<'tcx> Rvalue<'tcx> { | Rvalue::UnaryOp(_, _) | Rvalue::Discriminant(_) | Rvalue::Aggregate(_, _) - | Rvalue::ShallowInitBox(_, _) | Rvalue::WrapUnsafeBinder(_, _) => true, } } @@ -800,21 +794,10 @@ impl<'tcx> Rvalue<'tcx> { } AggregateKind::RawPtr(ty, mutability) => Ty::new_ptr(tcx, ty, mutability), }, - Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty), Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty, Rvalue::WrapUnsafeBinder(_, ty) => ty, } } - - #[inline] - /// Returns `true` if this rvalue is deeply initialized (most rvalues) or - /// whether its only shallowly initialized (`Rvalue::Box`). - pub fn initialization_state(&self) -> RvalueInitializationState { - match *self { - Rvalue::ShallowInitBox(_, _) => RvalueInitializationState::Shallow, - _ => RvalueInitializationState::Deep, - } - } } impl BorrowKind { diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 38f03cf4e8a00..30637ec09c416 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1450,13 +1450,6 @@ pub enum Rvalue<'tcx> { /// coroutine lowering, `Coroutine` aggregate kinds are disallowed too. Aggregate(Box>, IndexVec>), - /// Transmutes a `*mut u8` into shallow-initialized `Box`. - /// - /// This is different from a normal transmute because dataflow analysis will treat the box as - /// initialized but its content as uninitialized. Like other pointer casts, this in general - /// affects alias analysis. - ShallowInitBox(Operand<'tcx>, Ty<'tcx>), - /// A CopyForDeref is equivalent to a read from a place at the /// codegen level, but is treated specially by drop elaboration. When such a read happens, it /// is guaranteed (via nature of the mir_opt `Derefer` in rustc_mir_transform/src/deref_separator) diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 36e508f16ae2c..53c14d885aff3 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -814,11 +814,6 @@ macro_rules! make_mir_visitor { } } - Rvalue::ShallowInitBox(operand, ty) => { - self.visit_operand(operand, location); - self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)); - } - Rvalue::WrapUnsafeBinder(op, ty) => { self.visit_operand(op, location); self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)); diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index e72ed78d07e6a..bf0b25dac4c74 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -284,10 +284,6 @@ pub enum ExprKind<'tcx> { lint_level: LintLevel, value: ExprId, }, - /// A `box ` expression. - Box { - value: ExprId, - }, /// An `if` expression. If { if_then_scope: region::Scope, diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index dcfa6c4db3274..164ecbe804e30 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -50,7 +50,6 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>( Scope { value, region_scope: _, lint_level: _ } => { visitor.visit_expr(&visitor.thir()[value]) } - Box { value } => visitor.visit_expr(&visitor.thir()[value]), If { cond, then, else_opt, if_then_scope: _ } => { visitor.visit_expr(&visitor.thir()[cond]); visitor.visit_expr(&visitor.thir()[then]); diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs index 5e7a57d51a9ca..fb8fd73a9fd4e 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs @@ -554,7 +554,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::Unary { .. } | ExprKind::Binary { .. } | ExprKind::LogicalOp { .. } - | ExprKind::Box { .. } | ExprKind::Cast { .. } | ExprKind::Use { .. } | ExprKind::NeverToAny { .. } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 3a5839f2d404d..81afa0440998f 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -1,7 +1,6 @@ //! See docs in `build/expr/mod.rs`. use rustc_abi::FieldIdx; -use rustc_hir::lang_items::LangItem; use rustc_index::{Idx, IndexVec}; use rustc_middle::bug; use rustc_middle::middle::region; @@ -121,74 +120,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } block.and(Rvalue::UnaryOp(op, arg)) } - ExprKind::Box { value } => { - let value_ty = this.thir[value].ty; - let tcx = this.tcx; - let source_info = this.source_info(expr_span); - - let size = this.temp(tcx.types.usize, expr_span); - this.cfg.push_assign( - block, - source_info, - size, - Rvalue::NullaryOp(NullOp::SizeOf, value_ty), - ); - - let 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( - tcx, - tcx.require_lang_item(LangItem::ExchangeMalloc, expr_span), - [], - expr_span, - ); - let storage = this.temp(Ty::new_mut_ptr(tcx, tcx.types.u8), expr_span); - let success = this.cfg.start_new_block(); - this.cfg.terminate( - block, - source_info, - TerminatorKind::Call { - func: exchange_malloc, - args: [ - Spanned { node: Operand::Move(size), span: DUMMY_SP }, - Spanned { node: Operand::Move(align), span: DUMMY_SP }, - ] - .into(), - destination: storage, - target: Some(success), - unwind: UnwindAction::Continue, - call_source: CallSource::Misc, - fn_span: expr_span, - }, - ); - this.diverge_from(block); - block = success; - - let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span)); - this.cfg - .push(block, Statement::new(source_info, StatementKind::StorageLive(result))); - if let Some(scope) = scope.temp_lifetime { - // schedule a shallow free of that memory, lest we unwind: - this.schedule_drop_storage_and_value(expr_span, scope, result); - } - - // Transmute `*mut u8` to the box (thus far, uninitialized): - let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value_ty); - this.cfg.push_assign(block, source_info, Place::from(result), box_); - - // initialize the box contents: - block = this - .expr_into_dest(this.tcx.mk_place_deref(Place::from(result)), block, value) - .into_block(); - block.and(Rvalue::Use(Operand::Move(Place::from(result)))) - } ExprKind::Cast { source } => { let source_expr = &this.thir[source]; diff --git a/compiler/rustc_mir_build/src/builder/expr/category.rs b/compiler/rustc_mir_build/src/builder/expr/category.rs index 5e4219dbf5bc9..4cc0731391f87 100644 --- a/compiler/rustc_mir_build/src/builder/expr/category.rs +++ b/compiler/rustc_mir_build/src/builder/expr/category.rs @@ -64,7 +64,6 @@ impl Category { | ExprKind::Closure { .. } | ExprKind::Unary { .. } | ExprKind::Binary { .. } - | ExprKind::Box { .. } | ExprKind::Cast { .. } | ExprKind::PointerCoercion { .. } | ExprKind::Repeat { .. } diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs index bb65ef28bdc8c..1e588a5f0204f 100644 --- a/compiler/rustc_mir_build/src/builder/expr/into.rs +++ b/compiler/rustc_mir_build/src/builder/expr/into.rs @@ -769,7 +769,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // these are the cases that are more naturally handled by some other mode ExprKind::Unary { .. } | ExprKind::Binary { .. } - | ExprKind::Box { .. } | ExprKind::Cast { .. } | ExprKind::PointerCoercion { .. } | ExprKind::Repeat { .. } diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 195d45c2c4c49..252103cb19d45 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -474,7 +474,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { | ExprKind::LoopMatch { .. } | ExprKind::Let { .. } | ExprKind::Match { .. } - | ExprKind::Box { .. } | ExprKind::If { .. } | ExprKind::InlineAsm { .. } | ExprKind::OffsetOf { .. } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 0b9bc018a09b3..ce8f2b58ee704 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -20,7 +20,7 @@ use rustc_middle::ty::{ self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs, }; use rustc_middle::{bug, span_bug}; -use rustc_span::{Span, sym}; +use rustc_span::Span; use tracing::{debug, info, instrument, trace}; use crate::errors::*; @@ -385,24 +385,6 @@ impl<'tcx> ThirBuildCx<'tcx> { from_hir_call: true, fn_span: expr.span, } - } else if let ty::FnDef(def_id, _) = self.typeck_results.expr_ty(fun).kind() - && let Some(intrinsic) = self.tcx.intrinsic(def_id) - && intrinsic.name == sym::box_new - { - // We don't actually evaluate `fun` here, so make sure that doesn't miss any side-effects. - if !matches!(fun.kind, hir::ExprKind::Path(_)) { - span_bug!( - expr.span, - "`box_new` intrinsic can only be called via path expression" - ); - } - let value = &args[0]; - return Expr { - temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, - ty: expr_ty, - span: expr.span, - kind: ExprKind::Box { value: self.mirror_expr(value) }, - }; } else { // Tuple-like ADTs are represented as ExprKind::Call. We convert them here. let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 3929a97eed8f2..4cdac20ebcae5 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -353,7 +353,6 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { | Binary { .. } | Block { .. } | Borrow { .. } - | Box { .. } | Call { .. } | ByUse { .. } | Closure { .. } diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs index e0a5c18a2eedb..e33dfad2b1100 100644 --- a/compiler/rustc_mir_build/src/thir/print.rs +++ b/compiler/rustc_mir_build/src/thir/print.rs @@ -205,11 +205,6 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> { self.print_expr(*value, depth_lvl + 2); print_indented!(self, "}", depth_lvl); } - Box { value } => { - print_indented!(self, "Box {", depth_lvl); - self.print_expr(*value, depth_lvl + 1); - print_indented!(self, "}", depth_lvl); - } If { if_then_scope, cond, then, else_opt } => { print_indented!(self, "If {", depth_lvl); print_indented!(self, format!("if_then_scope: {:?}", if_then_scope), depth_lvl + 1); diff --git a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs index a4e4e30a8bb6c..6e48696b4479a 100644 --- a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs @@ -87,7 +87,6 @@ where Rvalue::Cast(..) | Rvalue::Ref(_, BorrowKind::Fake(_), _) - | Rvalue::ShallowInitBox(..) | Rvalue::Use(..) | Rvalue::ThreadLocalRef(..) | Rvalue::Repeat(..) diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index b45f8a724c69f..c61dffb2daf35 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -391,15 +391,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { } StatementKind::Assign(box (place, rval)) => { self.create_move_path(*place); - if let RvalueInitializationState::Shallow = rval.initialization_state() { - // Box starts out uninitialized - need to create a separate - // move-path for the interior so it will be separate from - // the exterior. - self.create_move_path(self.tcx.mk_place_deref(*place)); - self.gather_init(place.as_ref(), InitKind::Shallow); - } else { - self.gather_init(place.as_ref(), InitKind::Deep); - } + self.gather_init(place.as_ref(), InitKind::Deep); self.gather_rvalue(rval); } StatementKind::FakeRead(box (_, place)) => { @@ -435,7 +427,6 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { Rvalue::Use(ref operand) | Rvalue::Repeat(ref operand, _) | Rvalue::Cast(_, ref operand, _) - | Rvalue::ShallowInitBox(ref operand, _) | Rvalue::UnaryOp(_, ref operand) | Rvalue::WrapUnsafeBinder(ref operand, _) => self.gather_operand(operand), Rvalue::BinaryOp(ref _binop, box (ref lhs, ref rhs)) => { diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index fd5269d4ff8c8..af3ad76ba5ac2 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -480,7 +480,6 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { Rvalue::Discriminant(place) => state.get_discr(place.as_ref(), &self.map), Rvalue::Use(operand) => return self.handle_operand(operand, state), Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in runtime MIR"), - Rvalue::ShallowInitBox(..) => bug!("`ShallowInitBox` in runtime MIR"), Rvalue::Ref(..) | Rvalue::RawPtr(..) => { // We don't track such places. return ValueOrPlace::TOP; diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 808be19cbd817..68c47ec4c1922 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -1,12 +1,8 @@ //! This pass transforms derefs of Box into a deref of the pointer inside Box. //! //! Box is not actually a pointer so it is incorrect to dereference it directly. -//! -//! `ShallowInitBox` being a device for drop elaboration to understand deferred assignment to box -//! contents, we do not need this any more on runtime MIR. -use rustc_abi::{FieldIdx, VariantIdx}; -use rustc_index::{IndexVec, indexvec}; +use rustc_abi::FieldIdx; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; use rustc_middle::span_bug; @@ -89,68 +85,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { self.super_place(place, context, location); } - - fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { - self.super_statement(stmt, location); - - let tcx = self.tcx; - let source_info = stmt.source_info; - - if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind - && let Rvalue::ShallowInitBox(ref mut mutptr_to_u8, pointee) = *rvalue - && let ty::Adt(box_adt, box_args) = Ty::new_box(tcx, pointee).kind() - { - let args = tcx.mk_args(&[pointee.into()]); - let (unique_ty, nonnull_ty, ptr_ty) = - build_ptr_tys(tcx, pointee, self.unique_def, self.nonnull_def); - let adt_kind = |def: ty::AdtDef<'tcx>, args| { - Box::new(AggregateKind::Adt(def.did(), VariantIdx::ZERO, args, None, None)) - }; - let zst = |ty| { - Operand::Constant(Box::new(ConstOperand { - span: source_info.span, - user_ty: None, - const_: Const::zero_sized(ty), - })) - }; - - let constptr = self.patch.new_temp(ptr_ty, source_info.span); - self.patch.add_assign( - location, - constptr.into(), - Rvalue::Cast(CastKind::Transmute, mutptr_to_u8.clone(), ptr_ty), - ); - - let nonnull = self.patch.new_temp(nonnull_ty, source_info.span); - self.patch.add_assign( - location, - nonnull.into(), - Rvalue::Aggregate( - adt_kind(self.nonnull_def, args), - indexvec![Operand::Move(constptr.into())], - ), - ); - - let unique = self.patch.new_temp(unique_ty, source_info.span); - let phantomdata_ty = - self.unique_def.non_enum_variant().fields[FieldIdx::ONE].ty(tcx, args); - self.patch.add_assign( - location, - unique.into(), - Rvalue::Aggregate( - adt_kind(self.unique_def, args), - indexvec![Operand::Move(nonnull.into()), zst(phantomdata_ty)], - ), - ); - - let global_alloc_ty = - box_adt.non_enum_variant().fields[FieldIdx::ONE].ty(tcx, box_args); - *rvalue = Rvalue::Aggregate( - adt_kind(*box_adt, box_args), - indexvec![Operand::Move(unique.into()), zst(global_alloc_ty)], - ); - } - } } pub(super) struct ElaborateBoxDerefs; diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 03073bb7cbdb0..c8c9663b7981a 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1074,7 +1074,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> { // Unsupported values. Rvalue::ThreadLocalRef(..) => return None, - Rvalue::CopyForDeref(_) | Rvalue::ShallowInitBox(..) => { + Rvalue::CopyForDeref(_) => { bug!("forbidden in runtime MIR: {rvalue:?}") } }; diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index c67e875175fee..5b237e8ffc551 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -442,7 +442,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { | Rvalue::CopyForDeref(..) | Rvalue::Repeat(..) | Rvalue::Cast(..) - | Rvalue::ShallowInitBox(..) | Rvalue::Discriminant(..) | Rvalue::NullaryOp(..) | Rvalue::WrapUnsafeBinder(..) => {} @@ -620,8 +619,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ImmTy::from_scalar(Scalar::from_target_usize(val, self), layout).into() } - ShallowInitBox(..) => return None, - Cast(ref kind, ref value, to) => match kind { CastKind::IntToInt | CastKind::IntToFloat => { let value = self.eval_operand(value)?; diff --git a/compiler/rustc_mir_transform/src/lint.rs b/compiler/rustc_mir_transform/src/lint.rs index 2ab49645dc44f..86cd1fc4df4eb 100644 --- a/compiler/rustc_mir_transform/src/lint.rs +++ b/compiler/rustc_mir_transform/src/lint.rs @@ -85,7 +85,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Lint<'a, 'tcx> { | Rvalue::Repeat(..) | Rvalue::Aggregate(..) | Rvalue::Cast(..) - | Rvalue::ShallowInitBox(..) | Rvalue::WrapUnsafeBinder(..) => true, Rvalue::ThreadLocalRef(..) | Rvalue::NullaryOp(..) diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index c7dc18a4a1343..00974863a5cce 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -457,8 +457,6 @@ impl<'tcx> Validator<'_, 'tcx> { NullOp::ContractChecks => {} }, - Rvalue::ShallowInitBox(_, _) => return Err(Unpromotable), - Rvalue::UnaryOp(op, operand) => { match op { // These operations can never fail. diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index bef81935bb8f7..b0e7ec40577f4 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -1255,14 +1255,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } } - Rvalue::ShallowInitBox(operand, _) => { - if self.body.phase >= MirPhase::Runtime(RuntimePhase::Initial) { - self.fail(location, format!("ShallowInitBox after ElaborateBoxDerefs")) - } - - let a = operand.ty(&self.body.local_decls, self.tcx); - check_kinds!(a, "Cannot shallow init type {:?}", ty::RawPtr(..)); - } Rvalue::Cast(kind, operand, target_type) => { let op_ty = operand.ty(self.body, self.tcx); match kind { diff --git a/compiler/rustc_public/src/mir/body.rs b/compiler/rustc_public/src/mir/body.rs index 615a5a48d15b7..a82d3bbd1c49b 100644 --- a/compiler/rustc_public/src/mir/body.rs +++ b/compiler/rustc_public/src/mir/body.rs @@ -567,13 +567,6 @@ pub enum Rvalue { /// [#74836]: https://github.com/rust-lang/rust/issues/74836 Repeat(Operand, TyConst), - /// Transmutes a `*mut u8` into shallow-initialized `Box`. - /// - /// This is different from a normal transmute because dataflow analysis will treat the box as - /// initialized but its content as uninitialized. Like other pointer casts, this in general - /// affects alias analysis. - ShallowInitBox(Operand, Ty), - /// Creates a pointer/reference to the given thread local. /// /// The yielded type is a `*mut T` if the static is mutable, otherwise if the static is extern a @@ -659,7 +652,6 @@ impl Rvalue { } AggregateKind::RawPtr(ty, mutability) => Ok(Ty::new_ptr(ty, mutability)), }, - Rvalue::ShallowInitBox(_, ty) => Ok(Ty::new_box(*ty)), Rvalue::CopyForDeref(place) => place.ty(locals), } } diff --git a/compiler/rustc_public/src/mir/pretty.rs b/compiler/rustc_public/src/mir/pretty.rs index 8904870f29e32..c1d9b7ed48957 100644 --- a/compiler/rustc_public/src/mir/pretty.rs +++ b/compiler/rustc_public/src/mir/pretty.rs @@ -382,7 +382,6 @@ fn pretty_rvalue(writer: &mut W, rval: &Rvalue) -> io::Result<()> { Rvalue::Repeat(op, cnst) => { write!(writer, "[{}; {}]", pretty_operand(op), pretty_ty_const(cnst)) } - Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::ThreadLocalRef(item) => { write!(writer, "thread_local_ref{item:?}") } diff --git a/compiler/rustc_public/src/mir/visit.rs b/compiler/rustc_public/src/mir/visit.rs index 775237c8b3220..d89df555ba249 100644 --- a/compiler/rustc_public/src/mir/visit.rs +++ b/compiler/rustc_public/src/mir/visit.rs @@ -277,10 +277,6 @@ macro_rules! make_mir_visitor { self.visit_operand(op, location); self.visit_ty_const(constant, location); } - Rvalue::ShallowInitBox(op, ty) => { - self.visit_ty(ty, location); - self.visit_operand(op, location) - } Rvalue::ThreadLocalRef(_) => {} Rvalue::NullaryOp(_, ty) => { self.visit_ty(ty, location); diff --git a/compiler/rustc_public/src/unstable/convert/stable/mir.rs b/compiler/rustc_public/src/unstable/convert/stable/mir.rs index 392347ce345a0..891f287bb3b1a 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mir.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mir.rs @@ -243,9 +243,6 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> { let operands = operands.iter().map(|op| op.stable(tables, cx)).collect(); crate::mir::Rvalue::Aggregate(agg_kind.stable(tables, cx), operands) } - ShallowInitBox(op, ty) => { - crate::mir::Rvalue::ShallowInitBox(op.stable(tables, cx), ty.stable(tables, cx)) - } CopyForDeref(place) => crate::mir::Rvalue::CopyForDeref(place.stable(tables, cx)), WrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"), } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 38340f9bd7ec5..5f54a4bf73c31 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -944,7 +944,6 @@ symbols! { exact_div, except, exception_handling: "exception-handling", - exchange_malloc, exclusive_range_pattern, exhaustive_integer_patterns, exhaustive_patterns, diff --git a/compiler/rustc_ty_utils/messages.ftl b/compiler/rustc_ty_utils/messages.ftl index c1684bfb43b66..f67b5c1a94d0b 100644 --- a/compiler/rustc_ty_utils/messages.ftl +++ b/compiler/rustc_ty_utils/messages.ftl @@ -12,8 +12,6 @@ ty_utils_block_not_supported = blocks are not supported in generic constants ty_utils_borrow_not_supported = borrowing is not supported in generic constants -ty_utils_box_not_supported = allocations are not allowed in generic constants - ty_utils_by_use_not_supported = .use is not allowed in generic constants ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index eb751da7c7363..4913d32e55c8b 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -233,7 +233,6 @@ fn recurse_build<'tcx>( | ExprKind::LoopMatch { .. } => { error(GenericConstantTooComplexSub::LoopNotSupported(node.span))? } - ExprKind::Box { .. } => error(GenericConstantTooComplexSub::BoxNotSupported(node.span))?, ExprKind::ByUse { .. } => { error(GenericConstantTooComplexSub::ByUseNotSupported(node.span))? } @@ -320,7 +319,6 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> { count.has_non_region_param() } thir::ExprKind::Scope { .. } - | thir::ExprKind::Box { .. } | thir::ExprKind::If { .. } | thir::ExprKind::Call { .. } | thir::ExprKind::ByUse { .. } diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index f92c405242ce9..ebabb7f92afa1 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -51,8 +51,6 @@ pub(crate) enum GenericConstantTooComplexSub { YieldNotSupported(#[primary_span] Span), #[label(ty_utils_loop_not_supported)] LoopNotSupported(#[primary_span] Span), - #[label(ty_utils_box_not_supported)] - BoxNotSupported(#[primary_span] Span), #[label(ty_utils_binary_not_supported)] BinaryNotSupported(#[primary_span] Span), #[label(ty_utils_by_use_not_supported)] diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 39450f69ce30a..f966812f7386b 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -342,19 +342,6 @@ unsafe impl Allocator for Global { } } -/// The allocator for `Box`. -#[cfg(not(no_global_oom_handling))] -#[lang = "exchange_malloc"] -#[inline] -#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces -unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { - let layout = unsafe { Layout::from_size_align_unchecked(size, align) }; - match Global.allocate(layout) { - Ok(ptr) => ptr.as_mut_ptr(), - Err(_) => handle_alloc_error(layout), - } -} - // # Allocation error handler #[cfg(not(no_global_oom_handling))] diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index ae43fbfe1d69e..046af055362ee 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -233,15 +233,6 @@ pub struct Box< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, >(Unique, A); -/// Constructs a `Box` by calling the `exchange_malloc` lang item and moving the argument into -/// the newly allocated memory. This is an intrinsic to avoid unnecessary copies. -/// -/// This is the surface syntax for `box ` expressions. -#[doc(hidden)] -#[rustc_intrinsic] -#[unstable(feature = "liballoc_internals", issue = "none")] -pub fn box_new(x: T) -> Box; - impl Box { /// Allocates memory on the heap and then places `x` into it. /// @@ -253,13 +244,13 @@ impl Box { /// let five = Box::new(5); /// ``` #[cfg(not(no_global_oom_handling))] - #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[rustc_diagnostic_item = "box_new"] + #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub fn new(x: T) -> Self { - return box_new(x); + return Self::new_in(x, Global); } /// Constructs a new box with uninitialized contents. @@ -405,14 +396,23 @@ impl Box { #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] #[must_use] - #[inline] + #[inline(always)] pub fn new_in(x: T, alloc: A) -> Self where A: Allocator, { let mut boxed = Self::new_uninit_in(alloc); - boxed.write(x); - unsafe { boxed.assume_init() } + unsafe { + // SAFETY: `x` is valid for writing and has the same layout as `T`. + // + // We use `ptr::write` as `MaybeUninit::write` creates + // extra stack copies of `T` in debug mode. + // + // See https://github.com/rust-lang/rust/issues/136043 for more context. + ptr::write(&raw mut *boxed as *mut T, x); + // SAFETY: `x` was just initialized above. + boxed.assume_init() + } } /// Allocates memory in the given allocator then places `x` into it, diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 1e6e2ae8c3675..54f0c7bb38014 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -50,7 +50,7 @@ macro_rules! vec { <[_]>::into_vec( // Using the intrinsic produces a dramatic improvement in stack usage for // unoptimized programs using this code path to construct large Vecs. - $crate::boxed::box_new([$($x),+]) + $crate::boxed::Box::new([$($x),+]) ) ); } diff --git a/src/doc/rustc-dev-guide/src/lang-items.md b/src/doc/rustc-dev-guide/src/lang-items.md index 867c42144770e..70e9cfc523c73 100644 --- a/src/doc/rustc-dev-guide/src/lang-items.md +++ b/src/doc/rustc-dev-guide/src/lang-items.md @@ -23,8 +23,8 @@ Features provided by lang items include: `core::marker`; lang item `phantom_data`. Lang items are loaded lazily by the compiler; e.g. if one never uses `Box` -then there is no need to define functions for `exchange_malloc` and -`box_free`. `rustc` will emit an error when an item is needed but not found +then there is no need to define struct `global_alloc_ty`. +`rustc` will emit an error when an item is needed but not found in the current crate or any that it depends on. Most lang items are defined by the `core` library, but if you're trying to build an diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 7722bebdbbe0d..2dabde141232f 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 @@ -197,8 +197,7 @@ fn check_rvalue<'tcx>( Rvalue::NullaryOp( NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks | NullOp::ContractChecks, _, - ) - | Rvalue::ShallowInitBox(_, _) => Ok(()), + ) => Ok(()), Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(body, cx.tcx); if ty.is_integral() || ty.is_bool() { diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 849dcb9e88fb1..2a11ec7bcd4e8 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -809,7 +809,6 @@ ui/consts/issue-94371.rs ui/consts/issue-94675.rs ui/consts/issue-96169.rs ui/coroutine/issue-102645.rs -ui/coroutine/issue-105084.rs ui/coroutine/issue-110929-coroutine-conflict-error-ice.rs ui/coroutine/issue-113279.rs ui/coroutine/issue-44197.rs diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.diff b/tests/mir-opt/box_expr.main.ElaborateDrops.diff index 827dc6ac7aefe..9aa28f91d021c 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.diff +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.diff @@ -4,90 +4,61 @@ fn main() -> () { let mut _0: (); let _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let _6: (); - let mut _7: std::boxed::Box; -+ let mut _8: &mut std::boxed::Box; -+ let mut _9: (); -+ let mut _10: *const S; + let mut _2: S; + let _3: (); + let mut _4: std::boxed::Box; scope 1 { debug x => _1; } bb0: { StorageLive(_1); - _2 = SizeOf(S); - _3 = AlignOf(S); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; + StorageLive(_2); + _2 = S::new() -> [return: bb1, unwind continue]; } bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, S); - (*_5) = S::new() -> [return: bb2, unwind: bb8]; + _1 = Box::::new(move _2) -> [return: bb2, unwind: bb7]; } bb2: { - _1 = move _5; -- drop(_5) -> [return: bb3, unwind continue]; -+ goto -> bb3; + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = move _1; + _3 = std::mem::drop::>(move _4) -> [return: bb3, unwind: bb5]; } bb3: { - StorageDead(_5); - StorageLive(_6); - StorageLive(_7); - _7 = move _1; - _6 = std::mem::drop::>(move _7) -> [return: bb4, unwind: bb6]; - } - - bb4: { - StorageDead(_7); - StorageDead(_6); + StorageDead(_4); + StorageDead(_3); _0 = const (); -- drop(_1) -> [return: bb5, unwind continue]; -+ goto -> bb5; +- drop(_1) -> [return: bb4, unwind continue]; ++ goto -> bb4; } - bb5: { + bb4: { StorageDead(_1); return; } + bb5 (cleanup): { +- drop(_4) -> [return: bb6, unwind terminate(cleanup)]; ++ goto -> bb6; + } + bb6 (cleanup): { -- drop(_7) -> [return: bb7, unwind terminate(cleanup)]; -+ goto -> bb7; +- drop(_1) -> [return: bb8, unwind terminate(cleanup)]; ++ goto -> bb8; } bb7 (cleanup): { -- drop(_1) -> [return: bb9, unwind terminate(cleanup)]; -+ goto -> bb9; +- drop(_2) -> [return: bb8, unwind terminate(cleanup)]; ++ goto -> bb8; } bb8 (cleanup): { -- drop(_5) -> [return: bb9, unwind terminate(cleanup)]; -+ goto -> bb12; - } - - bb9 (cleanup): { resume; -+ } -+ -+ bb10 (cleanup): { -+ _8 = &mut _5; -+ _9 = as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)]; -+ } -+ -+ bb11 (cleanup): { -+ goto -> bb10; -+ } -+ -+ bb12 (cleanup): { -+ _10 = copy ((_5.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); -+ goto -> bb11; } } diff --git a/tests/mir-opt/box_expr.move_from_inner.ElaborateDrops.diff b/tests/mir-opt/box_expr.move_from_inner.ElaborateDrops.diff new file mode 100644 index 0000000000000..a0804c3531e7b --- /dev/null +++ b/tests/mir-opt/box_expr.move_from_inner.ElaborateDrops.diff @@ -0,0 +1,109 @@ +- // MIR for `move_from_inner` before ElaborateDrops ++ // MIR for `move_from_inner` after ElaborateDrops + + fn move_from_inner() -> () { + let mut _0: (); + let _1: std::boxed::Box; + let mut _2: S; + let _3: (); + let mut _4: S; ++ let mut _5: &mut std::boxed::Box; ++ let mut _6: (); ++ let mut _7: &mut std::boxed::Box; ++ let mut _8: (); ++ let mut _9: *const S; ++ let mut _10: &mut std::boxed::Box; ++ let mut _11: (); ++ let mut _12: *const S; + scope 1 { + debug x => _1; + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = S::new() -> [return: bb1, unwind continue]; + } + + bb1: { + _1 = Box::::new(move _2) -> [return: bb2, unwind: bb7]; + } + + bb2: { + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = move (*_1); + _3 = std::mem::drop::(move _4) -> [return: bb3, unwind: bb5]; + } + + bb3: { + StorageDead(_4); + StorageDead(_3); + _0 = const (); +- drop(_1) -> [return: bb4, unwind continue]; ++ goto -> bb13; + } + + bb4: { + StorageDead(_1); + return; + } + + bb5 (cleanup): { +- drop(_4) -> [return: bb6, unwind terminate(cleanup)]; ++ goto -> bb6; + } + + bb6 (cleanup): { +- drop(_1) -> [return: bb8, unwind terminate(cleanup)]; ++ goto -> bb16; + } + + bb7 (cleanup): { +- drop(_2) -> [return: bb8, unwind terminate(cleanup)]; ++ goto -> bb8; + } + + bb8 (cleanup): { + resume; ++ } ++ ++ bb9: { ++ goto -> bb4; ++ } ++ ++ bb10: { ++ _5 = &mut _1; ++ _6 = as Drop>::drop(move _5) -> [return: bb9, unwind: bb8]; ++ } ++ ++ bb11 (cleanup): { ++ _7 = &mut _1; ++ _8 = as Drop>::drop(move _7) -> [return: bb8, unwind terminate(cleanup)]; ++ } ++ ++ bb12: { ++ goto -> bb10; ++ } ++ ++ bb13: { ++ _9 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); ++ goto -> bb12; ++ } ++ ++ bb14 (cleanup): { ++ _10 = &mut _1; ++ _11 = as Drop>::drop(move _10) -> [return: bb8, unwind terminate(cleanup)]; ++ } ++ ++ bb15 (cleanup): { ++ goto -> bb14; ++ } ++ ++ bb16 (cleanup): { ++ _12 = copy ((_1.0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); ++ goto -> bb15; + } + } + diff --git a/tests/mir-opt/box_expr.rs b/tests/mir-opt/box_expr.rs index 6299c98718094..70ce316ece11e 100644 --- a/tests/mir-opt/box_expr.rs +++ b/tests/mir-opt/box_expr.rs @@ -1,26 +1,17 @@ //@ test-mir-pass: ElaborateDrops //@ needs-unwind - +// skip-filecheck #![feature(rustc_attrs, liballoc_internals)] +// EMIT_MIR box_expr.move_from_inner.ElaborateDrops.diff +fn move_from_inner() { + let x = Box::new(S::new()); + drop(*x); +} + // EMIT_MIR box_expr.main.ElaborateDrops.diff fn main() { - // CHECK-LABEL: fn main( - // CHECK: [[ptr:_.*]] = move {{_.*}} as *const S (Transmute); - // CHECK: [[nonnull:_.*]] = NonNull:: { pointer: move [[ptr]] }; - // CHECK: [[unique:_.*]] = Unique:: { pointer: move [[nonnull]], _marker: const PhantomData:: }; - // CHECK: [[box:_.*]] = Box::(move [[unique]], const std::alloc::Global); - // CHECK: [[ptr:_.*]] = copy (([[box]].0: std::ptr::Unique).0: std::ptr::NonNull) as *const S (Transmute); - // CHECK: (*[[ptr]]) = S::new() -> [return: [[ret:bb.*]], unwind: [[unwind:bb.*]]]; - // CHECK: [[ret]]: { - // CHECK: [[box2:_.*]] = move [[box]]; - // CHECK: [[box3:_.*]] = move [[box2]]; - // CHECK: std::mem::drop::>(move [[box3]]) - // CHECK: [[unwind]] (cleanup): { - // CHECK: [[boxref:_.*]] = &mut [[box]]; - // CHECK: as Drop>::drop(move [[boxref]]) - - let x = std::boxed::box_new(S::new()); + let x = Box::new(S::new()); drop(x); } diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.ElaborateDrops.diff b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.ElaborateDrops.diff new file mode 100644 index 0000000000000..2e961f06010bf --- /dev/null +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.ElaborateDrops.diff @@ -0,0 +1,129 @@ +- // MIR for `move_out_by_subslice` before ElaborateDrops ++ // MIR for `move_out_by_subslice` after ElaborateDrops + + fn move_out_by_subslice() -> () { + let mut _0: (); + let _1: [std::boxed::Box; 3]; + let mut _2: std::boxed::Box; + let mut _3: std::boxed::Box; + let mut _4: std::boxed::Box; + scope 1 { + debug a => _1; + let _5: [std::boxed::Box; 2]; + scope 2 { + debug _y => _5; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = Box::::new(const 1_i32) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_3); + _3 = Box::::new(const 2_i32) -> [return: bb2, unwind: bb11]; + } + + bb2: { + StorageLive(_4); + _4 = Box::::new(const 3_i32) -> [return: bb3, unwind: bb10]; + } + + bb3: { + _1 = [move _2, move _3, move _4]; +- drop(_4) -> [return: bb4, unwind: bb10]; ++ goto -> bb4; + } + + bb4: { + StorageDead(_4); +- drop(_3) -> [return: bb5, unwind: bb11]; ++ goto -> bb5; + } + + bb5: { + StorageDead(_3); +- drop(_2) -> [return: bb6, unwind continue]; ++ goto -> bb6; + } + + bb6: { + StorageDead(_2); + PlaceMention(_1); + StorageLive(_5); + _5 = move _1[0..2]; + _0 = const (); + drop(_5) -> [return: bb7, unwind: bb9]; + } + + bb7: { + StorageDead(_5); +- drop(_1) -> [return: bb8, unwind continue]; ++ goto -> bb19; + } + + bb8: { + StorageDead(_1); + return; + } + + bb9 (cleanup): { +- drop(_1) -> [return: bb12, unwind terminate(cleanup)]; ++ goto -> bb22; + } + + bb10 (cleanup): { + drop(_3) -> [return: bb11, unwind terminate(cleanup)]; + } + + bb11 (cleanup): { + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { + resume; ++ } ++ ++ bb13: { ++ goto -> bb8; ++ } ++ ++ bb14 (cleanup): { ++ goto -> bb12; ++ } ++ ++ bb15 (cleanup): { ++ goto -> bb14; ++ } ++ ++ bb16 (cleanup): { ++ drop(_1[2..3]) -> [return: bb15, unwind terminate(cleanup)]; ++ } ++ ++ bb17: { ++ goto -> bb13; ++ } ++ ++ bb18: { ++ goto -> bb17; ++ } ++ ++ bb19: { ++ drop(_1[2..3]) -> [return: bb18, unwind: bb15]; ++ } ++ ++ bb20 (cleanup): { ++ goto -> bb12; ++ } ++ ++ bb21 (cleanup): { ++ goto -> bb20; ++ } ++ ++ bb22 (cleanup): { ++ drop(_1[2..3]) -> [return: bb21, unwind terminate(cleanup)]; + } + } + 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 deleted file mode 100644 index 6d3b2cf291038..0000000000000 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir +++ /dev/null @@ -1,107 +0,0 @@ -// MIR for `move_out_by_subslice` after built - -fn move_out_by_subslice() -> () { - let mut _0: (); - let _1: [std::boxed::Box; 2]; - let mut _2: std::boxed::Box; - let mut _3: usize; - let mut _4: usize; - let mut _5: *mut u8; - let mut _6: std::boxed::Box; - let mut _7: std::boxed::Box; - let mut _8: usize; - let mut _9: usize; - let mut _10: *mut u8; - let mut _11: std::boxed::Box; - scope 1 { - debug a => _1; - let _12: [std::boxed::Box; 2]; - scope 2 { - debug _y => _12; - } - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - _3 = SizeOf(i32); - _4 = AlignOf(i32); - _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; - } - - bb1: { - StorageLive(_6); - _6 = ShallowInitBox(move _5, i32); - (*_6) = const 1_i32; - _2 = move _6; - drop(_6) -> [return: bb2, unwind: bb12]; - } - - bb2: { - 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(_11); - _11 = ShallowInitBox(move _10, i32); - (*_11) = const 2_i32; - _7 = move _11; - drop(_11) -> [return: bb4, unwind: bb11]; - } - - bb4: { - StorageDead(_11); - _1 = [move _2, move _7]; - drop(_7) -> [return: bb5, unwind: bb12]; - } - - bb5: { - StorageDead(_7); - drop(_2) -> [return: bb6, unwind: bb13]; - } - - bb6: { - StorageDead(_2); - FakeRead(ForLet(None), _1); - PlaceMention(_1); - StorageLive(_12); - _12 = move _1[0..2]; - _0 = const (); - drop(_12) -> [return: bb8, unwind: bb10]; - } - - bb7: { - FakeRead(ForMatchedPlace(None), _1); - unreachable; - } - - bb8: { - StorageDead(_12); - drop(_1) -> [return: bb9, unwind: bb13]; - } - - bb9: { - StorageDead(_1); - return; - } - - bb10 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb11 (cleanup): { - drop(_7) -> [return: bb12, unwind terminate(cleanup)]; - } - - bb12 (cleanup): { - drop(_2) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb13 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.ElaborateDrops.diff b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.ElaborateDrops.diff new file mode 100644 index 0000000000000..2a86d25a76bf8 --- /dev/null +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.ElaborateDrops.diff @@ -0,0 +1,101 @@ +- // MIR for `move_out_from_end` before ElaborateDrops ++ // MIR for `move_out_from_end` after ElaborateDrops + + fn move_out_from_end() -> () { + let mut _0: (); + let _1: [std::boxed::Box; 2]; + let mut _2: std::boxed::Box; + let mut _3: std::boxed::Box; + scope 1 { + debug a => _1; + let _4: std::boxed::Box; + scope 2 { + debug _y => _4; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = Box::::new(const 1_i32) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_3); + _3 = Box::::new(const 2_i32) -> [return: bb2, unwind: bb8]; + } + + bb2: { + _1 = [move _2, move _3]; +- drop(_3) -> [return: bb3, unwind: bb8]; ++ goto -> bb3; + } + + bb3: { + StorageDead(_3); +- drop(_2) -> [return: bb4, unwind continue]; ++ goto -> bb4; + } + + bb4: { + StorageDead(_2); + PlaceMention(_1); + StorageLive(_4); + _4 = move _1[1 of 2]; + _0 = const (); + drop(_4) -> [return: bb5, unwind: bb7]; + } + + bb5: { + StorageDead(_4); +- drop(_1) -> [return: bb6, unwind continue]; ++ goto -> bb14; + } + + bb6: { + StorageDead(_1); + return; + } + + bb7 (cleanup): { +- drop(_1) -> [return: bb9, unwind terminate(cleanup)]; ++ goto -> bb16; + } + + bb8 (cleanup): { + drop(_2) -> [return: bb9, unwind terminate(cleanup)]; + } + + bb9 (cleanup): { + resume; ++ } ++ ++ bb10: { ++ goto -> bb6; ++ } ++ ++ bb11 (cleanup): { ++ drop(_1[0..1]) -> [return: bb9, unwind terminate(cleanup)]; ++ } ++ ++ bb12 (cleanup): { ++ goto -> bb11; ++ } ++ ++ bb13: { ++ drop(_1[0..1]) -> [return: bb10, unwind: bb9]; ++ } ++ ++ bb14: { ++ goto -> bb13; ++ } ++ ++ bb15 (cleanup): { ++ drop(_1[0..1]) -> [return: bb9, unwind terminate(cleanup)]; ++ } ++ ++ bb16 (cleanup): { ++ goto -> bb15; + } + } + 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 deleted file mode 100644 index 003b90a912d25..0000000000000 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir +++ /dev/null @@ -1,107 +0,0 @@ -// MIR for `move_out_from_end` after built - -fn move_out_from_end() -> () { - let mut _0: (); - let _1: [std::boxed::Box; 2]; - let mut _2: std::boxed::Box; - let mut _3: usize; - let mut _4: usize; - let mut _5: *mut u8; - let mut _6: std::boxed::Box; - let mut _7: std::boxed::Box; - let mut _8: usize; - let mut _9: usize; - let mut _10: *mut u8; - let mut _11: std::boxed::Box; - scope 1 { - debug a => _1; - let _12: std::boxed::Box; - scope 2 { - debug _y => _12; - } - } - - bb0: { - StorageLive(_1); - StorageLive(_2); - _3 = SizeOf(i32); - _4 = AlignOf(i32); - _5 = alloc::alloc::exchange_malloc(move _3, move _4) -> [return: bb1, unwind: bb13]; - } - - bb1: { - StorageLive(_6); - _6 = ShallowInitBox(move _5, i32); - (*_6) = const 1_i32; - _2 = move _6; - drop(_6) -> [return: bb2, unwind: bb12]; - } - - bb2: { - 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(_11); - _11 = ShallowInitBox(move _10, i32); - (*_11) = const 2_i32; - _7 = move _11; - drop(_11) -> [return: bb4, unwind: bb11]; - } - - bb4: { - StorageDead(_11); - _1 = [move _2, move _7]; - drop(_7) -> [return: bb5, unwind: bb12]; - } - - bb5: { - StorageDead(_7); - drop(_2) -> [return: bb6, unwind: bb13]; - } - - bb6: { - StorageDead(_2); - FakeRead(ForLet(None), _1); - PlaceMention(_1); - StorageLive(_12); - _12 = move _1[1 of 2]; - _0 = const (); - drop(_12) -> [return: bb8, unwind: bb10]; - } - - bb7: { - FakeRead(ForMatchedPlace(None), _1); - unreachable; - } - - bb8: { - StorageDead(_12); - drop(_1) -> [return: bb9, unwind: bb13]; - } - - bb9: { - StorageDead(_1); - return; - } - - bb10 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb11 (cleanup): { - drop(_7) -> [return: bb12, unwind terminate(cleanup)]; - } - - bb12 (cleanup): { - drop(_2) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb13 (cleanup): { - resume; - } -} diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_from_middle.ElaborateDrops.diff b/tests/mir-opt/building/uniform_array_move_out.move_out_from_middle.ElaborateDrops.diff new file mode 100644 index 0000000000000..e372d8e3fa9be --- /dev/null +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_from_middle.ElaborateDrops.diff @@ -0,0 +1,129 @@ +- // MIR for `move_out_from_middle` before ElaborateDrops ++ // MIR for `move_out_from_middle` after ElaborateDrops + + fn move_out_from_middle() -> () { + let mut _0: (); + let _1: [std::boxed::Box; 3]; + let mut _2: std::boxed::Box; + let mut _3: std::boxed::Box; + let mut _4: std::boxed::Box; + scope 1 { + debug a => _1; + let _5: std::boxed::Box; + scope 2 { + debug _y => _5; + } + } + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = Box::::new(const 1_i32) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_3); + _3 = Box::::new(const 2_i32) -> [return: bb2, unwind: bb11]; + } + + bb2: { + StorageLive(_4); + _4 = Box::::new(const 3_i32) -> [return: bb3, unwind: bb10]; + } + + bb3: { + _1 = [move _2, move _3, move _4]; +- drop(_4) -> [return: bb4, unwind: bb10]; ++ goto -> bb4; + } + + bb4: { + StorageDead(_4); +- drop(_3) -> [return: bb5, unwind: bb11]; ++ goto -> bb5; + } + + bb5: { + StorageDead(_3); +- drop(_2) -> [return: bb6, unwind continue]; ++ goto -> bb6; + } + + bb6: { + StorageDead(_2); + PlaceMention(_1); + StorageLive(_5); + _5 = move _1[1 of 3]; + _0 = const (); + drop(_5) -> [return: bb7, unwind: bb9]; + } + + bb7: { + StorageDead(_5); +- drop(_1) -> [return: bb8, unwind continue]; ++ goto -> bb19; + } + + bb8: { + StorageDead(_1); + return; + } + + bb9 (cleanup): { +- drop(_1) -> [return: bb12, unwind terminate(cleanup)]; ++ goto -> bb22; + } + + bb10 (cleanup): { + drop(_3) -> [return: bb11, unwind terminate(cleanup)]; + } + + bb11 (cleanup): { + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { + resume; ++ } ++ ++ bb13: { ++ goto -> bb8; ++ } ++ ++ bb14 (cleanup): { ++ drop(_1[0..1]) -> [return: bb12, unwind terminate(cleanup)]; ++ } ++ ++ bb15 (cleanup): { ++ goto -> bb14; ++ } ++ ++ bb16 (cleanup): { ++ drop(_1[2..3]) -> [return: bb15, unwind terminate(cleanup)]; ++ } ++ ++ bb17: { ++ drop(_1[0..1]) -> [return: bb13, unwind: bb12]; ++ } ++ ++ bb18: { ++ goto -> bb17; ++ } ++ ++ bb19: { ++ drop(_1[2..3]) -> [return: bb18, unwind: bb15]; ++ } ++ ++ bb20 (cleanup): { ++ drop(_1[0..1]) -> [return: bb12, unwind terminate(cleanup)]; ++ } ++ ++ bb21 (cleanup): { ++ goto -> bb20; ++ } ++ ++ bb22 (cleanup): { ++ drop(_1[2..3]) -> [return: bb21, unwind terminate(cleanup)]; + } + } + diff --git a/tests/mir-opt/building/uniform_array_move_out.rs b/tests/mir-opt/building/uniform_array_move_out.rs index 36245273fe1c1..2356f77604866 100644 --- a/tests/mir-opt/building/uniform_array_move_out.rs +++ b/tests/mir-opt/building/uniform_array_move_out.rs @@ -1,17 +1,24 @@ //@ compile-flags: -Zmir-opt-level=0 +//@ needs-unwind // skip-filecheck #![feature(liballoc_internals, rustc_attrs)] -// EMIT_MIR uniform_array_move_out.move_out_from_end.built.after.mir +// EMIT_MIR uniform_array_move_out.move_out_from_end.ElaborateDrops.diff fn move_out_from_end() { - let a = [std::boxed::box_new(1), std::boxed::box_new(2)]; + let a = [Box::new(1), Box::new(2)]; let [.., _y] = a; } -// EMIT_MIR uniform_array_move_out.move_out_by_subslice.built.after.mir +// EMIT_MIR uniform_array_move_out.move_out_from_middle.ElaborateDrops.diff +fn move_out_from_middle() { + let a = [Box::new(1), Box::new(2), Box::new(3)]; + let [_, _y, _] = a; +} + +// EMIT_MIR uniform_array_move_out.move_out_by_subslice.ElaborateDrops.diff fn move_out_by_subslice() { - let a = [std::boxed::box_new(1), std::boxed::box_new(2)]; - let [_y @ ..] = a; + let a = [Box::new(1), Box::new(2), Box::new(3)]; + let [_y @ .., _] = a; } fn main() { 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 16bae67cc9892..20a4cbfd8e266 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,15 +6,7 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: usize; - let mut _5: usize; - let mut _6: *mut u8; - let mut _7: std::boxed::Box; - let mut _8: *const i32; - let mut _9: std::ptr::NonNull; - let mut _10: std::ptr::Unique; - let mut _11: *const i32; - let mut _12: *const i32; + let mut _4: *const i32; scope 1 { debug x => _1; } @@ -24,31 +16,12 @@ - StorageLive(_2); + nop; StorageLive(_3); -- _4 = SizeOf(i32); -- _5 = AlignOf(i32); -- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind unreachable]; -+ _4 = const 4_usize; -+ _5 = const 4_usize; -+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind unreachable]; + _3 = Box::::new(const 42_i32) -> [return: bb1, unwind unreachable]; } bb1: { - 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); + _4 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_4); - _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 3fbf7a57a76f8..9315ec8af90f2 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,15 +6,7 @@ let _1: i32; let mut _2: i32; let mut _3: std::boxed::Box; - let mut _4: usize; - let mut _5: usize; - let mut _6: *mut u8; - let mut _7: std::boxed::Box; - let mut _8: *const i32; - let mut _9: std::ptr::NonNull; - let mut _10: std::ptr::Unique; - let mut _11: *const i32; - let mut _12: *const i32; + let mut _4: *const i32; scope 1 { debug x => _1; } @@ -24,31 +16,12 @@ - StorageLive(_2); + nop; StorageLive(_3); -- _4 = SizeOf(i32); -- _5 = AlignOf(i32); -- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind continue]; -+ _4 = const 4_usize; -+ _5 = const 4_usize; -+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind continue]; + _3 = Box::::new(const 42_i32) -> [return: bb1, unwind continue]; } bb1: { - 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); + _4 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); + _2 = copy (*_4); - _1 = Add(move _2, const 0_i32); - StorageDead(_2); + _1 = copy _2; diff --git a/tests/mir-opt/const_prop/boxes.rs b/tests/mir-opt/const_prop/boxes.rs index a192d6b4133a2..5dc1d1c7f262f 100644 --- a/tests/mir-opt/const_prop/boxes.rs +++ b/tests/mir-opt/const_prop/boxes.rs @@ -10,8 +10,7 @@ fn main() { // CHECK-LABEL: fn main( // CHECK: debug x => [[x:_.*]]; - // CHECK: (*{{_.*}}) = const 42_i32; // CHECK: [[tmp:_.*]] = copy (*{{_.*}}); // CHECK: [[x]] = copy [[tmp]]; - let x = *(std::boxed::box_new(42)) + 0; + let x = *(Box::new(42)) + 0; } 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 f47e544385497..45b0b75df0093 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff @@ -11,6 +11,7 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); + let mut _12: std::alloc::Global; let mut _27: usize; scope 1 { debug vp_ctx => _1; @@ -24,50 +25,65 @@ scope 4 { debug _x => _8; } - scope 18 (inlined foo) { + scope 26 (inlined foo) { let mut _28: *const [()]; } } - scope 16 (inlined slice_from_raw_parts::<()>) { - scope 17 (inlined std::ptr::from_raw_parts::<[()], ()>) { + scope 24 (inlined slice_from_raw_parts::<()>) { + scope 25 (inlined std::ptr::from_raw_parts::<[()], ()>) { } } } } scope 5 (inlined Box::<()>::new) { - 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>; - let mut _20: isize; - let mut _22: !; + scope 6 (inlined Box::<()>::new_in) { + let mut _13: std::boxed::Box>; + let mut _14: *mut (); + let mut _15: *mut std::mem::MaybeUninit<()>; + let mut _16: *const std::mem::MaybeUninit<()>; + let mut _25: std::alloc::Global; + let mut _26: std::ptr::NonNull>; scope 7 { - let _21: std::ptr::NonNull<[u8]>; - scope 8 { - scope 11 (inlined NonNull::<[u8]>::as_mut_ptr) { - scope 12 (inlined NonNull::<[u8]>::as_non_null_ptr) { - scope 13 (inlined NonNull::<[u8]>::cast::) { - let mut _26: *mut [u8]; - scope 14 (inlined NonNull::<[u8]>::as_ptr) { + scope 8 (inlined #[track_caller] std::ptr::write::<()>) { + } + scope 9 (inlined Box::>::assume_init) { + let mut _17: *mut (); + scope 10 { + scope 19 (inlined Box::<()>::from_raw_in) { + let mut _19: std::ptr::Unique<()>; + scope 20 (inlined Unique::<()>::new_unchecked) { + let mut _20: std::ptr::NonNull<()>; + scope 21 (inlined #[track_caller] NonNull::<()>::new_unchecked) { + let _21: (); + let mut _22: *mut (); + let mut _23: *const (); + scope 22 (inlined core::ub_checks::check_language_ub) { + let mut _24: bool; + scope 23 (inlined core::ub_checks::check_language_ub::runtime) { + } + } + } + } + } + } + scope 11 (inlined Box::>::into_raw_with_allocator) { + scope 12 { + let _18: *mut std::mem::MaybeUninit<()>; + scope 13 { + scope 14 { + } + scope 17 (inlined >> as Deref>::deref) { } + scope 18 (inlined #[track_caller] std::ptr::read::) { + } + } + scope 16 (inlined >> as DerefMut>::deref_mut) { } } - scope 15 (inlined NonNull::::as_ptr) { + scope 15 (inlined ManuallyDrop::>>::new) { } } } - scope 10 (inlined ::allocate) { - } - } - scope 9 (inlined #[track_caller] Layout::from_size_align_unchecked) { - let mut _23: bool; - let _24: (); - let mut _25: std::ptr::Alignment; } } } @@ -81,23 +97,14 @@ - _4 = (); + _4 = const (); StorageLive(_12); - StorageLive(_13); - StorageLive(_14); - StorageLive(_15); + _12 = const std::alloc::Global; StorageLive(_16); - StorageLive(_17); -- _12 = SizeOf(()); -- _13 = AlignOf(()); -+ _12 = const 0_usize; -+ _13 = const 1_usize; - StorageLive(_18); - StorageLive(_20); StorageLive(_21); - StorageLive(_22); - StorageLive(_24); - StorageLive(_23); - _23 = UbChecks(); - switchInt(move _23) -> [0: bb6, otherwise: bb5]; + StorageLive(_25); + StorageLive(_26); + StorageLive(_13); +- _13 = Box::<()>::new_uninit_in(move _12) -> [return: bb2, unwind unreachable]; ++ _13 = Box::<()>::new_uninit_in(const std::alloc::Global) -> [return: bb2, unwind unreachable]; } bb1: { @@ -107,40 +114,62 @@ } bb2: { - unreachable; + StorageLive(_14); + StorageLive(_15); + _16 = copy ((_13.0: std::ptr::Unique>).0: std::ptr::NonNull>) as *const std::mem::MaybeUninit<()> (Transmute); + _15 = &raw mut (*_16); + _14 = copy _15 as *mut () (PtrToPtr); + StorageDead(_15); +- (*_14) = copy _4; ++ (*_14) = const (); + StorageDead(_14); + _26 = move ((_13.0: std::ptr::Unique>).0: std::ptr::NonNull>); +- _25 = move (_13.1: std::alloc::Global); ++ _25 = const std::alloc::Global; + StorageLive(_18); + _18 = &raw mut (*_16); +- StorageLive(_17); ++ nop; + _17 = copy _18 as *mut () (PtrToPtr); + StorageLive(_19); + StorageLive(_20); + StorageLive(_23); + StorageLive(_24); + _24 = UbChecks(); + switchInt(copy _24) -> [0: bb5, otherwise: bb3]; } bb3: { -- _22 = handle_alloc_error(move _18) -> unwind unreachable; -+ _22 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; + StorageLive(_22); +- _22 = copy _18 as *mut () (PtrToPtr); +- _21 = NonNull::::new_unchecked::precondition_check(move _22) -> [return: bb4, unwind unreachable]; ++ _22 = copy _17; ++ _21 = NonNull::::new_unchecked::precondition_check(copy _17) -> [return: bb4, unwind unreachable]; } bb4: { - _21 = copy ((_19 as Ok).0: std::ptr::NonNull<[u8]>); -- StorageLive(_26); -+ nop; - _26 = copy _21 as *mut [u8] (Transmute); - _14 = copy _26 as *mut u8 (PtrToPtr); -- StorageDead(_26); -+ nop; - StorageDead(_19); - StorageDead(_24); StorageDead(_22); - StorageDead(_21); + goto -> bb5; + } + + bb5: { + _23 = copy _18 as *const () (PtrToPtr); + _20 = NonNull::<()> { pointer: copy _23 }; + StorageDead(_24); + StorageDead(_23); + _19 = Unique::<()> { pointer: move _20, _marker: const PhantomData::<()> }; StorageDead(_20); +- _3 = Box::<()>(move _19, copy _25); ++ _3 = Box::<()>(move _19, const std::alloc::Global); + StorageDead(_19); +- StorageDead(_17); ++ nop; 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); - StorageDead(_15); - StorageDead(_14); StorageDead(_13); + StorageDead(_26); + StorageDead(_25); + StorageDead(_21); + StorageDead(_16); StorageDead(_12); StorageDead(_4); _2 = &_3; @@ -181,32 +210,5 @@ + nop; drop(_3) -> [return: bb1, unwind unreachable]; } - - bb5: { -- _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 _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); - StorageLive(_19); -- _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _18, const false) -> [return: bb7, unwind unreachable]; -+ _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; - } - - bb7: { - _20 = discriminant(_19); - switchInt(move _20) -> [0: bb4, 1: bb3, otherwise: bb2]; - } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 01 00 00 00 00 00 00 00 │ ........ } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff index 82a14a8b6ec99..fd0d0237c7d62 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff @@ -24,16 +24,18 @@ scope 4 { debug _x => _8; } - scope 7 (inlined foo) { + scope 8 (inlined foo) { let mut _13: *const [()]; } } - scope 5 (inlined slice_from_raw_parts::<()>) { - scope 6 (inlined std::ptr::from_raw_parts::<[()], ()>) { + scope 6 (inlined slice_from_raw_parts::<()>) { + scope 7 (inlined std::ptr::from_raw_parts::<[()], ()>) { } } } } + scope 5 (inlined Box::<()>::new) { + } bb0: { StorageLive(_1); @@ -42,12 +44,22 @@ StorageLive(_3); StorageLive(_4); - _4 = (); -- _3 = Box::<()>::new(move _4) -> [return: bb1, unwind continue]; +- _3 = Box::<()>::new_in(move _4, const std::alloc::Global) -> [return: bb3, unwind continue]; + _4 = const (); -+ _3 = Box::<()>::new(const ()) -> [return: bb1, unwind continue]; ++ _3 = Box::<()>::new_in(const (), const std::alloc::Global) -> [return: bb3, unwind continue]; } bb1: { + StorageDead(_3); + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { StorageDead(_4); _2 = &_3; _1 = &(*_2); @@ -85,17 +97,7 @@ - StorageDead(_5); + nop; + nop; - drop(_3) -> [return: bb2, unwind: bb3]; - } - - bb2: { - StorageDead(_3); - StorageDead(_1); - return; - } - - bb3 (cleanup): { - resume; + drop(_3) -> [return: bb1, unwind: bb2]; } } 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 fe88ff7a53e7d..45b0b75df0093 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff @@ -11,6 +11,7 @@ let mut _9: *const [()]; let mut _10: std::boxed::Box<()>; let mut _11: *const (); + let mut _12: std::alloc::Global; let mut _27: usize; scope 1 { debug vp_ctx => _1; @@ -24,50 +25,65 @@ scope 4 { debug _x => _8; } - scope 18 (inlined foo) { + scope 26 (inlined foo) { let mut _28: *const [()]; } } - scope 16 (inlined slice_from_raw_parts::<()>) { - scope 17 (inlined std::ptr::from_raw_parts::<[()], ()>) { + scope 24 (inlined slice_from_raw_parts::<()>) { + scope 25 (inlined std::ptr::from_raw_parts::<[()], ()>) { } } } } scope 5 (inlined Box::<()>::new) { - 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>; - let mut _20: isize; - let mut _22: !; + scope 6 (inlined Box::<()>::new_in) { + let mut _13: std::boxed::Box>; + let mut _14: *mut (); + let mut _15: *mut std::mem::MaybeUninit<()>; + let mut _16: *const std::mem::MaybeUninit<()>; + let mut _25: std::alloc::Global; + let mut _26: std::ptr::NonNull>; scope 7 { - let _21: std::ptr::NonNull<[u8]>; - scope 8 { - scope 11 (inlined NonNull::<[u8]>::as_mut_ptr) { - scope 12 (inlined NonNull::<[u8]>::as_non_null_ptr) { - scope 13 (inlined NonNull::<[u8]>::cast::) { - let mut _26: *mut [u8]; - scope 14 (inlined NonNull::<[u8]>::as_ptr) { + scope 8 (inlined #[track_caller] std::ptr::write::<()>) { + } + scope 9 (inlined Box::>::assume_init) { + let mut _17: *mut (); + scope 10 { + scope 19 (inlined Box::<()>::from_raw_in) { + let mut _19: std::ptr::Unique<()>; + scope 20 (inlined Unique::<()>::new_unchecked) { + let mut _20: std::ptr::NonNull<()>; + scope 21 (inlined #[track_caller] NonNull::<()>::new_unchecked) { + let _21: (); + let mut _22: *mut (); + let mut _23: *const (); + scope 22 (inlined core::ub_checks::check_language_ub) { + let mut _24: bool; + scope 23 (inlined core::ub_checks::check_language_ub::runtime) { + } + } + } + } + } + } + scope 11 (inlined Box::>::into_raw_with_allocator) { + scope 12 { + let _18: *mut std::mem::MaybeUninit<()>; + scope 13 { + scope 14 { + } + scope 17 (inlined >> as Deref>::deref) { } + scope 18 (inlined #[track_caller] std::ptr::read::) { + } + } + scope 16 (inlined >> as DerefMut>::deref_mut) { } } - scope 15 (inlined NonNull::::as_ptr) { + scope 15 (inlined ManuallyDrop::>>::new) { } } } - scope 10 (inlined ::allocate) { - } - } - scope 9 (inlined #[track_caller] Layout::from_size_align_unchecked) { - let mut _23: bool; - let _24: (); - let mut _25: std::ptr::Alignment; } } } @@ -81,23 +97,14 @@ - _4 = (); + _4 = const (); StorageLive(_12); - StorageLive(_13); - StorageLive(_14); - StorageLive(_15); + _12 = const std::alloc::Global; StorageLive(_16); - StorageLive(_17); -- _12 = SizeOf(()); -- _13 = AlignOf(()); -+ _12 = const 0_usize; -+ _13 = const 1_usize; - StorageLive(_18); - StorageLive(_20); StorageLive(_21); - StorageLive(_22); - StorageLive(_24); - StorageLive(_23); - _23 = UbChecks(); - switchInt(move _23) -> [0: bb6, otherwise: bb5]; + StorageLive(_25); + StorageLive(_26); + StorageLive(_13); +- _13 = Box::<()>::new_uninit_in(move _12) -> [return: bb2, unwind unreachable]; ++ _13 = Box::<()>::new_uninit_in(const std::alloc::Global) -> [return: bb2, unwind unreachable]; } bb1: { @@ -107,40 +114,62 @@ } bb2: { - unreachable; + StorageLive(_14); + StorageLive(_15); + _16 = copy ((_13.0: std::ptr::Unique>).0: std::ptr::NonNull>) as *const std::mem::MaybeUninit<()> (Transmute); + _15 = &raw mut (*_16); + _14 = copy _15 as *mut () (PtrToPtr); + StorageDead(_15); +- (*_14) = copy _4; ++ (*_14) = const (); + StorageDead(_14); + _26 = move ((_13.0: std::ptr::Unique>).0: std::ptr::NonNull>); +- _25 = move (_13.1: std::alloc::Global); ++ _25 = const std::alloc::Global; + StorageLive(_18); + _18 = &raw mut (*_16); +- StorageLive(_17); ++ nop; + _17 = copy _18 as *mut () (PtrToPtr); + StorageLive(_19); + StorageLive(_20); + StorageLive(_23); + StorageLive(_24); + _24 = UbChecks(); + switchInt(copy _24) -> [0: bb5, otherwise: bb3]; } bb3: { -- _22 = handle_alloc_error(move _18) -> unwind unreachable; -+ _22 = handle_alloc_error(const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}) -> unwind unreachable; + StorageLive(_22); +- _22 = copy _18 as *mut () (PtrToPtr); +- _21 = NonNull::::new_unchecked::precondition_check(move _22) -> [return: bb4, unwind unreachable]; ++ _22 = copy _17; ++ _21 = NonNull::::new_unchecked::precondition_check(copy _17) -> [return: bb4, unwind unreachable]; } bb4: { - _21 = copy ((_19 as Ok).0: std::ptr::NonNull<[u8]>); -- StorageLive(_26); -+ nop; - _26 = copy _21 as *mut [u8] (Transmute); - _14 = copy _26 as *mut u8 (PtrToPtr); -- StorageDead(_26); -+ nop; - StorageDead(_19); - StorageDead(_24); StorageDead(_22); - StorageDead(_21); + goto -> bb5; + } + + bb5: { + _23 = copy _18 as *const () (PtrToPtr); + _20 = NonNull::<()> { pointer: copy _23 }; + StorageDead(_24); + StorageDead(_23); + _19 = Unique::<()> { pointer: move _20, _marker: const PhantomData::<()> }; StorageDead(_20); +- _3 = Box::<()>(move _19, copy _25); ++ _3 = Box::<()>(move _19, const std::alloc::Global); + StorageDead(_19); +- StorageDead(_17); ++ nop; 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); - StorageDead(_15); - StorageDead(_14); StorageDead(_13); + StorageDead(_26); + StorageDead(_25); + StorageDead(_21); + StorageDead(_16); StorageDead(_12); StorageDead(_4); _2 = &_3; @@ -181,32 +210,5 @@ + nop; drop(_3) -> [return: bb1, unwind unreachable]; } - - bb5: { -- _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 _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); - StorageLive(_19); -- _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], copy _18, const false) -> [return: bb7, unwind unreachable]; -+ _19 = std::alloc::Global::alloc_impl(const alloc::alloc::exchange_malloc::promoted[0], const Layout {{ size: 0_usize, align: std::ptr::Alignment(std::ptr::alignment::AlignmentEnum::_Align1Shl0) }}, const false) -> [return: bb7, unwind unreachable]; - } - - bb7: { - _20 = discriminant(_19); - switchInt(move _20) -> [0: bb4, 1: bb3, otherwise: bb2]; - } -+ } -+ -+ ALLOC0 (size: 16, align: 8) { -+ 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................ } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff index 82a14a8b6ec99..fd0d0237c7d62 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff @@ -24,16 +24,18 @@ scope 4 { debug _x => _8; } - scope 7 (inlined foo) { + scope 8 (inlined foo) { let mut _13: *const [()]; } } - scope 5 (inlined slice_from_raw_parts::<()>) { - scope 6 (inlined std::ptr::from_raw_parts::<[()], ()>) { + scope 6 (inlined slice_from_raw_parts::<()>) { + scope 7 (inlined std::ptr::from_raw_parts::<[()], ()>) { } } } } + scope 5 (inlined Box::<()>::new) { + } bb0: { StorageLive(_1); @@ -42,12 +44,22 @@ StorageLive(_3); StorageLive(_4); - _4 = (); -- _3 = Box::<()>::new(move _4) -> [return: bb1, unwind continue]; +- _3 = Box::<()>::new_in(move _4, const std::alloc::Global) -> [return: bb3, unwind continue]; + _4 = const (); -+ _3 = Box::<()>::new(const ()) -> [return: bb1, unwind continue]; ++ _3 = Box::<()>::new_in(const (), const std::alloc::Global) -> [return: bb3, unwind continue]; } bb1: { + StorageDead(_3); + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { StorageDead(_4); _2 = &_3; _1 = &(*_2); @@ -85,17 +97,7 @@ - StorageDead(_5); + nop; + nop; - drop(_3) -> [return: bb2, unwind: bb3]; - } - - bb2: { - StorageDead(_3); - StorageDead(_1); - return; - } - - bb3 (cleanup): { - resume; + drop(_3) -> [return: bb1, unwind: bb2]; } } diff --git a/tests/mir-opt/issue_62289.rs b/tests/mir-opt/issue_62289.rs deleted file mode 100644 index d020c2cedca01..0000000000000 --- a/tests/mir-opt/issue_62289.rs +++ /dev/null @@ -1,15 +0,0 @@ -// skip-filecheck -// check that we don't forget to drop the Box if we early return before -// initializing it -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY - -#![feature(rustc_attrs, liballoc_internals)] - -// EMIT_MIR issue_62289.test.ElaborateDrops.before.mir -fn test() -> Option> { - Some(std::boxed::box_new(None?)) -} - -fn main() { - test(); -} 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 deleted file mode 100644 index 736a8bbca49c7..0000000000000 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir +++ /dev/null @@ -1,112 +0,0 @@ -// MIR for `test` before ElaborateDrops - -fn test() -> Option> { - let mut _0: std::option::Option>; - let mut _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: std::ops::ControlFlow, u32>; - let mut _7: std::option::Option; - let mut _8: isize; - let _9: std::option::Option; - let mut _10: !; - let mut _11: std::option::Option; - let _12: u32; - scope 1 { - debug residual => _9; - scope 2 { - } - } - scope 3 { - debug val => _12; - scope 4 { - } - } - - bb0: { - StorageLive(_1); - _2 = SizeOf(u32); - _3 = AlignOf(u32); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind: bb13]; - } - - bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, u32); - StorageLive(_6); - StorageLive(_7); - _7 = Option::::None; - _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; - } - - bb2: { - StorageDead(_7); - PlaceMention(_6); - _8 = discriminant(_6); - switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; - } - - bb3: { - unreachable; - } - - bb4: { - 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(_9); - _9 = copy ((_6 as Break).0: std::option::Option); - StorageLive(_11); - _11 = copy _9; - _0 = > as FromResidual>>::from_residual(move _11) -> [return: bb6, unwind: bb12]; - } - - bb6: { - StorageDead(_11); - StorageDead(_9); - drop(_5) -> [return: bb9, unwind: bb13]; - } - - bb7: { - StorageDead(_5); - _0 = Option::>::Some(move _1); - drop(_1) -> [return: bb8, unwind: bb13]; - } - - bb8: { - StorageDead(_1); - StorageDead(_6); - goto -> bb10; - } - - bb9: { - StorageDead(_5); - StorageDead(_1); - StorageDead(_6); - goto -> bb10; - } - - bb10: { - return; - } - - bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb13 (cleanup): { - resume; - } -} 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 deleted file mode 100644 index 1acb1ae20b698..0000000000000 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir +++ /dev/null @@ -1,112 +0,0 @@ -// MIR for `test` before ElaborateDrops - -fn test() -> Option> { - let mut _0: std::option::Option>; - let mut _1: std::boxed::Box; - let mut _2: usize; - let mut _3: usize; - let mut _4: *mut u8; - let mut _5: std::boxed::Box; - let mut _6: std::ops::ControlFlow, u32>; - let mut _7: std::option::Option; - let mut _8: isize; - let _9: std::option::Option; - let mut _10: !; - let mut _11: std::option::Option; - let _12: u32; - scope 1 { - debug residual => _9; - scope 2 { - } - } - scope 3 { - debug val => _12; - scope 4 { - } - } - - bb0: { - StorageLive(_1); - _2 = SizeOf(u32); - _3 = AlignOf(u32); - _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue]; - } - - bb1: { - StorageLive(_5); - _5 = ShallowInitBox(move _4, u32); - StorageLive(_6); - StorageLive(_7); - _7 = Option::::None; - _6 = as Try>::branch(move _7) -> [return: bb2, unwind: bb12]; - } - - bb2: { - StorageDead(_7); - PlaceMention(_6); - _8 = discriminant(_6); - switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; - } - - bb3: { - unreachable; - } - - bb4: { - 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(_9); - _9 = copy ((_6 as Break).0: std::option::Option); - StorageLive(_11); - _11 = copy _9; - _0 = > as FromResidual>>::from_residual(move _11) -> [return: bb6, unwind: bb12]; - } - - bb6: { - StorageDead(_11); - StorageDead(_9); - drop(_5) -> [return: bb9, unwind continue]; - } - - bb7: { - StorageDead(_5); - _0 = Option::>::Some(move _1); - drop(_1) -> [return: bb8, unwind continue]; - } - - bb8: { - StorageDead(_1); - StorageDead(_6); - goto -> bb10; - } - - bb9: { - StorageDead(_5); - StorageDead(_1); - StorageDead(_6); - goto -> bb10; - } - - bb10: { - return; - } - - bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate(cleanup)]; - } - - bb13 (cleanup): { - resume; - } -} diff --git a/tests/ui/coroutine/issue-105084.rs b/tests/ui/coroutine/issue-105084.rs deleted file mode 100644 index cddee49901757..0000000000000 --- a/tests/ui/coroutine/issue-105084.rs +++ /dev/null @@ -1,43 +0,0 @@ -//@compile-flags: --diagnostic-width=300 -#![feature(coroutines)] -#![feature(coroutine_clone)] -#![feature(coroutine_trait)] -#![feature(rustc_attrs, stmt_expr_attributes, liballoc_internals)] - -use std::ops::Coroutine; -use std::pin::Pin; - -fn copy(x: T) -> T { - x -} - -fn main() { - let mut g = #[coroutine] - || { - // This is desuraged as 4 stages: - // - allocate a `*mut u8` with `exchange_malloc`; - // - create a Box that is ignored for trait computations; - // - compute fields (and yields); - // - assign to `t`. - let t = std::boxed::box_new((5, yield)); - drop(t); - }; - - // Allocate the temporary box. - Pin::new(&mut g).resume(()); - - // The temporary box is in coroutine locals. - // As it is not taken into account for trait computation, - // the coroutine is `Copy`. - let mut h = copy(g); - //~^ ERROR the trait bound `Box<(i32, ())>: Copy` is not satisfied in - - // We now have 2 boxes with the same backing allocation: - // one inside `g` and one inside `h`. - // Proceed and drop `t` in `g`. - Pin::new(&mut g).resume(()); - //~^ ERROR borrow of moved value: `g` - - // Proceed and drop `t` in `h` -> double free! - Pin::new(&mut h).resume(()); -} diff --git a/tests/ui/coroutine/issue-105084.stderr b/tests/ui/coroutine/issue-105084.stderr deleted file mode 100644 index 23c1fdc545922..0000000000000 --- a/tests/ui/coroutine/issue-105084.stderr +++ /dev/null @@ -1,51 +0,0 @@ -error[E0382]: borrow of moved value: `g` - --> $DIR/issue-105084.rs:38:14 - | -LL | let mut g = #[coroutine] - | ----- move occurs because `g` has type `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`, which does not implement the `Copy` trait -... -LL | let mut h = copy(g); - | - value moved here -... -LL | Pin::new(&mut g).resume(()); - | ^^^^^^ value borrowed here after move - | -note: consider changing this parameter type in function `copy` to borrow instead if owning the value isn't necessary - --> $DIR/issue-105084.rs:10:21 - | -LL | fn copy(x: T) -> T { - | ---- ^ this parameter takes ownership of the value - | | - | in this function -help: consider cloning the value if the performance cost is acceptable - | -LL | let mut h = copy(g.clone()); - | ++++++++ - -error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}` - --> $DIR/issue-105084.rs:32:17 - | -LL | || { - | -- within this `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}` -... -LL | let mut h = copy(g); - | ^^^^^^^ within `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>` - | -note: coroutine does not implement `Copy` as this value is used across a yield - --> $DIR/issue-105084.rs:22:41 - | -LL | let t = std::boxed::box_new((5, yield)); - | ------------------------^^^^^-- - | | | - | | yield occurs here, with `std::boxed::box_new((5, yield))` maybe used later - | has type `Box<(i32, ())>` which does not implement `Copy` -note: required by a bound in `copy` - --> $DIR/issue-105084.rs:10:12 - | -LL | fn copy(x: T) -> T { - | ^^^^ required by this bound in `copy` - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0277, E0382. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/limits/issue-17913.rs b/tests/ui/limits/issue-17913.rs index 85deab4bc4c74..a80f25a5d3a4d 100644 --- a/tests/ui/limits/issue-17913.rs +++ b/tests/ui/limits/issue-17913.rs @@ -16,3 +16,4 @@ fn main() { } //~? ERROR are too big for the target architecture +//~? ERROR are too big for the target architecture diff --git a/tests/ui/limits/issue-17913.stderr b/tests/ui/limits/issue-17913.stderr index e9c3c14e18143..7b1730f0f2aa5 100644 --- a/tests/ui/limits/issue-17913.stderr +++ b/tests/ui/limits/issue-17913.stderr @@ -1,5 +1,20 @@ -error: values of the type `[&usize; usize::MAX]` are too big for the target architecture +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>::IS_ZST` failed inside this call +note: inside `std::mem::size_of::<[&usize; usize::MAX]>` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + +error[E0080]: values of the type `[&usize; usize::MAX]` are too big for the target architecture + --> $SRC_DIR/core/src/ptr/alignment.rs:LL:COL + | + = note: evaluation of `std::ptr::Alignment::of::>::{constant#0}` failed inside this call +note: inside `std::mem::align_of::>` + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + +note: the above error was encountered while instantiating `fn Box::<[&usize; usize::MAX]>::try_new_uninit_in` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -error: aborting due to 1 previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/macros/vec-macro-in-pattern.rs b/tests/ui/macros/vec-macro-in-pattern.rs index 9b9a1edf54c9e..5f6caa9967acf 100644 --- a/tests/ui/macros/vec-macro-in-pattern.rs +++ b/tests/ui/macros/vec-macro-in-pattern.rs @@ -4,7 +4,8 @@ fn main() { match Some(vec![42]) { - Some(vec![43]) => {} //~ ERROR expected a pattern, found a function call + Some(vec![43]) => {} + //~^ ERROR found associated function //~| ERROR found associated function //~| ERROR usage of qualified paths in this context is experimental _ => {} diff --git a/tests/ui/macros/vec-macro-in-pattern.stderr b/tests/ui/macros/vec-macro-in-pattern.stderr index 71ba0ea5ad4f5..7878941c112fd 100644 --- a/tests/ui/macros/vec-macro-in-pattern.stderr +++ b/tests/ui/macros/vec-macro-in-pattern.stderr @@ -1,12 +1,3 @@ -error[E0532]: expected a pattern, found a function call - --> $DIR/vec-macro-in-pattern.rs:7:14 - | -LL | Some(vec![43]) => {} - | ^^^^^^^^ not a tuple struct or tuple variant - | - = note: function calls are not allowed in patterns: - = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0658]: usage of qualified paths in this context is experimental --> $DIR/vec-macro-in-pattern.rs:7:14 | @@ -27,7 +18,16 @@ LL | Some(vec![43]) => {} = help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0164]: expected tuple struct or tuple variant, found associated function `::alloc::boxed::Box::new` + --> $DIR/vec-macro-in-pattern.rs:7:14 + | +LL | Some(vec![43]) => {} + | ^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch19-00-patterns.html + = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) + error: aborting due to 3 previous errors -Some errors have detailed explanations: E0164, E0532, E0658. +Some errors have detailed explanations: E0164, E0658. For more information about an error, try `rustc --explain E0164`. diff --git a/tests/ui/static/global-variable-promotion-error-7364.rs b/tests/ui/static/global-variable-promotion-error-7364.rs index dba4a484d6115..b72b1565d5a5d 100644 --- a/tests/ui/static/global-variable-promotion-error-7364.rs +++ b/tests/ui/static/global-variable-promotion-error-7364.rs @@ -4,6 +4,6 @@ use std::cell::RefCell; // Regression test for issue 7364 static boxed: Box> = Box::new(RefCell::new(0)); //~^ ERROR `RefCell` cannot be shared between threads safely [E0277] -//~| ERROR cannot call non-const associated function +//~| ERROR allocations are not allowed in statics [E0010] fn main() { } diff --git a/tests/ui/static/global-variable-promotion-error-7364.stderr b/tests/ui/static/global-variable-promotion-error-7364.stderr index b9d75676bef89..51dfb23e95750 100644 --- a/tests/ui/static/global-variable-promotion-error-7364.stderr +++ b/tests/ui/static/global-variable-promotion-error-7364.stderr @@ -11,16 +11,13 @@ note: required because it appears within the type `Box>` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL = note: shared static variables must have a type that implements `Sync` -error[E0015]: cannot call non-const associated function `Box::>::new` in statics +error[E0010]: allocations are not allowed in statics --> $DIR/global-variable-promotion-error-7364.rs:5:37 | LL | static boxed: Box> = Box::new(RefCell::new(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ allocation not allowed in statics error: aborting due to 2 previous errors -Some errors have detailed explanations: E0015, E0277. -For more information about an error, try `rustc --explain E0015`. +Some errors have detailed explanations: E0010, E0277. +For more information about an error, try `rustc --explain E0010`. diff --git a/tests/ui/static/static-mut-not-constant.rs b/tests/ui/static/static-mut-not-constant.rs index 3830b46828707..57fb249389c7f 100644 --- a/tests/ui/static/static-mut-not-constant.rs +++ b/tests/ui/static/static-mut-not-constant.rs @@ -1,4 +1,4 @@ static mut a: Box = Box::new(3); -//~^ ERROR cannot call non-const associated function +//~^ ERROR allocations are not allowed in statics [E0010] fn main() {} diff --git a/tests/ui/static/static-mut-not-constant.stderr b/tests/ui/static/static-mut-not-constant.stderr index f28ea0b1689ab..694c83ac883a0 100644 --- a/tests/ui/static/static-mut-not-constant.stderr +++ b/tests/ui/static/static-mut-not-constant.stderr @@ -1,12 +1,9 @@ -error[E0015]: cannot call non-const associated function `Box::::new` in statics +error[E0010]: allocations are not allowed in statics --> $DIR/static-mut-not-constant.rs:1:28 | LL | static mut a: Box = Box::new(3); - | ^^^^^^^^^^^ - | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` + | ^^^^^^^^^^^ allocation not allowed in statics error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0010`. diff --git a/tests/ui/unpretty/box.rs b/tests/ui/unpretty/box.rs deleted file mode 100644 index 83fdeff7a1796..0000000000000 --- a/tests/ui/unpretty/box.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ compile-flags: -Zunpretty=thir-tree -//@ check-pass - -#![feature(liballoc_internals)] - -fn main() { - let _ = std::boxed::box_new(1); -} diff --git a/tests/ui/unpretty/box.stdout b/tests/ui/unpretty/box.stdout deleted file mode 100644 index 92155d0c73b9d..0000000000000 --- a/tests/ui/unpretty/box.stdout +++ /dev/null @@ -1,90 +0,0 @@ -DefId(0:3 ~ box[efb9]::main): -params: [ -] -body: - Expr { - ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(11)), backwards_incompatible: None } - span: $DIR/box.rs:6:11: 8:2 (#0) - kind: - Scope { - region_scope: Node(11) - lint_level: Explicit(HirId(DefId(0:3 ~ box[efb9]::main).11)) - value: - Expr { - ty: () - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(11)), backwards_incompatible: None } - span: $DIR/box.rs:6:11: 8:2 (#0) - kind: - Block { - targeted_by_break: false - span: $DIR/box.rs:6:11: 8:2 (#0) - region_scope: Node(1) - safety_mode: Safe - stmts: [ - Stmt { - kind: Let { - remainder_scope: Remainder { block: 1, first_statement_index: 0} - init_scope: Node(2) - pattern: - Pat: { - ty: std::boxed::Box - span: $DIR/box.rs:7:9: 7:10 (#0) - kind: PatKind { - Wild - } - } - , - initializer: Some( - Expr { - ty: std::boxed::Box - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } - span: $DIR/box.rs:7:13: 7:35 (#0) - kind: - Scope { - region_scope: Node(3) - lint_level: Explicit(HirId(DefId(0:3 ~ box[efb9]::main).3)) - value: - Expr { - ty: std::boxed::Box - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } - span: $DIR/box.rs:7:13: 7:35 (#0) - kind: - Box { - Expr { - ty: i32 - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } - span: $DIR/box.rs:7:33: 7:34 (#0) - kind: - Scope { - region_scope: Node(8) - lint_level: Explicit(HirId(DefId(0:3 ~ box[efb9]::main).8)) - value: - Expr { - ty: i32 - temp_lifetime: TempLifetime { temp_lifetime: Some(Node(2)), backwards_incompatible: None } - span: $DIR/box.rs:7:33: 7:34 (#0) - kind: - Literal( lit: Spanned { node: Int(Pu128(1), Unsuffixed), span: $DIR/box.rs:7:33: 7:34 (#0) }, neg: false) - - } - } - } - } - } - } - } - ) - else_block: None - lint_level: Explicit(HirId(DefId(0:3 ~ box[efb9]::main).9)) - span: $DIR/box.rs:7:5: 7:35 (#0) - } - } - ] - expr: [] - } - } - } - } - -