1
Fork 0

Rollup merge of #93853 - steffahn:map_by_value, r=wesleywiser

Make all `hir::Map` methods consistently by-value

`hir::Map` only consists of a single reference (as part of the contained `TyCtxt`) anyways, so copying is literally zero overhead compared to passing a reference
This commit is contained in:
Matthias Krüger 2022-02-11 07:48:06 +01:00 committed by GitHub
commit ddba967855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 111 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

@ -141,22 +141,22 @@ pub trait Map<'hir> {
// Used when no map is actually available, forcing manual implementation of nested visitors. // Used when no map is actually available, forcing manual implementation of nested visitors.
impl<'hir> Map<'hir> for ! { impl<'hir> Map<'hir> for ! {
fn find(&self, _: HirId) -> Option<Node<'hir>> { fn find(&self, _: HirId) -> Option<Node<'hir>> {
unreachable!() *self;
} }
fn body(&self, _: BodyId) -> &'hir Body<'hir> { fn body(&self, _: BodyId) -> &'hir Body<'hir> {
unreachable!() *self;
} }
fn item(&self, _: ItemId) -> &'hir Item<'hir> { fn item(&self, _: ItemId) -> &'hir Item<'hir> {
unreachable!() *self;
} }
fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> { fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> {
unreachable!() *self;
} }
fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> { fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> {
unreachable!() *self;
} }
fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> { fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
unreachable!() *self;
} }
} }

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

