From 0298f75db0b4ee844922e04ec8fcad231bdfbc60 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 28 Aug 2024 16:06:28 +1000 Subject: [PATCH] Remove `HasLocalDecls`. It's a trait that lets you pass any of `Body`, `LocalDecls`, or `IndexVec` to various functions. A minor convenience, and a minor obfuscation, that not actually needed. This commit removes the trait and changes those functions to receive `&LocalDecls` instead of `&D where D: HasLocalDecls`. This makes lots of call sites slightly more verbose, but I think it's worth it for the overall simplicity. --- .../src/diagnostics/conflict_errors.rs | 17 ++-- .../rustc_borrowck/src/diagnostics/mod.rs | 22 +++--- .../src/diagnostics/move_errors.rs | 8 +- .../src/diagnostics/mutability_errors.rs | 18 +++-- compiler/rustc_borrowck/src/lib.rs | 10 +-- compiler/rustc_borrowck/src/path_utils.rs | 2 +- compiler/rustc_borrowck/src/place_ext.rs | 2 +- .../rustc_borrowck/src/places_conflict.rs | 4 +- compiler/rustc_borrowck/src/type_check/mod.rs | 77 ++++++++++--------- .../rustc_codegen_cranelift/src/abi/mod.rs | 4 +- .../src/intrinsics/simd.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 +- compiler/rustc_codegen_ssa/src/mir/place.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 8 +- .../src/check_consts/check.rs | 14 ++-- .../src/check_consts/post_drop_elaboration.rs | 2 +- .../src/check_consts/qualifs.rs | 10 ++- .../src/check_consts/resolver.rs | 13 ++-- .../rustc_const_eval/src/util/alignment.rs | 18 ++--- compiler/rustc_middle/src/mir/mod.rs | 25 ------ compiler/rustc_middle/src/mir/tcx.rs | 46 +++-------- .../src/build/custom/parse/instruction.rs | 2 +- compiler/rustc_mir_build/src/lints.rs | 4 +- .../rustc_mir_dataflow/src/elaborate_drops.rs | 2 +- .../src/impls/borrowed_locals.rs | 2 +- .../src/impls/initialized.rs | 2 +- .../src/move_paths/builder.rs | 6 +- .../src/abort_unwinding_calls.rs | 2 +- .../src/add_moves_for_packed_drops.rs | 4 +- .../src/add_subtyping_projections.rs | 3 +- .../src/check_packed_ref.rs | 2 +- compiler/rustc_mir_transform/src/coroutine.rs | 2 +- .../rustc_mir_transform/src/cost_checker.rs | 2 +- .../src/cross_crate_inline.rs | 2 +- .../src/dead_store_elimination.rs | 2 +- .../src/deref_separator.rs | 3 +- compiler/rustc_mir_transform/src/dest_prop.rs | 10 +-- .../src/early_otherwise_branch.rs | 6 +- .../src/ffi_unwind_calls.rs | 2 +- .../src/function_item_references.rs | 4 +- compiler/rustc_mir_transform/src/inline.rs | 14 ++-- .../rustc_mir_transform/src/jump_threading.rs | 8 +- .../src/known_panics_lint.rs | 2 +- .../rustc_mir_transform/src/match_branches.rs | 2 +- .../src/mentioned_items.rs | 10 +-- .../rustc_mir_transform/src/promote_consts.rs | 14 ++-- .../src/remove_uninit_drops.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 2 +- compiler/rustc_mir_transform/src/sroa.rs | 2 +- compiler/rustc_mir_transform/src/ssa.rs | 4 +- .../src/unreachable_enum_branching.rs | 2 +- .../src/unreachable_prop.rs | 2 +- compiler/rustc_mir_transform/src/validate.rs | 29 ++++--- compiler/rustc_monomorphize/src/collector.rs | 10 +-- .../src/collector/move_check.rs | 2 +- .../clippy_lints/src/redundant_clone.rs | 4 +- .../clippy_utils/src/qualify_min_const_fn.rs | 10 +-- 58 files changed, 231 insertions(+), 260 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index aaeedde2bedc3..8bae97ef4c499 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -244,7 +244,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { ); } - let ty = used_place.ty(self.body, self.infcx.tcx).ty; + let ty = used_place.ty(&self.body.local_decls, self.infcx.tcx).ty; let needs_note = match ty.kind() { ty::Closure(id, _) => { self.infcx.tcx.closure_kind_origin(id.expect_local()).is_none() @@ -254,7 +254,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let mpi = self.move_data.moves[move_out_indices[0]].path; let place = &self.move_data.move_paths[mpi].place; - let ty = place.ty(self.body, self.infcx.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.infcx.tcx).ty; // If we're in pattern, we do nothing in favor of the previous suggestion (#80913). // Same for if we're in a loop, see #101119. @@ -460,7 +460,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { && let ty::Param(_) = arg.kind() { let place = &self.move_data.move_paths[mpi].place; - let ty = place.ty(self.body, self.infcx.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.infcx.tcx).ty; if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() { *has_suggest_reborrow = true; self.suggest_reborrow(err, expr.span, moved_place); @@ -546,7 +546,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } } let place = &self.move_data.move_paths[mpi].place; - let ty = place.ty(self.body, self.infcx.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.infcx.tcx).ty; if let hir::Node::Expr(parent_expr) = parent && let hir::ExprKind::Call(call_expr, _) = parent_expr.kind && let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IntoIterIntoIter, _)) = @@ -828,7 +828,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { moved_place: PlaceRef<'tcx>, sugg_span: Span, ) { - let ty = moved_place.ty(self.body, self.infcx.tcx).ty; + let ty = moved_place.ty(&self.body.local_decls, self.infcx.tcx).ty; debug!("ty: {:?}, kind: {:?}", ty, ty.kind()); let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.param_env, ty) @@ -2204,8 +2204,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { ); return; } - let place_ty = PlaceRef::ty(&place.as_ref(), self.body, tcx).ty; - let borrowed_place_ty = PlaceRef::ty(&borrowed_place.as_ref(), self.body, tcx).ty; + let place_ty = PlaceRef::ty(&place.as_ref(), &self.body.local_decls, tcx).ty; + let borrowed_place_ty = + PlaceRef::ty(&borrowed_place.as_ref(), &self.body.local_decls, tcx).ty; if !has_split_at_mut(place_ty) && !has_split_at_mut(borrowed_place_ty) { // Only mention `split_at_mut` on `Vec`, array and slices. return; @@ -2729,7 +2730,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let union_ty = |place_base| { // Need to use fn call syntax `PlaceRef::ty` to determine the type of `place_base`; // using a type annotation in the closure argument instead leads to a lifetime error. - let ty = PlaceRef::ty(&place_base, self.body, self.infcx.tcx).ty; + let ty = PlaceRef::ty(&place_base, &self.body.local_decls, self.infcx.tcx).ty; ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty) }; diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 33f91d7ad3043..0f3542689a7bf 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -318,10 +318,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { ProjectionElem::Deref | ProjectionElem::Index(..) | ProjectionElem::ConstantIndex { .. } - | ProjectionElem::Subslice { .. } => { - PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx) - } - ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx), + | ProjectionElem::Subslice { .. } => PlaceRef { local, projection: proj_base } + .ty(&self.body.local_decls, self.infcx.tcx), + ProjectionElem::Downcast(..) => place.ty(&self.body.local_decls, self.infcx.tcx), ProjectionElem::Subtype(ty) | ProjectionElem::OpaqueCast(ty) => { PlaceTy::from_ty(*ty) } @@ -426,9 +425,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { .. }) = &bbd.terminator { - if let Some(source) = - BorrowedContentSource::from_call(func.ty(self.body, tcx), tcx) - { + if let Some(source) = BorrowedContentSource::from_call( + func.ty(&self.body.local_decls, tcx), + tcx, + ) { return source; } } @@ -440,7 +440,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // If we didn't find an overloaded deref or index, then assume it's a // built in deref and check the type of the base. - let base_ty = deref_base.ty(self.body, tcx).ty; + let base_ty = deref_base.ty(&self.body.local_decls, tcx).ty; if base_ty.is_unsafe_ptr() { BorrowedContentSource::DerefRawPointer } else if base_ty.is_mutable_ptr() { @@ -1154,7 +1154,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { err.subdiagnostic(CaptureReasonLabel::BorrowContent { var_span }); } if let Some((CallDesugaringKind::ForLoopIntoIter, _)) = desugaring { - let ty = moved_place.ty(self.body, tcx).ty; + let ty = moved_place.ty(&self.body.local_decls, tcx).ty; let suggest = match tcx.get_diagnostic_item(sym::IntoIterator) { Some(def_id) => type_known_to_meet_bound_modulo_regions( self.infcx, @@ -1181,7 +1181,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // suggest to reborrow it where it was moved, so it // will still be valid by the time we get to the usage. if let ty::Ref(_, _, hir::Mutability::Mut) = - moved_place.ty(self.body, self.infcx.tcx).ty.kind() + moved_place.ty(&self.body.local_decls, self.infcx.tcx).ty.kind() { // Suggest `reborrow` in other place for following situations: // 1. If we are in a loop this will be suggested later. @@ -1212,7 +1212,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { }); } // Erase and shadow everything that could be passed to the new infcx. - let ty = moved_place.ty(self.body, tcx).ty; + let ty = moved_place.ty(&self.body.local_decls, tcx).ty; if let ty::Adt(def, args) = ty.peel_refs().kind() && tcx.is_lang_item(def.did(), LangItem::Pin) diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 42b1ffd58ad3e..4e649468cc3f7 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -432,7 +432,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // Inspect the type of the content behind the // borrow to provide feedback about why this // was a move rather than a copy. - let ty = deref_target_place.ty(self.body, tcx).ty; + let ty = deref_target_place.ty(&self.body.local_decls, tcx).ty; let upvar_field = self .prefixes(move_place.as_ref(), PrefixSet::All) .find_map(|p| self.is_upvar_field_projection(p)); @@ -567,7 +567,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { self.add_borrow_suggestions(err, span); if binds_to.is_empty() { - let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; + let place_ty = move_from.ty(&self.body.local_decls, self.infcx.tcx).ty; let place_desc = match self.describe_place(move_from.as_ref()) { Some(desc) => format!("`{desc}`"), None => "value".to_string(), @@ -599,7 +599,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // No binding. Nothing to suggest. GroupedMoveError::OtherIllegalMove { ref original_path, use_spans, .. } => { let use_span = use_spans.var_or_use(); - let place_ty = original_path.ty(self.body, self.infcx.tcx).ty; + let place_ty = original_path.ty(&self.body.local_decls, self.infcx.tcx).ty; let place_desc = match self.describe_place(original_path.as_ref()) { Some(desc) => format!("`{desc}`"), None => "value".to_string(), @@ -757,7 +757,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { /// references to the struct's fields since doing so would be undefined behaviour fn add_note_for_packed_struct_derive(&self, err: &mut Diag<'_>, local: Local) { let local_place: PlaceRef<'tcx> = local.into(); - let local_ty = local_place.ty(self.body.local_decls(), self.infcx.tcx).ty.peel_refs(); + let local_ty = local_place.ty(&self.body.local_decls, self.infcx.tcx).ty.peel_refs(); if let Some(adt) = local_ty.ty_adt_def() && adt.repr().packed() diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 7b791928689c9..af81a74eca54f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -70,7 +70,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)], } => { debug_assert!(is_closure_like( - Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty + Place::ty_from(local, proj_base, &self.body.local_decls, self.infcx.tcx).ty )); let imm_borrow_derefed = self.upvars[upvar_index.index()] @@ -128,7 +128,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { { item_msg = access_place_desc; debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref()); - debug_assert!(is_closure_like(the_place_err.ty(self.body, self.infcx.tcx).ty)); + debug_assert!(is_closure_like( + the_place_err.ty(&self.body.local_decls, self.infcx.tcx).ty + )); reason = if self.is_upvar_field_projection(access_place.as_ref()).is_some() { ", as it is a captured variable in a `Fn` closure".to_string() @@ -267,7 +269,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } => { err.span_label(span, format!("cannot {act}")); - let place = Place::ty_from(local, proj_base, self.body, self.infcx.tcx); + let place = + Place::ty_from(local, proj_base, &self.body.local_decls, self.infcx.tcx); if let Some(span) = get_mut_span_in_struct_field(self.infcx.tcx, place.ty, *field) { err.span_suggestion_verbose( span, @@ -377,7 +380,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { if suggest { self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local); let tcx = self.infcx.tcx; - if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() { + if let ty::Closure(id, _) = + *the_place_err.ty(&self.body.local_decls, tcx).ty.kind() + { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); } } @@ -389,7 +394,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { projection: [proj_base @ .., ProjectionElem::Field(upvar_index, _)], } => { debug_assert!(is_closure_like( - Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty + Place::ty_from(local, proj_base, &self.body.local_decls, self.infcx.tcx).ty )); let captured_place = self.upvars[upvar_index.index()]; @@ -430,7 +435,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } let tcx = self.infcx.tcx; - if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind() + if let ty::Ref(_, ty, Mutability::Mut) = + the_place_err.ty(&self.body.local_decls, tcx).ty.kind() && let ty::Closure(id, _) = *ty.kind() { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index bb1aea14693e9..74a5ccd61946a 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1374,7 +1374,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { for (place_ref, proj) in place.iter_projections().rev() { // Handle (a) if proj == ProjectionElem::Deref { - match place_ref.ty(this.body(), this.infcx.tcx).ty.kind() { + match place_ref.ty(&this.body().local_decls, this.infcx.tcx).ty.kind() { // We aren't modifying a variable directly ty::Ref(_, _, hir::Mutability::Mut) => return, @@ -1875,7 +1875,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) = place_span.0.last_projection() { - let place_ty = place_base.ty(self.body(), self.infcx.tcx); + let place_ty = place_base.ty(&self.body().local_decls, self.infcx.tcx); if let ty::Array(..) = place_ty.ty.kind() { self.check_if_subslice_element_is_moved( location, @@ -1987,7 +1987,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { // assigning to `P.f` requires `P` itself // be already initialized let tcx = self.infcx.tcx; - let base_ty = place_base.ty(self.body(), tcx).ty; + let base_ty = place_base.ty(&self.body().local_decls, tcx).ty; match base_ty.kind() { ty::Adt(def, _) if def.has_dtor(tcx) => { self.check_if_path_or_subpath_is_moved( @@ -2076,7 +2076,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { // no move out from an earlier location) then this is an attempt at initialization // of the union - we should error in that case. let tcx = this.infcx.tcx; - if base.ty(this.body(), tcx).ty.is_union() { + if base.ty(&this.body().local_decls, tcx).ty.is_union() { if this.move_data.path_map[mpi].iter().any(|moi| { this.move_data.moves[*moi].source.is_predecessor_of(location, this.body) }) { @@ -2298,7 +2298,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> { Some((place_base, elem)) => { match elem { ProjectionElem::Deref => { - let base_ty = place_base.ty(self.body(), self.infcx.tcx).ty; + let base_ty = place_base.ty(&self.body().local_decls, self.infcx.tcx).ty; // Check the kind of deref to decide match base_ty.kind() { diff --git a/compiler/rustc_borrowck/src/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs index 4afb41be18f10..7bfb07f3d24a5 100644 --- a/compiler/rustc_borrowck/src/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -158,7 +158,7 @@ pub(crate) fn is_upvar_field_projection<'tcx>( match place_ref.last_projection() { Some((place_base, ProjectionElem::Field(field, _ty))) => { - let base_ty = place_base.ty(body, tcx).ty; + let base_ty = place_base.ty(&body.local_decls, tcx).ty; if (base_ty.is_closure() || base_ty.is_coroutine() || base_ty.is_coroutine_closure()) && (!by_ref || upvars[field.index()].is_by_ref()) { diff --git a/compiler/rustc_borrowck/src/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs index ce63d51682e5b..b5daa330b8aa5 100644 --- a/compiler/rustc_borrowck/src/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -38,7 +38,7 @@ impl<'tcx> Place<'tcx> { for (i, (proj_base, elem)) in self.iter_projections().enumerate() { if elem == ProjectionElem::Deref { - let ty = proj_base.ty(body, tcx).ty; + let ty = proj_base.ty(&body.local_decls, tcx).ty; match ty.kind() { ty::Ref(_, _, hir::Mutability::Not) if i == 0 => { // For references to thread-local statics, we do need diff --git a/compiler/rustc_borrowck/src/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs index 311f17f15b9ee..eed2e329322fb 100644 --- a/compiler/rustc_borrowck/src/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -199,7 +199,7 @@ fn place_components_conflict<'tcx>( // our place. This is a conflict if that is a part our // access cares about. - let base_ty = base.ty(body, tcx).ty; + let base_ty = base.ty(&body.local_decls, tcx).ty; match (elem, base_ty.kind(), access) { (_, _, Shallow(Some(ArtificialField::ArrayLength))) @@ -311,7 +311,7 @@ fn place_projection_conflict<'tcx>( debug!("place_element_conflict: DISJOINT-OR-EQ-FIELD"); Overlap::EqualOrDisjoint } else { - let ty = pi1.ty(body, tcx).ty; + let ty = pi1.ty(&body.local_decls, tcx).ty; if ty.is_union() { // Different fields of a union, we are basically stuck. debug!("place_element_conflict: STUCK-UNION"); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d8f74840eb52f..3bda96c1ad381 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -420,7 +420,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { self.super_rvalue(rvalue, location); - let rval_ty = rvalue.ty(self.body(), self.tcx()); + let rval_ty = rvalue.ty(&self.body().local_decls, self.tcx()); self.sanitize_type(rvalue, rval_ty); } @@ -630,7 +630,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { })) } ProjectionElem::Index(i) => { - let index_ty = Place::from(i).ty(self.body(), tcx).ty; + let index_ty = Place::from(i).ty(&self.body().local_decls, tcx).ty; if index_ty != tcx.types.usize { PlaceTy::from_ty(span_mirbug_and_err!(self, i, "index by non-usize {:?}", i)) } else { @@ -1218,11 +1218,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { place.as_local().map(|l| &body.local_decls[l]) ); - let place_ty = place.ty(body, tcx).ty; + let place_ty = place.ty(&body.local_decls, tcx).ty; debug!(?place_ty); let place_ty = self.normalize(place_ty, location); debug!("place_ty normalized: {:?}", place_ty); - let rv_ty = rv.ty(body, tcx); + let rv_ty = rv.ty(&body.local_decls, tcx); debug!(?rv_ty); let rv_ty = self.normalize(rv_ty, location); debug!("normalized rv_ty: {:?}", rv_ty); @@ -1274,7 +1274,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } StatementKind::AscribeUserType(box (place, projection), variance) => { - let place_ty = place.ty(body, tcx).ty; + let place_ty = place.ty(&body.local_decls, tcx).ty; if let Err(terr) = self.relate_type_and_user_type( place_ty, *variance, @@ -1341,7 +1341,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { TerminatorKind::SwitchInt { discr, .. } => { self.check_operand(discr, term_location); - let switch_ty = discr.ty(body, tcx); + let switch_ty = discr.ty(&body.local_decls, tcx); if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() { span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty); } @@ -1360,7 +1360,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_operand(&arg.node, term_location); } - let func_ty = func.ty(body, tcx); + let func_ty = func.ty(&body.local_decls, tcx); debug!("func_ty.kind: {:?}", func_ty.kind()); let sig = match func_ty.kind() { @@ -1452,16 +1452,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { TerminatorKind::Assert { cond, msg, .. } => { self.check_operand(cond, term_location); - let cond_ty = cond.ty(body, tcx); + let cond_ty = cond.ty(&body.local_decls, tcx); if cond_ty != tcx.types.bool { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } if let AssertKind::BoundsCheck { len, index } = &**msg { - if len.ty(body, tcx) != tcx.types.usize { + if len.ty(&body.local_decls, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } - if index.ty(body, tcx) != tcx.types.usize { + if index.ty(&body.local_decls, tcx) != tcx.types.usize { span_mirbug!(self, index, "bounds-check index non-usize {:?}", index) } } @@ -1472,7 +1472,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { match body.yield_ty() { None => span_mirbug!(self, term, "yield in non-coroutine"), Some(ty) => { - let value_ty = value.ty(body, tcx); + let value_ty = value.ty(&body.local_decls, tcx); if let Err(terr) = self.sub_types( value_ty, ty, @@ -1494,7 +1494,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { match body.resume_ty() { None => span_mirbug!(self, term, "yield in non-coroutine"), Some(ty) => { - let resume_ty = resume_arg.ty(body, tcx); + let resume_ty = resume_arg.ty(&body.local_decls, tcx); if let Err(terr) = self.sub_types( ty, resume_ty.ty, @@ -1528,7 +1528,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let tcx = self.tcx(); match target { Some(_) => { - let dest_ty = destination.ty(body, tcx).ty; + let dest_ty = destination.ty(&body.local_decls, tcx).ty; let dest_ty = self.normalize(dest_ty, term_location); let category = match destination.as_local() { Some(RETURN_PLACE) => { @@ -1604,7 +1604,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } - let func_ty = func.ty(body, self.infcx.tcx); + let func_ty = func.ty(&body.local_decls, self.infcx.tcx); if let ty::FnDef(def_id, _) = *func_ty.kind() { // Some of the SIMD intrinsics are special: they need a particular argument to be a constant. // (Eventually this should use const-generics, but those are not up for the task yet: @@ -1628,7 +1628,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { debug!(?func_ty); for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() { - let op_arg_ty = op_arg.node.ty(body, self.tcx()); + let op_arg_ty = op_arg.node.ty(&body.local_decls, self.tcx()); let op_arg_ty = self.normalize(op_arg_ty, term_location); let category = if call_source.from_hir_call() { @@ -1907,7 +1907,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Rvalue::Repeat(operand, len) => { self.check_operand(operand, location); - let array_ty = rvalue.ty(body.local_decls(), tcx); + let array_ty = rvalue.ty(&body.local_decls, tcx); self.prove_predicate( ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(array_ty.into())), Locations::Single(location), @@ -1925,7 +1925,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. - let ty = place.ty(body, tcx).ty; + let ty = place.ty(&body.local_decls, tcx).ty; let trait_ref = ty::TraitRef::new( tcx, tcx.require_lang_item(LangItem::Copy, Some(span)), @@ -1978,7 +1978,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { match cast_kind { CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => { - let fn_sig = op.ty(body, tcx).fn_sig(tcx); + let fn_sig = op.ty(&body.local_decls, tcx).fn_sig(tcx); // The type that we see in the fcx is like // `foo::<'a, 'b>`, where `foo` is the path to a @@ -2007,7 +2007,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(safety)) => { - let sig = match op.ty(body, tcx).kind() { + let sig = match op.ty(&body.local_decls, tcx).kind() { ty::Closure(_, args) => args.as_closure().sig(), _ => bug!(), }; @@ -2032,7 +2032,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer) => { - let fn_sig = op.ty(body, tcx).fn_sig(tcx); + let fn_sig = op.ty(&body.local_decls, tcx).fn_sig(tcx); // The type that we see in the fcx is like // `foo::<'a, 'b>`, where `foo` is the path to a @@ -2065,7 +2065,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let trait_ref = ty::TraitRef::new( tcx, tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)), - [op.ty(body, tcx), ty], + [op.ty(&body.local_decls, tcx), ty], ); self.prove_trait_ref( @@ -2092,7 +2092,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { _ => panic!("Invalid dyn* cast_ty"), }; - let self_ty = op.ty(body, tcx); + let self_ty = op.ty(&body.local_decls, tcx); self.prove_predicates( existential_predicates @@ -2115,7 +2115,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerCoercion(PointerCoercion::MutToConstPointer) => { - let ty::RawPtr(ty_from, hir::Mutability::Mut) = op.ty(body, tcx).kind() + let ty::RawPtr(ty_from, hir::Mutability::Mut) = + op.ty(&body.local_decls, tcx).kind() else { span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,); return; @@ -2142,7 +2143,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerCoercion(PointerCoercion::ArrayToPointer) => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let opt_ty_elem_mut = match ty_from.kind() { ty::RawPtr(array_ty, array_mut) => match array_ty.kind() { @@ -2204,7 +2205,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerExposeProvenance => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2222,7 +2223,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } CastKind::PointerWithExposedProvenance => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2239,7 +2240,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::IntToInt => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2256,7 +2257,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::IntToFloat => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2273,7 +2274,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::FloatToInt => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2290,7 +2291,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::FloatToFloat => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2307,7 +2308,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::FnPtrToPtr => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2324,7 +2325,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } CastKind::PtrToPtr => { - let ty_from = op.ty(body, tcx); + let ty_from = op.ty(&body.local_decls, tcx); let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); match (cast_ty_from, cast_ty_to) { @@ -2408,11 +2409,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_operand(left, location); self.check_operand(right, location); - let ty_left = left.ty(body, tcx); + let ty_left = left.ty(&body.local_decls, tcx); match ty_left.kind() { // Types with regions are comparable if they have a common super-type. ty::RawPtr(_, _) | ty::FnPtr(..) => { - let ty_right = right.ty(body, tcx); + let ty_right = right.ty(&body.local_decls, tcx); let common_ty = self.infcx.next_ty_var(body.source_info(location).span); self.sub_types( ty_left, @@ -2442,7 +2443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // For types with no regions we can just check that the // both operands have the same type. ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) - if ty_left == right.ty(body, tcx) => {} + if ty_left == right.ty(&body.local_decls, tcx) => {} // Other types are compared by trait methods, not by // `Rvalue::BinaryOp`. _ => span_mirbug!( @@ -2450,7 +2451,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { rvalue, "unexpected comparison types {:?} and {:?}", ty_left, - right.ty(body, tcx) + right.ty(&body.local_decls, tcx) ), } } @@ -2542,7 +2543,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { continue; } }; - let operand_ty = operand.ty(body, tcx); + let operand_ty = operand.ty(&body.local_decls, tcx); let operand_ty = self.normalize(operand_ty, location); if let Err(terr) = self.sub_types( @@ -2626,7 +2627,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { match elem { ProjectionElem::Deref => { - let base_ty = base.ty(body, tcx).ty; + let base_ty = base.ty(&body.local_decls, tcx).ty; debug!("add_reborrow_constraint - base_ty = {:?}", base_ty); match base_ty.kind() { diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 24cf3f061a567..524d54e07e85f 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -432,7 +432,9 @@ pub(crate) fn codegen_terminator_call<'tcx>( let extra_args = &args[fn_sig.inputs().skip_binder().len()..]; let extra_args = fx.tcx.mk_type_list_from_iter( - extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))), + extra_args + .iter() + .map(|op_arg| fx.monomorphize(op_arg.node.ty(&fx.mir.local_decls, fx.tcx))), ); let fn_abi = if let Some(instance) = instance { RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args) diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs index ca910dccb0d06..489739dae38e2 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs @@ -182,7 +182,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( // Make sure this is actually an array, since typeck only checks the length-suffixed // version of this intrinsic. - let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx)); + let idx_ty = fx.monomorphize(idx.node.ty(&fx.mir.local_decls, fx.tcx)); let n: u16 = match idx_ty.kind() { ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len .try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all()) diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 386e1f91e7f0c..e74965291d1e3 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -109,7 +109,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, ) ); if is_consume { - let base_ty = place_base.ty(self.fx.mir, cx.tcx()); + let base_ty = place_base.ty(&self.fx.mir.local_decls, cx.tcx()); let base_ty = self.fx.monomorphize(base_ty); // ZSTs don't require any actual memory access. diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 817e2ca72ec12..f6efe85fea585 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -504,7 +504,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { unwind: mir::UnwindAction, mergeable_succ: bool, ) -> MergingSucc { - let ty = location.ty(self.mir, bx.tcx()).ty; + let ty = location.ty(&self.mir.local_decls, bx.tcx()).ty; let ty = self.monomorphize(ty); let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); @@ -869,7 +869,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let extra_args = &args[sig.inputs().skip_binder().len()..]; let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| { - let op_ty = op_arg.node.ty(self.mir, bx.tcx()); + let op_ty = op_arg.node.ty(&self.mir.local_decls, bx.tcx()); self.monomorphize(op_ty) })); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 0fad4d169edd5..2cd9d2b9d0dcf 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -538,7 +538,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> { let tcx = self.cx.tcx(); - let place_ty = place_ref.ty(self.mir, tcx); + let place_ty = place_ref.ty(&self.mir.local_decls, tcx); self.monomorphize(place_ty.ty) } } diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index d94c6f8ddcec3..3f11d05f36fec 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -678,7 +678,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::Rvalue::Discriminant(ref place) => { - let discr_ty = rvalue.ty(self.mir, bx.tcx()); + let discr_ty = rvalue.ty(&self.mir.local_decls, bx.tcx()); let discr_ty = self.monomorphize(discr_ty); let discr = self.codegen_place(bx, place.as_ref()).codegen_get_discr(bx, discr_ty); OperandRef { @@ -746,7 +746,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Use(ref operand) => self.codegen_operand(bx, operand), mir::Rvalue::Repeat(..) => bug!("{rvalue:?} in codegen_rvalue_operand"), mir::Rvalue::Aggregate(_, ref fields) => { - let ty = rvalue.ty(self.mir, self.cx.tcx()); + let ty = rvalue.ty(&self.mir.local_decls, self.cx.tcx()); let ty = self.monomorphize(ty); let layout = self.cx.layout_of(ty); @@ -1053,7 +1053,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool { match *rvalue { mir::Rvalue::Cast(mir::CastKind::Transmute, ref operand, cast_ty) => { - let operand_ty = operand.ty(self.mir, self.cx.tcx()); + let operand_ty = operand.ty(&self.mir.local_decls, self.cx.tcx()); let cast_layout = self.cx.layout_of(self.monomorphize(cast_ty)); let operand_layout = self.cx.layout_of(self.monomorphize(operand_ty)); @@ -1114,7 +1114,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::AggregateKind::Coroutine(..) | mir::AggregateKind::CoroutineClosure(..) => false, }; allowed_kind && { - let ty = rvalue.ty(self.mir, self.cx.tcx()); + let ty = rvalue.ty(&self.mir.local_decls, self.cx.tcx()); let ty = self.monomorphize(ty); let layout = self.cx.spanned_layout_of(ty, span); !self.cx.is_backend_ref(layout) diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 6a086a3a7e5a0..7a99cd9c98fc7 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -588,7 +588,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { Rvalue::ShallowInitBox(_, _) => {} Rvalue::UnaryOp(_, operand) => { - let ty = operand.ty(self.body, self.tcx); + let ty = operand.ty(&self.body.local_decls, self.tcx); if is_int_bool_float_or_char(ty) { // Int, bool, float, and char operations are fine. } else { @@ -597,8 +597,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } Rvalue::BinaryOp(op, box (lhs, rhs)) => { - let lhs_ty = lhs.ty(self.body, self.tcx); - let rhs_ty = rhs.ty(self.body, self.tcx); + let lhs_ty = lhs.ty(&self.body.local_decls, self.tcx); + let rhs_ty = rhs.ty(&self.body.local_decls, self.tcx); if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) { // Int, bool, float, and char operations are fine. @@ -652,7 +652,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { match elem { ProjectionElem::Deref => { - let base_ty = place_ref.ty(self.body, self.tcx).ty; + let base_ty = place_ref.ty(&self.body.local_decls, self.tcx).ty; if base_ty.is_unsafe_ptr() { if place_ref.projection.is_empty() { let decl = &self.body.local_decls[place_ref.local]; @@ -731,7 +731,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { let ConstCx { tcx, body, param_env, .. } = *self.ccx; let caller = self.def_id(); - let fn_ty = func.ty(body, tcx); + let fn_ty = func.ty(&body.local_decls, tcx); let (mut callee, mut fn_args) = match *fn_ty.kind() { ty::FnDef(def_id, fn_args) => (def_id, fn_args), @@ -923,7 +923,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } let mut err_span = self.span; - let ty_of_dropped_place = dropped_place.ty(self.body, self.tcx).ty; + let ty_of_dropped_place = dropped_place.ty(&self.body.local_decls, self.tcx).ty; let ty_needs_non_const_drop = qualifs::NeedsNonConstDrop::in_any_value_of_ty(self.ccx, ty_of_dropped_place); @@ -1006,7 +1006,7 @@ fn place_as_reborrow<'tcx>( // Ensure the type being derefed is a reference and not a raw pointer. // This is sufficient to prevent an access to a `static mut` from being marked as a // reborrow, even if the check above were to disappear. - let inner_ty = place_base.ty(body, tcx).ty; + let inner_ty = place_base.ty(&body.local_decls, tcx).ty; if let ty::Ref(..) = inner_ty.kind() { return Some(place_base); diff --git a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs index c4f06e5af0be5..d1ccebc78863a 100644 --- a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs @@ -83,7 +83,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> { match &terminator.kind { mir::TerminatorKind::Drop { place: dropped_place, .. } => { - let dropped_ty = dropped_place.ty(self.body, self.tcx).ty; + let dropped_ty = dropped_place.ty(&self.body.local_decls, self.tcx).ty; if !NeedsNonConstDrop::in_any_value_of_ty(self.ccx, dropped_ty) { // Instead of throwing a bug, we just return here. This is because we have to diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index c566dc7fa844d..7205384eece45 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -272,7 +272,7 @@ where { match rvalue { Rvalue::ThreadLocalRef(_) | Rvalue::NullaryOp(..) => { - Q::in_any_value_of_ty(cx, rvalue.ty(cx.body, cx.tcx)) + Q::in_any_value_of_ty(cx, rvalue.ty(&cx.body.local_decls, cx.tcx)) } Rvalue::Discriminant(place) | Rvalue::Len(place) => { @@ -294,7 +294,7 @@ where Rvalue::Ref(_, _, place) | Rvalue::RawPtr(_, place) => { // Special-case reborrows to be more like a copy of the reference. if let Some((place_base, ProjectionElem::Deref)) = place.as_ref().last_projection() { - let base_ty = place_base.ty(cx.body, cx.tcx).ty; + let base_ty = place_base.ty(&cx.body.local_decls, cx.tcx).ty; if let ty::Ref(..) = base_ty.kind() { return in_place::(cx, in_local, place_base); } @@ -312,7 +312,9 @@ where return true; } // Don't do any value-based reasoning for unions. - if def.is_union() && Q::in_any_value_of_ty(cx, rvalue.ty(cx.body, cx.tcx)) { + if def.is_union() + && Q::in_any_value_of_ty(cx, rvalue.ty(&cx.body.local_decls, cx.tcx)) + { return true; } } @@ -344,7 +346,7 @@ where | ProjectionElem::Index(_) => {} } - let base_ty = place_base.ty(cx.body, cx.tcx); + let base_ty = place_base.ty(&cx.body.local_decls, cx.tcx); let proj_ty = base_ty.projection_ty(cx.tcx, elem).ty; if !Q::in_any_value_of_ty(cx, proj_ty) { return false; diff --git a/compiler/rustc_const_eval/src/check_consts/resolver.rs b/compiler/rustc_const_eval/src/check_consts/resolver.rs index 681184f7fbcde..f3b30aa7fff1e 100644 --- a/compiler/rustc_const_eval/src/check_consts/resolver.rs +++ b/compiler/rustc_const_eval/src/check_consts/resolver.rs @@ -53,7 +53,7 @@ where if !value { for (base, _elem) in place.iter_projections() { - let base_ty = base.ty(self.ccx.body, self.ccx.tcx); + let base_ty = base.ty(&self.ccx.body.local_decls, self.ccx.tcx); if base_ty.ty.is_union() && Q::in_any_value_of_ty(self.ccx, base_ty.ty) { value = true; break; @@ -86,7 +86,7 @@ where return_places.for_each(|place| { // We cannot reason about another function's internals, so use conservative type-based // qualification for the result of a function call. - let return_ty = place.ty(self.ccx.body, self.ccx.tcx).ty; + let return_ty = place.ty(&self.ccx.body.local_decls, self.ccx.tcx).ty; let qualif = Q::in_any_value_of_ty(self.ccx, return_ty); if !place.is_indirect() { @@ -120,7 +120,10 @@ where /// /// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134 fn shared_borrow_allows_mutation(&self, place: mir::Place<'tcx>) -> bool { - !place.ty(self.ccx.body, self.ccx.tcx).ty.is_freeze(self.ccx.tcx, self.ccx.param_env) + !place + .ty(&self.ccx.body.local_decls, self.ccx.tcx) + .ty + .is_freeze(self.ccx.tcx, self.ccx.param_env) } } @@ -172,7 +175,7 @@ where match rvalue { mir::Rvalue::RawPtr(_mt, borrowed_place) => { if !borrowed_place.is_indirect() && self.address_of_allows_mutation() { - let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty; + let place_ty = borrowed_place.ty(&self.ccx.body.local_decls, self.ccx.tcx).ty; if Q::in_any_value_of_ty(self.ccx, place_ty) { self.state.qualif.insert(borrowed_place.local); self.state.borrow.insert(borrowed_place.local); @@ -183,7 +186,7 @@ where mir::Rvalue::Ref(_, kind, borrowed_place) => { if !borrowed_place.is_indirect() && self.ref_allows_mutation(*kind, *borrowed_place) { - let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty; + let place_ty = borrowed_place.ty(&self.ccx.body.local_decls, self.ccx.tcx).ty; if Q::in_any_value_of_ty(self.ccx, place_ty) { self.state.qualif.insert(borrowed_place.local); self.state.borrow.insert(borrowed_place.local); diff --git a/compiler/rustc_const_eval/src/util/alignment.rs b/compiler/rustc_const_eval/src/util/alignment.rs index 5ad55968398eb..b2a8cf0d2e0f4 100644 --- a/compiler/rustc_const_eval/src/util/alignment.rs +++ b/compiler/rustc_const_eval/src/util/alignment.rs @@ -6,15 +6,12 @@ use tracing::debug; /// Returns `true` if this place is allowed to be less aligned /// than its containing struct (because it is within a packed /// struct). -pub fn is_disaligned<'tcx, L>( +pub fn is_disaligned<'tcx>( tcx: TyCtxt<'tcx>, - local_decls: &L, + local_decls: &LocalDecls<'tcx>, param_env: ty::ParamEnv<'tcx>, place: Place<'tcx>, -) -> bool -where - L: HasLocalDecls<'tcx>, -{ +) -> bool { debug!("is_disaligned({:?})", place); let Some(pack) = is_within_packed(tcx, local_decls, place) else { debug!("is_disaligned({:?}) - not within packed", place); @@ -50,14 +47,11 @@ where } } -pub fn is_within_packed<'tcx, L>( +pub fn is_within_packed<'tcx>( tcx: TyCtxt<'tcx>, - local_decls: &L, + local_decls: &LocalDecls<'tcx>, place: Place<'tcx>, -) -> Option -where - L: HasLocalDecls<'tcx>, -{ +) -> Option { place .iter_projections() .rev() diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 5b2aac781ebad..1151e648948f5 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -81,31 +81,6 @@ pub use self::pretty::{ /// Types for locals pub type LocalDecls<'tcx> = IndexSlice>; -pub trait HasLocalDecls<'tcx> { - fn local_decls(&self) -> &LocalDecls<'tcx>; -} - -impl<'tcx> HasLocalDecls<'tcx> for IndexVec> { - #[inline] - fn local_decls(&self) -> &LocalDecls<'tcx> { - self - } -} - -impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { - #[inline] - fn local_decls(&self) -> &LocalDecls<'tcx> { - self - } -} - -impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> { - #[inline] - fn local_decls(&self) -> &LocalDecls<'tcx> { - &self.local_decls - } -} - thread_local! { static PASS_NAMES: RefCell> = { RefCell::new(FxHashMap::default()) diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 8d57d0d865469..17c9abd95e3f4 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -117,35 +117,24 @@ impl<'tcx> PlaceTy<'tcx> { } impl<'tcx> Place<'tcx> { - pub fn ty_from( + pub fn ty_from( local: Local, projection: &[PlaceElem<'tcx>], - local_decls: &D, + local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'tcx>, - ) -> PlaceTy<'tcx> - where - D: HasLocalDecls<'tcx>, - { - projection - .iter() - .fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, &elem| { - place_ty.projection_ty(tcx, elem) - }) + ) -> PlaceTy<'tcx> { + projection.iter().fold(PlaceTy::from_ty(local_decls[local].ty), |place_ty, &elem| { + place_ty.projection_ty(tcx, elem) + }) } - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> - where - D: HasLocalDecls<'tcx>, - { + pub fn ty(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> { Place::ty_from(self.local, self.projection, local_decls, tcx) } } impl<'tcx> PlaceRef<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> - where - D: HasLocalDecls<'tcx>, - { + pub fn ty(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> { Place::ty_from(self.local, self.projection, local_decls, tcx) } } @@ -156,10 +145,7 @@ pub enum RvalueInitializationState { } impl<'tcx> Rvalue<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> - where - D: HasLocalDecls<'tcx>, - { + pub fn ty(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), Rvalue::Repeat(ref operand, count) => { @@ -220,24 +206,16 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> - where - D: HasLocalDecls<'tcx>, - { + pub fn ty(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self { &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty, Operand::Constant(c) => c.const_.ty(), } } - pub fn span(&self, local_decls: &D) -> Span - where - D: HasLocalDecls<'tcx>, - { + pub fn span(&self, local_decls: &LocalDecls<'tcx>) -> Span { match self { - &Operand::Copy(ref l) | &Operand::Move(ref l) => { - local_decls.local_decls()[l.local].source_info.span - } + &Operand::Copy(ref l) | &Operand::Move(ref l) => local_decls[l.local].source_info.span, Operand::Constant(c) => c.span, } } diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index 0b13ceb574d04..61cdae8b3d4c9 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -258,7 +258,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { ), ExprKind::Cast { source } => { let source = self.parse_operand(*source)?; - let source_ty = source.ty(self.body.local_decls(), self.tcx); + let source_ty = source.ty(&self.body.local_decls, self.tcx); let cast_kind = mir_cast_kind(source_ty, expr.ty); Ok(Rvalue::Cast(cast_kind, source, expr.ty)) }, diff --git a/compiler/rustc_mir_build/src/lints.rs b/compiler/rustc_mir_build/src/lints.rs index 80e91811b1c5f..ec8e26e1c76a0 100644 --- a/compiler/rustc_mir_build/src/lints.rs +++ b/compiler/rustc_mir_build/src/lints.rs @@ -136,7 +136,7 @@ impl<'tcx> TerminatorClassifier<'tcx> for CallRecursion<'tcx> { let caller = body.source.def_id(); let param_env = tcx.param_env(caller); - let func_ty = func.ty(body, tcx); + let func_ty = func.ty(&body.local_decls, tcx); if let ty::FnDef(callee, args) = *func_ty.kind() { let Ok(normalized_args) = tcx.try_normalize_erasing_regions(param_env, args) else { return false; @@ -171,7 +171,7 @@ impl<'tcx> TerminatorClassifier<'tcx> for RecursiveDrop<'tcx> { ) -> bool { let TerminatorKind::Drop { place, .. } = &terminator.kind else { return false }; - let dropped_ty = place.ty(body, tcx).ty; + let dropped_ty = place.ty(&body.local_decls, tcx).ty; dropped_ty == self.drop_for } } diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index d7e738b8829e0..a27d2a54362c5 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -199,7 +199,7 @@ where { #[instrument(level = "trace", skip(self), ret)] fn place_ty(&self, place: Place<'tcx>) -> Ty<'tcx> { - place.ty(self.elaborator.body(), self.tcx()).ty + place.ty(&self.elaborator.body().local_decls, self.tcx()).ty } fn tcx(&self) -> TyCtxt<'tcx> { diff --git a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs index e8e78fb8a89ee..ac86254e5b188 100644 --- a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs @@ -26,7 +26,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeBorrowedLocals { fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain { // bottom = unborrowed - BitSet::new_empty(body.local_decls().len()) + BitSet::new_empty(body.local_decls.len()) } fn initialize_start_block(&self, _: &Body<'tcx>, _: &mut Self::Domain) { diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index ddfd0739358d1..fea59361f2cef 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -760,7 +760,7 @@ fn switch_on_enum_discriminant<'mir, 'tcx>( mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))) if *lhs == switch_on => { - match discriminated.ty(body, tcx).ty.kind() { + match discriminated.ty(&body.local_decls, tcx).ty.kind() { ty::Adt(def, _) => return Some((*discriminated, *def)), // `Rvalue::Discriminant` is also used to get the active yield point for a diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index 14390723ba4b6..041d1a76e12bf 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -133,7 +133,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> { for (place_ref, elem) in data.rev_lookup.un_derefer.iter_projections(place.as_ref()) { let body = self.builder.body; let tcx = self.builder.tcx; - let place_ty = place_ref.ty(body, tcx).ty; + let place_ty = place_ref.ty(&body.local_decls, tcx).ty; if place_ty.references_error() { return MovePathResult::Error; } @@ -562,7 +562,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> { return; } }; - let base_ty = base_place.ty(self.builder.body, self.builder.tcx).ty; + let base_ty = base_place.ty(&self.builder.body.local_decls, self.builder.tcx).ty; let len: u64 = match base_ty.kind() { ty::Array(_, size) => { size.eval_target_usize(self.builder.tcx, self.builder.param_env) @@ -604,7 +604,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> { // Check if we are assigning into a field of a union, if so, lookup the place // of the union so it is marked as initialized again. if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() { - if place_base.ty(self.builder.body, self.builder.tcx).ty.is_union() { + if place_base.ty(&self.builder.body.local_decls, self.builder.tcx).ty.is_union() { place = place_base; } } diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index edb6bc4fbea2f..870493f7b5dda 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -61,7 +61,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { let call_can_unwind = match &terminator.kind { TerminatorKind::Call { func, .. } => { - let ty = func.ty(body, tcx); + let ty = func.ty(&body.local_decls, tcx); let sig = ty.fn_sig(tcx); let fn_def_id = match ty.kind() { ty::FnPtr(..) => None, diff --git a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs index cd850e2d73189..bdb810148064b 100644 --- a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs +++ b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs @@ -59,7 +59,7 @@ fn add_moves_for_packed_drops_patch<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) match terminator.kind { TerminatorKind::Drop { place, .. } - if util::is_disaligned(tcx, body, param_env, place) => + if util::is_disaligned(tcx, &body.local_decls, param_env, place) => { add_move_for_packed_drop(tcx, body, &mut patch, terminator, loc, data.is_cleanup); } @@ -84,7 +84,7 @@ fn add_move_for_packed_drop<'tcx>( }; let source_info = terminator.source_info; - let ty = place.ty(body, tcx).ty; + let ty = place.ty(&body.local_decls, tcx).ty; let temp = patch.new_temp(ty, terminator.source_info.span); let storage_dead_block = patch.new_block(BasicBlockData { diff --git a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs index 04204c68f7b76..874b87afd79a1 100644 --- a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs +++ b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs @@ -1,4 +1,3 @@ -use rustc_index::IndexVec; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; @@ -9,7 +8,7 @@ pub struct Subtyper; pub struct SubTypeChecker<'a, 'tcx> { tcx: TyCtxt<'tcx>, patcher: MirPatch<'tcx>, - local_decls: &'a IndexVec>, + local_decls: &'a LocalDecls<'tcx>, } impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> { diff --git a/compiler/rustc_mir_transform/src/check_packed_ref.rs b/compiler/rustc_mir_transform/src/check_packed_ref.rs index 9902002580aed..e21f26bdb0310 100644 --- a/compiler/rustc_mir_transform/src/check_packed_ref.rs +++ b/compiler/rustc_mir_transform/src/check_packed_ref.rs @@ -38,7 +38,7 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> { fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) { if context.is_borrow() { - if util::is_disaligned(self.tcx, self.body, self.param_env, *place) { + if util::is_disaligned(self.tcx, &self.body.local_decls, self.param_env, *place) { let def_id = self.body.source.instance.def_id(); if let Some(impl_def_id) = self.tcx.impl_of_method(def_id) && self.tcx.is_builtin_derived(impl_def_id) diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 703339bf5bca8..6274c7421f0f0 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -644,7 +644,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { match &bb_data.terminator().kind { TerminatorKind::Call { func, .. } => { - let func_ty = func.ty(body, tcx); + let func_ty = func.ty(&body.local_decls, tcx); if let ty::FnDef(def_id, _) = *func_ty.kind() { if def_id == get_context_def_id { let local = eliminate_get_context_call(&mut body[bb]); diff --git a/compiler/rustc_mir_transform/src/cost_checker.rs b/compiler/rustc_mir_transform/src/cost_checker.rs index a1c1422912ee3..ea42dc0c0d1fc 100644 --- a/compiler/rustc_mir_transform/src/cost_checker.rs +++ b/compiler/rustc_mir_transform/src/cost_checker.rs @@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { match &terminator.kind { TerminatorKind::Drop { place, unwind, .. } => { // If the place doesn't actually need dropping, treat it like a regular goto. - let ty = self.instantiate_ty(place.ty(self.callee_body, self.tcx).ty); + let ty = self.instantiate_ty(place.ty(&self.callee_body.local_decls, self.tcx).ty); if ty.needs_drop(self.tcx, self.param_env) { self.penalty += CALL_PENALTY; if let UnwindAction::Cleanup(_) = unwind { diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index 50aaed090f6b8..0cbc0a12d69bc 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -109,7 +109,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { let tcx = self.tcx; match terminator.kind { TerminatorKind::Drop { ref place, unwind, .. } => { - let ty = place.ty(self.callee_body, tcx).ty; + let ty = place.ty(&self.callee_body.local_decls, tcx).ty; if !ty.is_trivially_pure_clone_copy() { self.calls += 1; if let UnwindAction::Cleanup(_) = unwind { diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs index f473073083af4..3469d62abc993 100644 --- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs +++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs @@ -65,7 +65,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // the move may be codegened as a pointer to that field. // Using that disaligned pointer may trigger UB in the callee, // so do nothing. - && is_within_packed(tcx, body, place).is_none() + && is_within_packed(tcx, &body.local_decls, place).is_none() { call_operands_to_move.push((bb, index)); } diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index 0e2fccc85dacd..eec378e308a2a 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -1,4 +1,3 @@ -use rustc_index::IndexVec; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::NonUseContext::VarDebugInfo; use rustc_middle::mir::visit::{MutVisitor, PlaceContext}; @@ -10,7 +9,7 @@ pub struct Derefer; pub struct DerefChecker<'a, 'tcx> { tcx: TyCtxt<'tcx>, patcher: MirPatch<'tcx>, - local_decls: &'a IndexVec>, + local_decls: &'a LocalDecls<'tcx>, } impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> { diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index ed924761892c7..6f1fc8608263c 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -137,8 +137,8 @@ use rustc_index::interval::SparseIntervalMatrix; use rustc_middle::bug; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::{ - dump_mir, traversal, Body, HasLocalDecls, InlineAsmOperand, Local, LocalKind, Location, - Operand, PassWhere, Place, Rvalue, Statement, StatementKind, TerminatorKind, + dump_mir, traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, PassWhere, + Place, Rvalue, Statement, StatementKind, TerminatorKind, }; use rustc_middle::ty::TyCtxt; use rustc_mir_dataflow::impls::MaybeLiveLocals; @@ -787,15 +787,15 @@ impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> { // As described at the top of this file, we do not touch locals which have // different types. - let src_ty = self.body.local_decls()[src].ty; - let dest_ty = self.body.local_decls()[dest].ty; + let src_ty = self.body.local_decls[src].ty; + let dest_ty = self.body.local_decls[dest].ty; if src_ty != dest_ty { // FIXME(#112651): This can be removed afterwards. Also update the module description. trace!("skipped `{src:?} = {dest:?}` due to subtyping: {src_ty} != {dest_ty}"); return; } - // Also, we need to make sure that MIR actually allows the `src` to be removed + // Also.local_decls, we need to make sure that MIR actually allows the `src` to be removed if is_local_required(src, self.body) { return; } diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 49e41c35f1f24..578cc82cda761 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -126,7 +126,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch { Operand::Copy(x) => Operand::Copy(*x), Operand::Constant(x) => Operand::Constant(x.clone()), }; - let parent_ty = parent_op.ty(body.local_decls(), tcx); + let parent_ty = parent_op.ty(&body.local_decls, tcx); let statements_before = bbs[parent].statements.len(); let parent_end = Location { block: parent, statement_index: statements_before }; @@ -233,7 +233,7 @@ fn evaluate_candidate<'tcx>( else { return None; }; - let parent_ty = parent_discr.ty(body.local_decls(), tcx); + let parent_ty = parent_discr.ty(&body.local_decls, tcx); if !bbs[targets.otherwise()].is_empty_unreachable() { // Someone could write code like this: // ```rust @@ -275,7 +275,7 @@ fn evaluate_candidate<'tcx>( else { return None; }; - let child_ty = child_discr.ty(body.local_decls(), tcx); + let child_ty = child_discr.ty(&body.local_decls, tcx); if child_ty != parent_ty { return None; } diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index 9a2cc057232f3..6906bc3f87426 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -47,7 +47,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool { let Some(terminator) = &block.terminator else { continue }; let TerminatorKind::Call { func, .. } = &terminator.kind else { continue }; - let ty = func.ty(body, tcx); + let ty = func.ty(&body.local_decls, tcx); let sig = ty.fn_sig(tcx); // Rust calls cannot themselves create foreign unwinds. diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index b7873e73c18c7..5fede53b77bc8 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -41,11 +41,11 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> { } = &terminator.kind { let source_info = *self.body.source_info(location); - let func_ty = func.ty(self.body, self.tcx); + let func_ty = func.ty(&self.body.local_decls, self.tcx); if let ty::FnDef(def_id, args_ref) = *func_ty.kind() { // Handle calls to `transmute` if self.tcx.is_diagnostic_item(sym::transmute, def_id) { - let arg_ty = args[0].node.ty(self.body, self.tcx); + let arg_ty = args[0].node.ty(&self.body.local_decls, self.tcx); for inner_ty in arg_ty.walk().filter_map(|arg| arg.as_type()) { if let Some((fn_id, fn_args)) = FunctionItemRefChecker::is_fn_ref(inner_ty) { diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 61fc5fc881606..0fd2758c82dd9 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -394,7 +394,7 @@ impl<'tcx> Inliner<'tcx> { // FIXME(explicit_tail_calls): figure out if we can inline tail calls if let TerminatorKind::Call { ref func, fn_span, .. } = terminator.kind { - let func_ty = func.ty(caller_body, self.tcx); + let func_ty = func.ty(&caller_body.local_decls, self.tcx); if let ty::FnDef(def_id, args) = *func_ty.kind() { // To resolve an instance its args have to be fully normalized. let args = self.tcx.try_normalize_erasing_regions(self.param_env, args).ok()?; @@ -550,7 +550,7 @@ impl<'tcx> Inliner<'tcx> { // If the place doesn't actually need dropping, treat it like a regular goto. let ty = callsite.callee.instantiate_mir( self.tcx, - ty::EarlyBinder::bind(&place.ty(callee_body, tcx).ty), + ty::EarlyBinder::bind(&place.ty(&callee_body.local_decls, tcx).ty), ); if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind @@ -636,7 +636,7 @@ impl<'tcx> Inliner<'tcx> { BorrowKind::Mut { kind: MutBorrowKind::Default }, destination, ); - let dest_ty = dest.ty(caller_body, self.tcx); + let dest_ty = dest.ty(&caller_body.local_decls, self.tcx); let temp = Place::from(self.new_call_temp(caller_body, &callsite, dest_ty, return_block)); caller_body[callsite.block].statements.push(Statement { @@ -658,7 +658,7 @@ impl<'tcx> Inliner<'tcx> { self.new_call_temp( caller_body, &callsite, - destination.ty(caller_body, self.tcx).ty, + destination.ty(&caller_body.local_decls, self.tcx).ty, return_block, ), ) @@ -760,7 +760,7 @@ impl<'tcx> Inliner<'tcx> { // the actually used items. By doing this we can entirely avoid visiting the callee! // We need to reconstruct the `required_item` for the callee so that we can find and // remove it. - let callee_item = MentionedItem::Fn(func.ty(caller_body, self.tcx)); + let callee_item = MentionedItem::Fn(func.ty(&caller_body.local_decls, self.tcx)); let caller_mentioned_items = caller_body.mentioned_items.as_mut().unwrap(); if let Some(idx) = caller_mentioned_items.iter().position(|item| item.node == callee_item) { // We found the callee, so remove it and add its items instead. @@ -824,7 +824,7 @@ impl<'tcx> Inliner<'tcx> { assert!(args.next().is_none()); let tuple = Place::from(tuple); - let ty::Tuple(tuple_tys) = tuple.ty(caller_body, tcx).ty.kind() else { + let ty::Tuple(tuple_tys) = tuple.ty(&caller_body.local_decls, tcx).ty.kind() else { bug!("Closure arguments are not passed as a tuple"); }; @@ -868,7 +868,7 @@ impl<'tcx> Inliner<'tcx> { // Otherwise, create a temporary for the argument. trace!("creating temp for argument {:?}", arg); - let arg_ty = arg.ty(caller_body, self.tcx); + let arg_ty = arg.ty(&caller_body.local_decls, self.tcx); let local = self.new_call_temp(caller_body, callsite, arg_ty, return_block); caller_body[callsite.block].statements.push(Statement { source_info: callsite.source_info, diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 96c52845a4a39..aa38e14690214 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -200,7 +200,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { let discr = discr.place()?; debug!(?discr, ?bb); - let discr_ty = discr.ty(self.body, self.tcx).ty; + let discr_ty = discr.ty(&self.body.local_decls, self.tcx).ty; let discr_layout = self.ecx.layout_of(discr_ty).ok()?; let discr = self.map.find(discr.as_ref())?; @@ -467,7 +467,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { } // If we expect `lhs ?= A`, we have an opportunity if we assume `constant == A`. Rvalue::Aggregate(box ref kind, ref operands) => { - let agg_ty = lhs_place.ty(self.body, self.tcx).ty; + let agg_ty = lhs_place.ty(&self.body.local_decls, self.tcx).ty; let lhs = match kind { // Do not support unions. AggregateKind::Adt(.., Some(_)) => return None, @@ -551,7 +551,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { // we have an opportunity if `variant_index ?= A`. StatementKind::SetDiscriminant { box place, variant_index } => { let discr_target = self.map.find_discr(place.as_ref())?; - let enum_ty = place.ty(self.body, self.tcx).ty; + let enum_ty = place.ty(&self.body.local_decls, self.tcx).ty; // `SetDiscriminant` may be a no-op if the assigned variant is the untagged variant // of a niche encoding. If we cannot ensure that we write to the discriminant, do // nothing. @@ -643,7 +643,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> { debug_assert_eq!(self.body.basic_blocks.predecessors()[target_bb].len(), 1); let discr = discr.place()?; - let discr_ty = discr.ty(self.body, self.tcx).ty; + let discr_ty = discr.ty(&self.body.local_decls, self.tcx).ty; let discr_layout = self.ecx.layout_of(discr_ty).ok()?; let conditions = state.try_get(discr.as_ref(), self.map)?; diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 7eed47cf2398e..ad617be90c1e7 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -545,7 +545,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { return None; } use rustc_middle::mir::Rvalue::*; - let layout = self.ecx.layout_of(dest.ty(self.body, self.tcx).ty).ok()?; + let layout = self.ecx.layout_of(dest.ty(&self.body.local_decls, self.tcx).ty).ok()?; trace!(?layout); let val: Value<'_> = match *rvalue { diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 47758b56f8c90..438233c1d2a24 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -72,7 +72,7 @@ trait SimplifyMatch<'tcx> { _ => unreachable!(), }; - let discr_ty = discr.ty(body.local_decls(), tcx); + let discr_ty = discr.ty(&body.local_decls, tcx); self.can_simplify(tcx, targets, param_env, bbs, discr_ty)?; let mut patch = MirPatch::new(body); diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index 32c8064ebca50..83f018f768587 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -39,12 +39,12 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { let span = || self.body.source_info(location).span; match &terminator.kind { mir::TerminatorKind::Call { func, .. } | mir::TerminatorKind::TailCall { func, .. } => { - let callee_ty = func.ty(self.body, self.tcx); + let callee_ty = func.ty(&self.body.local_decls, self.tcx); self.mentioned_items .push(Spanned { node: MentionedItem::Fn(callee_ty), span: span() }); } mir::TerminatorKind::Drop { place, .. } => { - let ty = place.ty(self.body, self.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.tcx).ty; self.mentioned_items.push(Spanned { node: MentionedItem::Drop(ty), span: span() }); } mir::TerminatorKind::InlineAsm { ref operands, .. } => { @@ -77,7 +77,7 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { | mir::Rvalue::Cast(mir::CastKind::DynStar, ref operand, target_ty) => { // This isn't monomorphized yet so we can't tell what the actual types are -- just // add everything that may involve a vtable. - let source_ty = operand.ty(self.body, self.tcx); + let source_ty = operand.ty(&self.body.local_decls, self.tcx); let may_involve_vtable = match ( source_ty.builtin_deref(true).map(|t| t.kind()), target_ty.builtin_deref(true).map(|t| t.kind()), @@ -98,7 +98,7 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { ref operand, _, ) => { - let source_ty = operand.ty(self.body, self.tcx); + let source_ty = operand.ty(&self.body.local_decls, self.tcx); self.mentioned_items .push(Spanned { node: MentionedItem::Closure(source_ty), span: span() }); } @@ -108,7 +108,7 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { ref operand, _, ) => { - let fn_ty = operand.ty(self.body, self.tcx); + let fn_ty = operand.ty(&self.body.local_decls, self.tcx); self.mentioned_items.push(Spanned { node: MentionedItem::Fn(fn_ty), span: span() }); } _ => {} diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 6e84914ef972c..28c5815ba9588 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -327,7 +327,7 @@ impl<'tcx> Validator<'_, 'tcx> { && let Some((_, Rvalue::Use(Operand::Constant(c)))) = statement.kind.as_assign() && let Some(idx) = c.const_.try_eval_target_usize(self.tcx, self.param_env) // Determine the type of the thing we are indexing. - && let ty::Array(_, len) = place_base.ty(self.body, self.tcx).ty.kind() + && let ty::Array(_, len) = place_base.ty(&self.body.local_decls, self.tcx).ty.kind() // It's an array; determine its length. && let Some(len) = len.try_eval_target_usize(self.tcx, self.param_env) // If the index is in-bounds, go ahead. @@ -341,7 +341,7 @@ impl<'tcx> Validator<'_, 'tcx> { } ProjectionElem::Field(..) => { - let base_ty = place_base.ty(self.body, self.tcx).ty; + let base_ty = place_base.ty(&self.body.local_decls, self.tcx).ty; if base_ty.is_union() { // No promotion of union field accesses. return Err(Unpromotable); @@ -400,7 +400,7 @@ impl<'tcx> Validator<'_, 'tcx> { // FIXME: consider changing this to only promote &mut [] for default borrows, // also forbidding two phase borrows BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow } => { - let ty = place.ty(self.body, self.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.tcx).ty; // In theory, any zero-sized value could be borrowed // mutably without consequences. However, only &mut [] @@ -464,7 +464,7 @@ impl<'tcx> Validator<'_, 'tcx> { Rvalue::BinaryOp(op, box (lhs, rhs)) => { let op = *op; - let lhs_ty = lhs.ty(self.body, self.tcx); + let lhs_ty = lhs.ty(&self.body.local_decls, self.tcx); if let ty::RawPtr(_, _) | ty::FnPtr(..) = lhs_ty.kind() { // Raw and fn pointer operations are not allowed inside consts and thus not promotable. @@ -556,7 +556,7 @@ impl<'tcx> Validator<'_, 'tcx> { // no problem, only using it is. if let Some((place_base, ProjectionElem::Deref)) = place.as_ref().last_projection() { - let base_ty = place_base.ty(self.body, self.tcx).ty; + let base_ty = place_base.ty(&self.body.local_decls, self.tcx).ty; if let ty::Ref(..) = base_ty.kind() { return self.validate_place(place_base); } @@ -570,7 +570,7 @@ impl<'tcx> Validator<'_, 'tcx> { if let Some((place_base, ProjectionElem::Deref)) = place_simplified.last_projection() { - let base_ty = place_base.ty(self.body, self.tcx).ty; + let base_ty = place_base.ty(&self.body.local_decls, self.tcx).ty; if let ty::Ref(..) = base_ty.kind() { place_simplified = place_base; } @@ -647,7 +647,7 @@ impl<'tcx> Validator<'_, 'tcx> { // Functions marked `#[rustc_promotable]` are explicitly allowed to be promoted, so we can // accept them at this point. - let fn_ty = callee.ty(self.body, self.tcx); + let fn_ty = callee.ty(&self.body.local_decls, self.tcx); if let ty::FnDef(def_id, _) = *fn_ty.kind() { if self.tcx.is_promotable_const_fn(def_id) { return Ok(()); diff --git a/compiler/rustc_mir_transform/src/remove_uninit_drops.rs b/compiler/rustc_mir_transform/src/remove_uninit_drops.rs index fae1cb5f7d8a5..8bdcc9ef2a3a3 100644 --- a/compiler/rustc_mir_transform/src/remove_uninit_drops.rs +++ b/compiler/rustc_mir_transform/src/remove_uninit_drops.rs @@ -48,7 +48,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops { param_env, maybe_inits, &move_data, - place.ty(body, tcx).ty, + place.ty(&body.local_decls, tcx).ty, mpi, ); if !should_keep { diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 09b4e5e07113b..36775fba03f7d 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -261,7 +261,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) BorrowKind::Mut { kind: MutBorrowKind::Default }, tcx.mk_place_deref(dropee_ptr), ); - let ref_ty = reborrow.ty(body.local_decls(), tcx); + let ref_ty = reborrow.ty(&body.local_decls, tcx); dropee_ptr = body.local_decls.push(LocalDecl::new(ref_ty, span)).into(); let new_statements = [ StatementKind::Assign(Box::new((dropee_ptr, reborrow))), diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index c2108795372f6..6cca02216fda5 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -98,7 +98,7 @@ fn escaping_locals<'tcx>( let mut set = BitSet::new_empty(body.local_decls.len()); set.insert_range(RETURN_PLACE..=Local::from_usize(body.arg_count)); - for (local, decl) in body.local_decls().iter_enumerated() { + for (local, decl) in body.local_decls.iter_enumerated() { if excluded.contains(local) || is_excluded_ty(decl.ty) { set.insert(local); } diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index 76591f526250c..2f020c4733e57 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -335,8 +335,8 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) { }; let Some(rhs) = place.as_local() else { continue }; - let local_ty = body.local_decls()[local].ty; - let rhs_ty = body.local_decls()[rhs].ty; + let local_ty = body.local_decls[local].ty; + let rhs_ty = body.local_decls[rhs].ty; if local_ty != rhs_ty { // FIXME(#112651): This can be removed afterwards. trace!("skipped `{local:?} = {rhs:?}` due to subtyping: {local_ty} != {rhs_ty}"); diff --git a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs index 81baf58a5e0a0..ee81ec165b30d 100644 --- a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs +++ b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs @@ -40,7 +40,7 @@ fn get_switched_on_type<'tcx>( if let StatementKind::Assign(box (l, Rvalue::Discriminant(place))) = stmt_before_term.kind && l.as_local() == Some(local) { - let ty = place.ty(body, tcx).ty; + let ty = place.ty(&body.local_decls, tcx).ty; if ty.is_enum() { return Some(ty); } diff --git a/compiler/rustc_mir_transform/src/unreachable_prop.rs b/compiler/rustc_mir_transform/src/unreachable_prop.rs index a6c3c3b189ed0..56de3753aca24 100644 --- a/compiler/rustc_mir_transform/src/unreachable_prop.rs +++ b/compiler/rustc_mir_transform/src/unreachable_prop.rs @@ -91,7 +91,7 @@ fn remove_successors_from_switch<'tcx>( // In order to preserve this information, we record reachable and unreachable targets as // `Assume` statements in MIR. - let discr_ty = discr.ty(body, tcx); + let discr_ty = discr.ty(&body.local_decls, tcx); let discr_size = Size::from_bits(match discr_ty.kind() { ty::Uint(uint) => uint.normalize(tcx.sess.target.pointer_width).bit_width().unwrap(), ty::Int(int) => int.normalize(tcx.sess.target.pointer_width).bit_width().unwrap(), diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 36908036796c1..2f3312ce60b56 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -885,7 +885,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { AggregateKind::Tuple => {} AggregateKind::Array(dest) => { for src in fields { - if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) { + if !self + .mir_assign_valid_types(src.ty(&self.body.local_decls, self.tcx), dest) + { self.fail(location, "array field has the wrong type"); } } @@ -899,7 +901,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { adt_def.non_enum_variant().fields[field].ty(self.tcx, args), ); if let [field] = fields.raw.as_slice() { - let src_ty = field.ty(self.body, self.tcx); + let src_ty = field.ty(&self.body.local_decls, self.tcx); if !self.mir_assign_valid_types(src_ty, dest_ty) { self.fail(location, "union field has the wrong type"); } @@ -918,7 +920,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { let dest_ty = self .tcx .normalize_erasing_regions(self.param_env, dest.ty(self.tcx, args)); - if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest_ty) { + if !self.mir_assign_valid_types( + src.ty(&self.body.local_decls, self.tcx), + dest_ty, + ) { self.fail(location, "adt field has the wrong type"); } } @@ -929,7 +934,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.fail(location, "closure has the wrong number of initialized fields"); } for (src, dest) in std::iter::zip(fields, upvars) { - if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) { + if !self + .mir_assign_valid_types(src.ty(&self.body.local_decls, self.tcx), dest) + { self.fail(location, "closure field has the wrong type"); } } @@ -940,7 +947,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.fail(location, "coroutine has the wrong number of initialized fields"); } for (src, dest) in std::iter::zip(fields, upvars) { - if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) { + if !self + .mir_assign_valid_types(src.ty(&self.body.local_decls, self.tcx), dest) + { self.fail(location, "coroutine field has the wrong type"); } } @@ -954,7 +963,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } for (src, dest) in std::iter::zip(fields, upvars) { - if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest) { + if !self + .mir_assign_valid_types(src.ty(&self.body.local_decls, self.tcx), dest) + { self.fail(location, "coroutine-closure field has the wrong type"); } } @@ -968,8 +979,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } if let [data_ptr, metadata] = fields.raw.as_slice() { - let data_ptr_ty = data_ptr.ty(self.body, self.tcx); - let metadata_ty = metadata.ty(self.body, self.tcx); + let data_ptr_ty = data_ptr.ty(&self.body.local_decls, self.tcx); + let metadata_ty = metadata.ty(&self.body.local_decls, self.tcx); if let ty::RawPtr(in_pointee, in_mut) = data_ptr_ty.kind() { if *in_mut != mutability { self.fail(location, "input and output mutability must match"); @@ -1137,7 +1148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, '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); + let op_ty = operand.ty(&self.body.local_decls, self.tcx); match kind { CastKind::DynStar => { // FIXME(dyn-star): make sure nothing needs to be done here. diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index ff4207fbefda8..ac70894ce9fbf 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -666,7 +666,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { target_ty, ) | mir::Rvalue::Cast(mir::CastKind::DynStar, ref operand, target_ty) => { - let source_ty = operand.ty(self.body, self.tcx); + let source_ty = operand.ty(&self.body.local_decls, self.tcx); // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items .insert(MentionedItem::UnsizeCast { source_ty, target_ty }); @@ -694,7 +694,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { ref operand, _, ) => { - let fn_ty = operand.ty(self.body, self.tcx); + let fn_ty = operand.ty(&self.body.local_decls, self.tcx); // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items.insert(MentionedItem::Fn(fn_ty)); let fn_ty = self.monomorphize(fn_ty); @@ -705,7 +705,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { ref operand, _, ) => { - let source_ty = operand.ty(self.body, self.tcx); + let source_ty = operand.ty(&self.body.local_decls, self.tcx); // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items.insert(MentionedItem::Closure(source_ty)); let source_ty = self.monomorphize(source_ty); @@ -757,7 +757,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { match terminator.kind { mir::TerminatorKind::Call { ref func, ref args, ref fn_span, .. } | mir::TerminatorKind::TailCall { ref func, ref args, ref fn_span } => { - let callee_ty = func.ty(self.body, tcx); + let callee_ty = func.ty(&self.body.local_decls, tcx); // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items.insert(MentionedItem::Fn(callee_ty)); let callee_ty = self.monomorphize(callee_ty); @@ -765,7 +765,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { visit_fn_use(self.tcx, callee_ty, true, source, &mut self.used_items) } mir::TerminatorKind::Drop { ref place, .. } => { - let ty = place.ty(self.body, self.tcx).ty; + let ty = place.ty(&self.body.local_decls, self.tcx).ty; // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items.insert(MentionedItem::Drop(ty)); let ty = self.monomorphize(ty); diff --git a/compiler/rustc_monomorphize/src/collector/move_check.rs b/compiler/rustc_monomorphize/src/collector/move_check.rs index 851f86e86b8e8..f4d690e90686b 100644 --- a/compiler/rustc_monomorphize/src/collector/move_check.rs +++ b/compiler/rustc_monomorphize/src/collector/move_check.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { limit: Limit, operand: &mir::Operand<'tcx>, ) -> Option { - let ty = operand.ty(self.body, self.tcx); + let ty = operand.ty(&self.body.local_decls, self.tcx); let ty = self.monomorphize(ty); let Ok(layout) = self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) else { return None; diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index bfdc1cbeed7e1..034330ea0c45f 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -258,8 +258,8 @@ fn is_call_with_ref_arg<'tcx>( } = kind && args.len() == 1 && let mir::Operand::Move(mir::Place { local, .. }) = &args[0].node - && let ty::FnDef(def_id, _) = *func.ty(mir, cx.tcx).kind() - && let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(mir, cx.tcx)) + && let ty::FnDef(def_id, _) = *func.ty(&mir.local_decls, cx.tcx).kind() + && let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(&mir.local_decls, cx.tcx)) && !is_copy(cx, inner_ty) { Some((def_id, *local, inner_ty, destination.as_local()?)) 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 d9befb3c157a3..9ce009d78fe51 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 @@ -166,7 +166,7 @@ fn check_rvalue<'tcx>( Rvalue::BinaryOp(_, box (lhs, rhs)) => { check_operand(tcx, lhs, span, body, msrv)?; check_operand(tcx, rhs, span, body, msrv)?; - let ty = lhs.ty(body, tcx); + let ty = lhs.ty(&body.local_decls, tcx); if ty.is_integral() || ty.is_bool() || ty.is_char() { Ok(()) } else { @@ -179,7 +179,7 @@ fn check_rvalue<'tcx>( Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_) | NullOp::UbChecks, _) | Rvalue::ShallowInitBox(_, _) => Ok(()), Rvalue::UnaryOp(_, operand) => { - let ty = operand.ty(body, tcx); + let ty = operand.ty(&body.local_decls, tcx); if ty.is_integral() || ty.is_bool() { check_operand(tcx, operand, span, body, msrv) } else { @@ -268,11 +268,11 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B for (base, elem) in place.as_ref().iter_projections() { match elem { ProjectionElem::Field(..) => { - if base.ty(body, tcx).ty.is_union() && !msrv.meets(msrvs::CONST_FN_UNION) { + if base.ty(&body.local_decls, tcx).ty.is_union() && !msrv.meets(msrvs::CONST_FN_UNION) { return Err((span, "accessing union fields is unstable".into())); } }, - ProjectionElem::Deref => match base.ty(body, tcx).ty.kind() { + ProjectionElem::Deref => match base.ty(&body.local_decls, tcx).ty.kind() { ty::RawPtr(_, hir::Mutability::Mut) => { return Err((span, "dereferencing raw mut pointer in const fn is unstable".into())); }, @@ -331,7 +331,7 @@ fn check_terminator<'tcx>( fn_span: _, } | TerminatorKind::TailCall { func, args, fn_span: _ } => { - let fn_ty = func.ty(body, tcx); + let fn_ty = func.ty(&body.local_decls, tcx); if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { if !is_const_fn(tcx, fn_def_id, msrv) { return Err((