From 7eff2feb62be2ab39b110a434acdc3f852b5a7a3 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 10 Feb 2022 13:04:59 +0100 Subject: [PATCH] Remove further usage of `&hir::Map` --- .../src/diagnostics/mutability_errors.rs | 4 +-- .../src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_resolve/src/late/lifetimes.rs | 33 +++++++++---------- .../rustc_save_analysis/src/dump_visitor.rs | 8 ++--- .../error_reporting/on_unimplemented.rs | 2 +- .../rustc_typeck/src/check/method/suggest.rs | 2 +- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 049c3aab979..e6c057cc8ee 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -763,7 +763,7 @@ fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_ HirId, ImplItem, ImplItemKind, Item, ItemKind, }; - fn maybe_body_id_of_fn(hir_map: &Map<'_>, id: HirId) -> Option { + fn maybe_body_id_of_fn(hir_map: Map<'_>, id: HirId) -> Option { match hir_map.find(id) { Some(Node::Item(Item { kind: ItemKind::Fn(_, _, body_id), .. })) | Some(Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })) => { @@ -774,7 +774,7 @@ fn maybe_body_id_of_fn(hir_map: &Map<'_>, id: HirId) -> Option { } let hir_map = self.infcx.tcx.hir(); let mir_body_hir_id = self.mir_hir_id(); - if let Some(fn_body_id) = maybe_body_id_of_fn(&hir_map, mir_body_hir_id) { + if let Some(fn_body_id) = maybe_body_id_of_fn(hir_map, mir_body_hir_id) { if let Block( hir::Block { expr: diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 8d41497541a..b2de440084c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2226,7 +2226,7 @@ pub fn construct_generic_bound_failure( bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, ) -> DiagnosticBuilder<'a> { - let hir = &self.tcx.hir(); + let hir = self.tcx.hir(); // Attempt to obtain the span of the parameter so we can // suggest adding an explicit lifetime bound to it. let generics = self diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index f3d57139e08..ed9e43ae8d1 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -41,9 +41,9 @@ pub enum LifetimeUseSet<'tcx> { } trait RegionExt { - fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (ParamName, Region); + fn early(hir_map: Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (ParamName, Region); - fn late(index: u32, hir_map: &Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region); + fn late(index: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region); fn late_anon(named_late_bound_vars: u32, index: &Cell) -> Region; @@ -59,7 +59,7 @@ fn subst<'a, L>(self, params: L, map: &NamedRegionMap) -> Option } impl RegionExt for Region { - fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (ParamName, Region) { + fn early(hir_map: Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (ParamName, Region) { let i = *index; *index += 1; let def_id = hir_map.local_def_id(param.hir_id); @@ -68,7 +68,7 @@ fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam<'_>) -> (Param (param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id.to_def_id(), origin)) } - fn late(idx: u32, hir_map: &Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) { + fn late(idx: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) { let depth = ty::INNERMOST; let def_id = hir_map.local_def_id(param.hir_id); let origin = LifetimeDefOrigin::from_param(param); @@ -817,7 +817,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => { - Some(Region::early(&self.tcx.hir(), &mut index, param)) + Some(Region::early(self.tcx.hir(), &mut index, param)) } GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { non_lifetime_count += 1; @@ -888,7 +888,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .enumerate() .map(|(late_bound_idx, param)| { - let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param); + let pair = Region::late(late_bound_idx as u32, self.tcx.hir(), param); let r = late_region_as_bound_region(self.tcx, &pair.1); (pair, r) }) @@ -1045,7 +1045,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { for param in generics.params { match param.kind { GenericParamKind::Lifetime { .. } => { - let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m); + let (name, reg) = Region::early(self.tcx.hir(), &mut index, ¶m); let Region::EarlyBound(_, def_id, _) = reg else { bug!(); }; @@ -1145,7 +1145,7 @@ fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => { - Some(Region::early(&self.tcx.hir(), &mut index, param)) + Some(Region::early(self.tcx.hir(), &mut index, param)) } GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { non_lifetime_count += 1; @@ -1214,7 +1214,7 @@ fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => { - Some(Region::early(&self.tcx.hir(), &mut index, param)) + Some(Region::early(self.tcx.hir(), &mut index, param)) } GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => { non_lifetime_count += 1; @@ -1368,7 +1368,7 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) { .enumerate() .map(|(late_bound_idx, param)| { let pair = - Region::late(late_bound_idx as u32, &this.tcx.hir(), param); + Region::late(late_bound_idx as u32, this.tcx.hir(), param); let r = late_region_as_bound_region(this.tcx, &pair.1); (pair, r) }) @@ -1463,11 +1463,8 @@ fn visit_poly_trait_ref( .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .enumerate() .map(|(late_bound_idx, param)| { - let pair = Region::late( - initial_bound_vars + late_bound_idx as u32, - &self.tcx.hir(), - param, - ); + let pair = + Region::late(initial_bound_vars + late_bound_idx as u32, self.tcx.hir(), param); let r = late_region_as_bound_region(self.tcx, &pair.1); lifetimes.insert(pair.0, pair.1); r @@ -2200,9 +2197,9 @@ fn visit_early_late( if self.map.late_bound.contains(¶m.hir_id) { let late_bound_idx = named_late_bound_vars; named_late_bound_vars += 1; - Some(Region::late(late_bound_idx, &self.tcx.hir(), param)) + Some(Region::late(late_bound_idx, self.tcx.hir(), param)) } else { - Some(Region::early(&self.tcx.hir(), &mut next_early_index, param)) + Some(Region::early(self.tcx.hir(), &mut next_early_index, param)) } } GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { @@ -2222,7 +2219,7 @@ fn visit_early_late( }) .enumerate() .map(|(late_bound_idx, param)| { - let pair = Region::late(late_bound_idx as u32, &self.tcx.hir(), param); + let pair = Region::late(late_bound_idx as u32, self.tcx.hir(), param); late_region_as_bound_region(self.tcx, &pair.1) }) .collect(); diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index a3f7e84b1d5..79d55b297fd 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -262,7 +262,7 @@ fn process_method( ) { debug!("process_method: {:?}:{}", def_id, ident); - let map = &self.tcx.hir(); + let map = self.tcx.hir(); let hir_id = map.local_def_id_to_hir_id(def_id); self.nest_typeck_results(def_id, |v| { if let Some(mut method_data) = v.save_ctxt.get_method_data(hir_id, ident, span) { @@ -361,7 +361,7 @@ fn process_fn( ty_params: &'tcx hir::Generics<'tcx>, body: hir::BodyId, ) { - let map = &self.tcx.hir(); + let map = self.tcx.hir(); self.nest_typeck_results(item.def_id, |v| { let body = map.body(body); if let Some(fn_data) = v.save_ctxt.get_item_data(item) { @@ -626,7 +626,7 @@ fn process_impl(&mut self, item: &'tcx hir::Item<'tcx>, impl_: &'tcx hir::Impl<' } } - let map = &self.tcx.hir(); + let map = self.tcx.hir(); self.nest_typeck_results(item.def_id, |v| { v.visit_ty(&impl_.self_ty); if let Some(trait_ref) = &impl_.of_trait { @@ -716,7 +716,7 @@ fn process_trait( // walk generics and methods self.process_generic_params(generics, &qualname, item.hir_id()); for method in methods { - let map = &self.tcx.hir(); + let map = self.tcx.hir(); self.process_trait_item(map.trait_item(method.id), item.def_id.to_def_id()) } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 1540725246b..4e7a34d5951 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -77,7 +77,7 @@ fn impl_similar_to( /// Used to set on_unimplemented's `ItemContext` /// to be the enclosing (async) block/function/closure fn describe_enclosure(&self, hir_id: hir::HirId) -> Option<&'static str> { - let hir = &self.tcx.hir(); + let hir = self.tcx.hir(); let node = hir.find(hir_id)?; match &node { hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => { diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 58ea197d3e9..a17553b920f 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1663,7 +1663,7 @@ fn suggest_traits_to_import( let table_owner = table.borrow().hir_owner; let generics = self.tcx.generics_of(table_owner.to_def_id()); let type_param = generics.type_param(param, self.tcx); - let hir = &self.tcx.hir(); + let hir = self.tcx.hir(); if let Some(def_id) = type_param.def_id.as_local() { let id = hir.local_def_id_to_hir_id(def_id); // Get the `hir::Param` to verify whether it already has any bounds.