@ -149,18 +149,18 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
} }
impl<'hir> Map<'hir> { impl<'hir> Map<'hir> {
pub fn krate(&self) -> &'hir Crate<'hir> { pub fn krate(self) -> &'hir Crate<'hir> {
self.tcx.hir_crate(()) self.tcx.hir_crate(())
} }
pub fn root_module(&self) -> &'hir Mod<'hir> { pub fn root_module(self) -> &'hir Mod<'hir> {
match self.tcx.hir_owner(CRATE_DEF_ID).map(|o| o.node) { match self.tcx.hir_owner(CRATE_DEF_ID).map(|o| o.node) {
Some(OwnerNode::Crate(item)) => item, Some(OwnerNode::Crate(item)) => item,
_ => bug!(), _ => bug!(),
} }
} }
pub fn items(&self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir { pub fn items(self) -> impl Iterator<Item = &'hir Item<'hir>> + 'hir {
let krate = self.krate(); let krate = self.krate();
krate.owners.iter().filter_map(|owner| match owner.as_owner()?.node() { krate.owners.iter().filter_map(|owner| match owner.as_owner()?.node() {
OwnerNode::Item(item) => Some(item), OwnerNode::Item(item) => Some(item),
@ -168,16 +168,16 @@ impl<'hir> Map<'hir> {
}) })
} }
pub fn def_key(&self, def_id: LocalDefId) -> DefKey { pub fn def_key(self, def_id: LocalDefId) -> DefKey {
// Accessing the DefKey is ok, since it is part of DefPathHash. // Accessing the DefKey is ok, since it is part of DefPathHash.
self.tcx.untracked_resolutions.definitions.def_key(def_id) self.tcx.untracked_resolutions.definitions.def_key(def_id)
} }
pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> { pub fn def_path_from_hir_id(self, id: HirId) -> Option<DefPath> {
self.opt_local_def_id(id).map(|def_id| self.def_path(def_id)) self.opt_local_def_id(id).map(|def_id| self.def_path(def_id))
} }
pub fn def_path(&self, def_id: LocalDefId) -> DefPath { pub fn def_path(self, def_id: LocalDefId) -> DefPath {
// Accessing the DefPath is ok, since it is part of DefPathHash. // Accessing the DefPath is ok, since it is part of DefPathHash.
self.tcx.untracked_resolutions.definitions.def_path(def_id) self.tcx.untracked_resolutions.definitions.def_path(def_id)
} }
@ -189,7 +189,7 @@ impl<'hir> Map<'hir> {
} }
#[inline] #[inline]
pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId { pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
self.opt_local_def_id(hir_id).unwrap_or_else(|| { self.opt_local_def_id(hir_id).unwrap_or_else(|| {
bug!( bug!(
"local_def_id: no entry for `{:?}`, which has a map of `{:?}`", "local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
@ -200,7 +200,7 @@ impl<'hir> Map<'hir> {
} }
#[inline] #[inline]
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> { pub fn opt_local_def_id(self, hir_id: HirId) -> Option<LocalDefId> {
if hir_id.local_id == ItemLocalId::new(0) { if hir_id.local_id == ItemLocalId::new(0) {
Some(hir_id.owner) Some(hir_id.owner)
} else { } else {
@ -214,18 +214,18 @@ impl<'hir> Map<'hir> {
} }
#[inline] #[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId { pub fn local_def_id_to_hir_id(self, def_id: LocalDefId) -> HirId {
self.tcx.local_def_id_to_hir_id(def_id) self.tcx.local_def_id_to_hir_id(def_id)
} }
pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ { pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'hir {
// Create a dependency to the crate to be sure we reexcute this when the amount of // Create a dependency to the crate to be sure we reexcute this when the amount of
// definitions change. // definitions change.
self.tcx.ensure().hir_crate(()); self.tcx.ensure().hir_crate(());
self.tcx.untracked_resolutions.definitions.iter_local_def_id() self.tcx.untracked_resolutions.definitions.iter_local_def_id()
} }
pub fn opt_def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> { pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
let hir_id = self.local_def_id_to_hir_id(local_def_id); let hir_id = self.local_def_id_to_hir_id(local_def_id);
let def_kind = match self.find(hir_id)? { let def_kind = match self.find(hir_id)? {
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {
@ -312,12 +312,12 @@ impl<'hir> Map<'hir> {
Some(def_kind) Some(def_kind)
} }
pub fn def_kind(&self, local_def_id: LocalDefId) -> DefKind { pub fn def_kind(self, local_def_id: LocalDefId) -> DefKind {
self.opt_def_kind(local_def_id) self.opt_def_kind(local_def_id)
.unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", local_def_id)) .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", local_def_id))
} }
pub fn find_parent_node(&self, id: HirId) -> Option<HirId> { pub fn find_parent_node(self, id: HirId) -> Option<HirId> {
if id.local_id == ItemLocalId::from_u32(0) { if id.local_id == ItemLocalId::from_u32(0) {
Some(self.tcx.hir_owner_parent(id.owner)) Some(self.tcx.hir_owner_parent(id.owner))
} else { } else {
@ -328,12 +328,12 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn get_parent_node(&self, hir_id: HirId) -> HirId { pub fn get_parent_node(self, hir_id: HirId) -> HirId {
self.find_parent_node(hir_id).unwrap() self.find_parent_node(hir_id).unwrap()
} }
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub fn find(&self, id: HirId) -> Option<Node<'hir>> { pub fn find(self, id: HirId) -> Option<Node<'hir>> {
if id.local_id == ItemLocalId::from_u32(0) { if id.local_id == ItemLocalId::from_u32(0) {
let owner = self.tcx.hir_owner(id.owner)?; let owner = self.tcx.hir_owner(id.owner)?;
Some(owner.node.into()) Some(owner.node.into())
@ -346,26 +346,26 @@ impl<'hir> Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
#[inline] #[inline]
pub fn find_by_def_id(&self, id: LocalDefId) -> Option<Node<'hir>> { pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>> {
self.find(self.local_def_id_to_hir_id(id)) self.find(self.local_def_id_to_hir_id(id))
} }
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
pub fn get(&self, id: HirId) -> Node<'hir> { pub fn get(self, id: HirId) -> Node<'hir> {
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
} }
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
#[inline] #[inline]
pub fn get_by_def_id(&self, id: LocalDefId) -> Node<'hir> { pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id)) self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
} }
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> { pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id))) id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id)))
} }
pub fn get_generics(&self, id: LocalDefId) -> Option<&'hir Generics<'hir>> { pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
let node = self.tcx.hir_owner(id)?; let node = self.tcx.hir_owner(id)?;
match node.node { match node.node {
OwnerNode::ImplItem(impl_item) => Some(&impl_item.generics), OwnerNode::ImplItem(impl_item) => Some(&impl_item.generics),
@ -386,27 +386,27 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn item(&self, id: ItemId) -> &'hir Item<'hir> { pub fn item(self, id: ItemId) -> &'hir Item<'hir> {
self.tcx.hir_owner(id.def_id).unwrap().node.expect_item() self.tcx.hir_owner(id.def_id).unwrap().node.expect_item()
} }
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir> {
self.tcx.hir_owner(id.def_id).unwrap().node.expect_trait_item() self.tcx.hir_owner(id.def_id).unwrap().node.expect_trait_item()
} }
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir> {
self.tcx.hir_owner(id.def_id).unwrap().node.expect_impl_item() self.tcx.hir_owner(id.def_id).unwrap().node.expect_impl_item()
} }
pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
self.tcx.hir_owner(id.def_id).unwrap().node.expect_foreign_item() self.tcx.hir_owner(id.def_id).unwrap().node.expect_foreign_item()
} }
pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id] self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
} }
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
if let Some(node) = self.find(hir_id) { if let Some(node) = self.find(hir_id) {
fn_decl(node) fn_decl(node)
} else { } else {
@ -414,7 +414,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn fn_sig_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> { pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
if let Some(node) = self.find(hir_id) { if let Some(node) = self.find(hir_id) {
fn_sig(node) fn_sig(node)
} else { } else {
@ -422,7 +422,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn enclosing_body_owner(&self, hir_id: HirId) -> HirId { pub fn enclosing_body_owner(self, hir_id: HirId) -> HirId {
for (parent, _) in self.parent_iter(hir_id) { for (parent, _) in self.parent_iter(hir_id) {
if let Some(body) = self.maybe_body_owned_by(parent) { if let Some(body) = self.maybe_body_owned_by(parent) {
return self.body_owner(body); return self.body_owner(body);
@ -435,24 +435,24 @@ impl<'hir> Map<'hir> {
/// Returns the `HirId` that corresponds to the definition of /// Returns the `HirId` that corresponds to the definition of
/// which this is the body of, i.e., a `fn`, `const` or `static` /// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`. /// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
let parent = self.get_parent_node(hir_id); let parent = self.get_parent_node(hir_id);
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id))); assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)));
parent parent
} }
pub fn body_owner_def_id(&self, id: BodyId) -> LocalDefId { pub fn body_owner_def_id(self, id: BodyId) -> LocalDefId {
self.local_def_id(self.body_owner(id)) self.local_def_id(self.body_owner(id))
} }
/// Given a `HirId`, returns the `BodyId` associated with it, /// Given a `HirId`, returns the `BodyId` associated with it,
/// if the node is a body owner, otherwise returns `None`. /// if the node is a body owner, otherwise returns `None`.
pub fn maybe_body_owned_by(&self, hir_id: HirId) -> Option<BodyId> { pub fn maybe_body_owned_by(self, hir_id: HirId) -> Option<BodyId> {
self.find(hir_id).map(associated_body).flatten() self.find(hir_id).map(associated_body).flatten()
} }
/// Given a body owner's id, returns the `BodyId` associated with it. /// Given a body owner's id, returns the `BodyId` associated with it.
pub fn body_owned_by(&self, id: HirId) -> BodyId { pub fn body_owned_by(self, id: HirId) -> BodyId {
self.maybe_body_owned_by(id).unwrap_or_else(|| { self.maybe_body_owned_by(id).unwrap_or_else(|| {
span_bug!( span_bug!(
self.span(id), self.span(id),
@ -462,7 +462,7 @@ impl<'hir> Map<'hir> {
}) })
} }
pub fn body_param_names(&self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir { pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
self.body(id).params.iter().map(|arg| match arg.pat.kind { self.body(id).params.iter().map(|arg| match arg.pat.kind {
PatKind::Binding(_, _, ident, _) => ident, PatKind::Binding(_, _, ident, _) => ident,
_ => Ident::empty(), _ => Ident::empty(),
@ -472,7 +472,7 @@ impl<'hir> Map<'hir> {
/// Returns the `BodyOwnerKind` of this `LocalDefId`. /// Returns the `BodyOwnerKind` of this `LocalDefId`.
/// ///
/// Panics if `LocalDefId` does not have an associated body. /// Panics if `LocalDefId` does not have an associated body.
pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { pub fn body_owner_kind(self, id: HirId) -> BodyOwnerKind {
match self.get(id) { match self.get(id) {
Node::Item(&Item { kind: ItemKind::Const(..), .. }) Node::Item(&Item { kind: ItemKind::Const(..), .. })
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { kind: TraitItemKind::Const(..), .. })
@ -495,7 +495,7 @@ impl<'hir> Map<'hir> {
/// This should only be used for determining the context of a body, a return /// This should only be used for determining the context of a body, a return
/// value of `Some` does not always suggest that the owner of the body is `const`, /// value of `Some` does not always suggest that the owner of the body is `const`,
/// just that it has to be checked as if it were. /// just that it has to be checked as if it were.
pub fn body_const_context(&self, did: LocalDefId) -> Option<ConstContext> { pub fn body_const_context(self, did: LocalDefId) -> Option<ConstContext> {
let hir_id = self.local_def_id_to_hir_id(did); let hir_id = self.local_def_id_to_hir_id(did);
let ccx = match self.body_owner_kind(hir_id) { let ccx = match self.body_owner_kind(hir_id) {
BodyOwnerKind::Const => ConstContext::Const, BodyOwnerKind::Const => ConstContext::Const,
@ -549,7 +549,7 @@ impl<'hir> Map<'hir> {
}); });
} }
pub fn ty_param_owner(&self, id: HirId) -> LocalDefId { pub fn ty_param_owner(self, id: HirId) -> LocalDefId {
match self.get(id) { match self.get(id) {
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => { Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => {
id.expect_owner() id.expect_owner()
@ -559,7 +559,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn ty_param_name(&self, id: HirId) -> Symbol { pub fn ty_param_name(self, id: HirId) -> Symbol {
match self.get(id) { match self.get(id) {
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => { Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => {
kw::SelfUpper kw::SelfUpper
@ -569,18 +569,18 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] { pub fn trait_impls(self, trait_did: DefId) -> &'hir [LocalDefId] {
self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..]) self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
} }
/// Gets the attributes on the crate. This is preferable to /// Gets the attributes on the crate. This is preferable to
/// invoking `krate.attrs` because it registers a tighter /// invoking `krate.attrs` because it registers a tighter
/// dep-graph access. /// dep-graph access.
pub fn krate_attrs(&self) -> &'hir [ast::Attribute] { pub fn krate_attrs(self) -> &'hir [ast::Attribute] {
self.attrs(CRATE_HIR_ID) self.attrs(CRATE_HIR_ID)
} }
pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) { pub fn get_module(self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = HirId::make_owner(module); let hir_id = HirId::make_owner(module);
match self.tcx.hir_owner(module).map(|o| o.node) { match self.tcx.hir_owner(module).map(|o| o.node) {
Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => { Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => {
@ -620,7 +620,7 @@ impl<'hir> Map<'hir> {
/// follows lexical scoping rules -- then you want a different /// follows lexical scoping rules -- then you want a different
/// approach. You should override `visit_nested_item` in your /// approach. You should override `visit_nested_item` in your
/// visitor and then call `intravisit::walk_crate` instead. /// visitor and then call `intravisit::walk_crate` instead.
pub fn visit_all_item_likes<V>(&self, visitor: &mut V) pub fn visit_all_item_likes<V>(self, visitor: &mut V)
where where
V: itemlikevisit::ItemLikeVisitor<'hir>, V: itemlikevisit::ItemLikeVisitor<'hir>,
{ {
@ -637,7 +637,7 @@ impl<'hir> Map<'hir> {
} }
/// A parallel version of `visit_all_item_likes`. /// A parallel version of `visit_all_item_likes`.
pub fn par_visit_all_item_likes<V>(&self, visitor: &V) pub fn par_visit_all_item_likes<V>(self, visitor: &V)
where where
V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send, V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send,
{ {
@ -653,7 +653,7 @@ impl<'hir> Map<'hir> {
}) })
} }
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V) pub fn visit_item_likes_in_module<V>(self, module: LocalDefId, visitor: &mut V)
where where
V: ItemLikeVisitor<'hir>, V: ItemLikeVisitor<'hir>,
{ {
@ -676,7 +676,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn for_each_module(&self, f: impl Fn(LocalDefId)) { pub fn for_each_module(self, f: impl Fn(LocalDefId)) {
let mut queue = VecDeque::new(); let mut queue = VecDeque::new();
queue.push_back(CRATE_DEF_ID); queue.push_back(CRATE_DEF_ID);
@ -689,12 +689,12 @@ impl<'hir> Map<'hir> {
#[cfg(not(parallel_compiler))] #[cfg(not(parallel_compiler))]
#[inline] #[inline]
pub fn par_for_each_module(&self, f: impl Fn(LocalDefId)) { pub fn par_for_each_module(self, f: impl Fn(LocalDefId)) {
self.for_each_module(f) self.for_each_module(f)
} }
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
pub fn par_for_each_module(&self, f: impl Fn(LocalDefId) + Sync) { pub fn par_for_each_module(self, f: impl Fn(LocalDefId) + Sync) {
use rustc_data_structures::sync::{par_iter, ParallelIterator}; use rustc_data_structures::sync::{par_iter, ParallelIterator};
par_iter_submodules(self.tcx, CRATE_DEF_ID, &f); par_iter_submodules(self.tcx, CRATE_DEF_ID, &f);
@ -721,7 +721,7 @@ impl<'hir> Map<'hir> {
} }
/// Checks if the node is left-hand side of an assignment. /// Checks if the node is left-hand side of an assignment.
pub fn is_lhs(&self, id: HirId) -> bool { pub fn is_lhs(self, id: HirId) -> bool {
match self.find(self.get_parent_node(id)) { match self.find(self.get_parent_node(id)) {
Some(Node::Expr(expr)) => match expr.kind { Some(Node::Expr(expr)) => match expr.kind {
ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id, ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id,
@ -733,7 +733,7 @@ impl<'hir> Map<'hir> {
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context. /// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
/// Used exclusively for diagnostics, to avoid suggestion function calls. /// Used exclusively for diagnostics, to avoid suggestion function calls.
pub fn is_inside_const_context(&self, hir_id: HirId) -> bool { pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some() self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
} }
@ -759,7 +759,7 @@ impl<'hir> Map<'hir> {
/// false /// false
/// } /// }
/// ``` /// ```
pub fn get_return_block(&self, id: HirId) -> Option<HirId> { pub fn get_return_block(self, id: HirId) -> Option<HirId> {
let mut iter = self.parent_iter(id).peekable(); let mut iter = self.parent_iter(id).peekable();
let mut ignore_tail = false; let mut ignore_tail = false;
if let Some(node) = self.find(id) { if let Some(node) = self.find(id) {
@ -799,7 +799,7 @@ impl<'hir> Map<'hir> {
/// parent item is in this map. The "parent item" is the closest parent node /// parent item is in this map. The "parent item" is the closest parent node
/// in the HIR which is recorded by the map and is an item, either an item /// in the HIR which is recorded by the map and is an item, either an item
/// in a module, trait, or impl. /// in a module, trait, or impl.
pub fn get_parent_item(&self, hir_id: HirId) -> LocalDefId { pub fn get_parent_item(self, hir_id: HirId) -> LocalDefId {
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
def_id def_id
} else { } else {
@ -809,7 +809,7 @@ impl<'hir> Map<'hir> {
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no /// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map. /// module parent is in this map.
pub(super) fn get_module_parent_node(&self, hir_id: HirId) -> LocalDefId { pub(super) fn get_module_parent_node(self, hir_id: HirId) -> LocalDefId {
for (def_id, node) in self.parent_owner_iter(hir_id) { for (def_id, node) in self.parent_owner_iter(hir_id) {
if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node { if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
return def_id; return def_id;
@ -823,7 +823,7 @@ impl<'hir> Map<'hir> {
/// ///
/// Used by error reporting when there's a type error in an if or match arm caused by the /// Used by error reporting when there's a type error in an if or match arm caused by the
/// expression needing to be unit. /// expression needing to be unit.
pub fn get_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> { pub fn get_if_cause(self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
for (_, node) in self.parent_iter(hir_id) { for (_, node) in self.parent_iter(hir_id) {
match node { match node {
Node::Item(_) Node::Item(_)
@ -841,7 +841,7 @@ impl<'hir> Map<'hir> {
} }
/// Returns the nearest enclosing scope. A scope is roughly an item or block. /// Returns the nearest enclosing scope. A scope is roughly an item or block.
pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> { pub fn get_enclosing_scope(self, hir_id: HirId) -> Option<HirId> {
for (hir_id, node) in self.parent_iter(hir_id) { for (hir_id, node) in self.parent_iter(hir_id) {
if let Node::Item(Item { if let Node::Item(Item {
kind: kind:
@ -868,7 +868,7 @@ impl<'hir> Map<'hir> {
} }
/// Returns the defining scope for an opaque type definition. /// Returns the defining scope for an opaque type definition.
pub fn get_defining_scope(&self, id: HirId) -> HirId { pub fn get_defining_scope(self, id: HirId) -> HirId {
let mut scope = id; let mut scope = id;
loop { loop {
scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID); scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID);
@ -878,7 +878,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi { pub fn get_foreign_abi(self, hir_id: HirId) -> Abi {
let parent = self.get_parent_item(hir_id); let parent = self.get_parent_item(hir_id);
if let Some(node) = self.tcx.hir_owner(parent) { if let Some(node) = self.tcx.hir_owner(parent) {
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node.node if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node.node
@ -892,35 +892,35 @@ impl<'hir> Map<'hir> {
) )
} }
pub fn expect_item(&self, id: LocalDefId) -> &'hir Item<'hir> { pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(id) {
Some(Owner { node: OwnerNode::Item(item), .. }) => item, Some(Owner { node: OwnerNode::Item(item), .. }) => item,
_ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
} }
pub fn expect_impl_item(&self, id: LocalDefId) -> &'hir ImplItem<'hir> { pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(id) {
Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item, Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
} }
pub fn expect_trait_item(&self, id: LocalDefId) -> &'hir TraitItem<'hir> { pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(id) {
Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item, Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))), _ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))),
} }
} }
pub fn expect_variant(&self, id: HirId) -> &'hir Variant<'hir> { pub fn expect_variant(self, id: HirId) -> &'hir Variant<'hir> {
match self.find(id) { match self.find(id) {
Some(Node::Variant(variant)) => variant, Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)), _ => bug!("expected variant, found {}", self.node_to_string(id)),
} }
} }
pub fn expect_foreign_item(&self, id: LocalDefId) -> &'hir ForeignItem<'hir> { pub fn expect_foreign_item(self, id: LocalDefId) -> &'hir ForeignItem<'hir> {
match self.tcx.hir_owner(id) { match self.tcx.hir_owner(id) {
Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item, Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item,
_ => { _ => {
@ -929,14 +929,14 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn expect_expr(&self, id: HirId) -> &'hir Expr<'hir> { pub fn expect_expr(self, id: HirId) -> &'hir Expr<'hir> {
match self.find(id) { match self.find(id) {
Some(Node::Expr(expr)) => expr, Some(Node::Expr(expr)) => expr,
_ => bug!("expected expr, found {}", self.node_to_string(id)), _ => bug!("expected expr, found {}", self.node_to_string(id)),
} }
} }
pub fn opt_name(&self, id: HirId) -> Option<Symbol> { pub fn opt_name(self, id: HirId) -> Option<Symbol> {
Some(match self.get(id) { Some(match self.get(id) {
Node::Item(i) => i.ident.name, Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name, Node::ForeignItem(fi) => fi.ident.name,
@ -952,7 +952,7 @@ impl<'hir> Map<'hir> {
}) })
} }
pub fn name(&self, id: HirId) -> Symbol { pub fn name(self, id: HirId) -> Symbol {
match self.opt_name(id) { match self.opt_name(id) {
Some(name) => name, Some(name) => name,
None => bug!("no name for {}", self.node_to_string(id)), None => bug!("no name for {}", self.node_to_string(id)),
@ -961,18 +961,18 @@ impl<'hir> Map<'hir> {
/// Given a node ID, gets a list of attributes associated with the AST /// Given a node ID, gets a list of attributes associated with the AST
/// corresponding to the node-ID. /// corresponding to the node-ID.
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] { pub fn attrs(self, id: HirId) -> &'hir [ast::Attribute] {
self.tcx.hir_attrs(id.owner).get(id.local_id) self.tcx.hir_attrs(id.owner).get(id.local_id)
} }
/// Gets the span of the definition of the specified HIR node. /// Gets the span of the definition of the specified HIR node.
/// This is used by `tcx.get_span` /// This is used by `tcx.get_span`
pub fn span(&self, hir_id: HirId) -> Span { pub fn span(self, hir_id: HirId) -> Span {
self.opt_span(hir_id) self.opt_span(hir_id)
.unwrap_or_else(|| bug!("hir::map::Map::span: id not in map: {:?}", hir_id)) .unwrap_or_else(|| bug!("hir::map::Map::span: id not in map: {:?}", hir_id))
} }
pub fn opt_span(&self, hir_id: HirId) -> Option<Span> { pub fn opt_span(self, hir_id: HirId) -> Option<Span> {
let span = match self.find(hir_id)? { let span = match self.find(hir_id)? {
Node::Param(param) => param.span, Node::Param(param) => param.span,
Node::Item(item) => match &item.kind { Node::Item(item) => match &item.kind {
@ -1021,7 +1021,7 @@ impl<'hir> Map<'hir> {
/// Like `hir.span()`, but includes the body of function items /// Like `hir.span()`, but includes the body of function items
/// (instead of just the function header) /// (instead of just the function header)
pub fn span_with_body(&self, hir_id: HirId) -> Span { pub fn span_with_body(self, hir_id: HirId) -> Span {
match self.find(hir_id) { match self.find(hir_id) {
Some(Node::TraitItem(item)) => item.span, Some(Node::TraitItem(item)) => item.span,
Some(Node::ImplItem(impl_item)) => impl_item.span, Some(Node::ImplItem(impl_item)) => impl_item.span,
@ -1031,11 +1031,11 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn span_if_local(&self, id: DefId) -> Option<Span> { pub fn span_if_local(self, id: DefId) -> Option<Span> {
id.as_local().and_then(|id| self.opt_span(self.local_def_id_to_hir_id(id))) id.as_local().and_then(|id| self.opt_span(self.local_def_id_to_hir_id(id)))
} }
pub fn res_span(&self, res: Res) -> Option<Span> { pub fn res_span(self, res: Res) -> Option<Span> {
match res { match res {
Res::Err => None, Res::Err => None,
Res::Local(id) => Some(self.span(id)), Res::Local(id) => Some(self.span(id)),
@ -1045,13 +1045,13 @@ impl<'hir> Map<'hir> {
/// Get a representation of this `id` for debugging purposes. /// Get a representation of this `id` for debugging purposes.
/// NOTE: Do NOT use this in diagnostics! /// NOTE: Do NOT use this in diagnostics!
pub fn node_to_string(&self, id: HirId) -> String { pub fn node_to_string(self, id: HirId) -> String {
hir_id_to_string(self, id) hir_id_to_string(self, id)
} }
/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when /// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
/// called with the HirId for the `{ ... }` anon const /// called with the HirId for the `{ ... }` anon const
pub fn opt_const_param_default_param_hir_id(&self, anon_const: HirId) -> Option<HirId> { pub fn opt_const_param_default_param_hir_id(self, anon_const: HirId) -> Option<HirId> {
match self.get(self.get_parent_node(anon_const)) { match self.get(self.get_parent_node(anon_const)) {
Node::GenericParam(GenericParam { Node::GenericParam(GenericParam {
hir_id: param_id, hir_id: param_id,
@ -1065,27 +1065,27 @@ impl<'hir> Map<'hir> {
impl<'hir> intravisit::Map<'hir> for Map<'hir> { impl<'hir> intravisit::Map<'hir> for Map<'hir> {
fn find(&self, hir_id: HirId) -> Option<Node<'hir>> { fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
self.find(hir_id) (*self).find(hir_id)
} }
fn body(&self, id: BodyId) -> &'hir Body<'hir> { fn body(&self, id: BodyId) -> &'hir Body<'hir> {
self.body(id) (*self).body(id)
} }
fn item(&self, id: ItemId) -> &'hir Item<'hir> { fn item(&self, id: ItemId) -> &'hir Item<'hir> {
self.item(id) (*self).item(id)
} }
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
self.trait_item(id) (*self).trait_item(id)
} }
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
self.impl_item(id) (*self).impl_item(id)
} }
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
self.foreign_item(id) (*self).foreign_item(id)
} }
} }
@ -1154,7 +1154,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
upstream_crates upstream_crates
} }
fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String { fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
let id_str = format!(" (hir_id={})", id); let id_str = format!(" (hir_id={})", id);
let path_str = || { let path_str = || {

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
@ -2194,9 +2191,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 { .. } => {
@ -2216,7 +2213,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.