1
Fork 0

Remove further usage of &hir::Map

This commit is contained in:
Frank Steffahn 2022-02-10 13:04:59 +01:00
parent 89ac81a6e6
commit 7eff2feb62
6 changed files with 24 additions and 27 deletions

View file

@ -763,7 +763,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
HirId, ImplItem, ImplItemKind, Item, ItemKind, HirId, ImplItem, ImplItemKind, Item, ItemKind,
}; };
fn maybe_body_id_of_fn(hir_map: &Map<'_>, id: HirId) -> Option<BodyId> { fn maybe_body_id_of_fn(hir_map: Map<'_>, id: HirId) -> Option<BodyId> {
match hir_map.find(id) { match hir_map.find(id) {
Some(Node::Item(Item { kind: ItemKind::Fn(_, _, body_id), .. })) Some(Node::Item(Item { kind: ItemKind::Fn(_, _, body_id), .. }))
| Some(Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })) => { | Some(Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })) => {
@ -774,7 +774,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} }
let hir_map = self.infcx.tcx.hir(); let hir_map = self.infcx.tcx.hir();
let mir_body_hir_id = self.mir_hir_id(); 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( if let Block(
hir::Block { hir::Block {
expr: expr:

View file

@ -2226,7 +2226,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
bound_kind: GenericKind<'tcx>, bound_kind: GenericKind<'tcx>,
sub: Region<'tcx>, sub: Region<'tcx>,
) -> DiagnosticBuilder<'a> { ) -> DiagnosticBuilder<'a> {
let hir = &self.tcx.hir(); let hir = self.tcx.hir();
// Attempt to obtain the span of the parameter so we can // Attempt to obtain the span of the parameter so we can
// suggest adding an explicit lifetime bound to it. // suggest adding an explicit lifetime bound to it.
let generics = self let generics = self

View file

@ -41,9 +41,9 @@ pub enum LifetimeUseSet<'tcx> {
} }
trait RegionExt { 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<u32>) -> Region; fn late_anon(named_late_bound_vars: u32, index: &Cell<u32>) -> Region;
@ -59,7 +59,7 @@ trait RegionExt {
} }
impl RegionExt for Region { 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; let i = *index;
*index += 1; *index += 1;
let def_id = hir_map.local_def_id(param.hir_id); let def_id = hir_map.local_def_id(param.hir_id);
@ -68,7 +68,7 @@ impl RegionExt for Region {
(param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id.to_def_id(), origin)) (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 depth = ty::INNERMOST;
let def_id = hir_map.local_def_id(param.hir_id); let def_id = hir_map.local_def_id(param.hir_id);
let origin = LifetimeDefOrigin::from_param(param); let origin = LifetimeDefOrigin::from_param(param);
@ -817,7 +817,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
Some(Region::early(&self.tcx.hir(), &mut index, param)) Some(Region::early(self.tcx.hir(), &mut index, param))
} }
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
non_lifetime_count += 1; non_lifetime_count += 1;
@ -888,7 +888,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .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); let r = late_region_as_bound_region(self.tcx, &pair.1);
(pair, r) (pair, r)
}) })
@ -1045,7 +1045,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
for param in generics.params { for param in generics.params {
match param.kind { match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, &param); let (name, reg) = Region::early(self.tcx.hir(), &mut index, &param);
let Region::EarlyBound(_, def_id, _) = reg else { let Region::EarlyBound(_, def_id, _) = reg else {
bug!(); bug!();
}; };
@ -1145,7 +1145,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
Some(Region::early(&self.tcx.hir(), &mut index, param)) Some(Region::early(self.tcx.hir(), &mut index, param))
} }
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
non_lifetime_count += 1; non_lifetime_count += 1;
@ -1214,7 +1214,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
Some(Region::early(&self.tcx.hir(), &mut index, param)) Some(Region::early(self.tcx.hir(), &mut index, param))
} }
GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => { GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => {
non_lifetime_count += 1; non_lifetime_count += 1;
@ -1368,7 +1368,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = 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); let r = late_region_as_bound_region(this.tcx, &pair.1);
(pair, r) (pair, r)
}) })
@ -1463,11 +1463,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = Region::late( let pair =
initial_bound_vars + late_bound_idx as u32, Region::late(initial_bound_vars + late_bound_idx as u32, self.tcx.hir(), param);
&self.tcx.hir(),
param,
);
let r = late_region_as_bound_region(self.tcx, &pair.1); let r = late_region_as_bound_region(self.tcx, &pair.1);
lifetimes.insert(pair.0, pair.1); lifetimes.insert(pair.0, pair.1);
r r
@ -2200,9 +2197,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if self.map.late_bound.contains(&param.hir_id) { if self.map.late_bound.contains(&param.hir_id) {
let late_bound_idx = named_late_bound_vars; let late_bound_idx = named_late_bound_vars;
named_late_bound_vars += 1; 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 { } 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 { .. } => { GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
@ -2222,7 +2219,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}) })
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .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) late_region_as_bound_region(self.tcx, &pair.1)
}) })
.collect(); .collect();

View file

@ -262,7 +262,7 @@ impl<'tcx> DumpVisitor<'tcx> {
) { ) {
debug!("process_method: {:?}:{}", def_id, ident); 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); let hir_id = map.local_def_id_to_hir_id(def_id);
self.nest_typeck_results(def_id, |v| { self.nest_typeck_results(def_id, |v| {
if let Some(mut method_data) = v.save_ctxt.get_method_data(hir_id, ident, span) { if let Some(mut method_data) = v.save_ctxt.get_method_data(hir_id, ident, span) {
@ -361,7 +361,7 @@ impl<'tcx> DumpVisitor<'tcx> {
ty_params: &'tcx hir::Generics<'tcx>, ty_params: &'tcx hir::Generics<'tcx>,
body: hir::BodyId, body: hir::BodyId,
) { ) {
let map = &self.tcx.hir(); let map = self.tcx.hir();
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id, |v| {
let body = map.body(body); let body = map.body(body);
if let Some(fn_data) = v.save_ctxt.get_item_data(item) { if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
@ -626,7 +626,7 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
} }
let map = &self.tcx.hir(); let map = self.tcx.hir();
self.nest_typeck_results(item.def_id, |v| { self.nest_typeck_results(item.def_id, |v| {
v.visit_ty(&impl_.self_ty); v.visit_ty(&impl_.self_ty);
if let Some(trait_ref) = &impl_.of_trait { if let Some(trait_ref) = &impl_.of_trait {
@ -716,7 +716,7 @@ impl<'tcx> DumpVisitor<'tcx> {
// walk generics and methods // walk generics and methods
self.process_generic_params(generics, &qualname, item.hir_id()); self.process_generic_params(generics, &qualname, item.hir_id());
for method in methods { 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()) self.process_trait_item(map.trait_item(method.id), item.def_id.to_def_id())
} }
} }

View file

@ -77,7 +77,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// Used to set on_unimplemented's `ItemContext` /// Used to set on_unimplemented's `ItemContext`
/// to be the enclosing (async) block/function/closure /// to be the enclosing (async) block/function/closure
fn describe_enclosure(&self, hir_id: hir::HirId) -> Option<&'static str> { 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)?; let node = hir.find(hir_id)?;
match &node { match &node {
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => { hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. }) => {

View file

@ -1663,7 +1663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let table_owner = table.borrow().hir_owner; let table_owner = table.borrow().hir_owner;
let generics = self.tcx.generics_of(table_owner.to_def_id()); let generics = self.tcx.generics_of(table_owner.to_def_id());
let type_param = generics.type_param(param, self.tcx); 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() { if let Some(def_id) = type_param.def_id.as_local() {
let id = hir.local_def_id_to_hir_id(def_id); let id = hir.local_def_id_to_hir_id(def_id);
// Get the `hir::Param` to verify whether it already has any bounds. // Get the `hir::Param` to verify whether it already has any bounds.