Struct rustc_middle::hir::map::Map
source · pub struct Map<'hir> {
pub(super) tcx: TyCtxt<'hir>,
}
Fields§
§tcx: TyCtxt<'hir>
Implementations§
source§impl<'hir> Map<'hir>
impl<'hir> Map<'hir>
pub fn krate(self) -> &'hir Crate<'hir>
pub fn root_module(self) -> &'hir Mod<'hir>
pub fn items(self) -> impl Iterator<Item = ItemId> + 'hir
pub fn module_items( self, module: LocalModDefId ) -> impl Iterator<Item = ItemId> + 'hir
pub fn def_key(self, def_id: LocalDefId) -> DefKey
pub fn def_path(self, def_id: LocalDefId) -> DefPath
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash
pub fn local_def_id_to_hir_id(self, def_id: impl Into<LocalDefId>) -> HirId
sourcepub(super) fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind>
pub(super) fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind>
Do not call this function directly. The query should be called.
sourcepub fn opt_parent_id(self, id: HirId) -> Option<HirId>
pub fn opt_parent_id(self, id: HirId) -> Option<HirId>
Finds the id of the parent node to this one.
If calling repeatedly and iterating over parents, prefer Map::parent_iter
.
pub fn parent_id(self, hir_id: HirId) -> HirId
pub fn get_parent(self, hir_id: HirId) -> Node<'hir>
pub fn find_parent(self, hir_id: HirId) -> Option<Node<'hir>>
sourcepub fn find(self, id: HirId) -> Option<Node<'hir>>
pub fn find(self, id: HirId) -> Option<Node<'hir>>
Retrieves the Node
corresponding to id
, returning None
if cannot be found.
sourcepub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>>
pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>>
Retrieves the Node
corresponding to id
, returning None
if cannot be found.
sourcepub fn get(self, id: HirId) -> Node<'hir>
pub fn get(self, id: HirId) -> Node<'hir>
Retrieves the Node
corresponding to id
, panicking if it cannot be found.
sourcepub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir>
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir>
Retrieves the Node
corresponding to id
, panicking if it cannot be found.
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>>
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>>
pub fn owner(self, id: OwnerId) -> OwnerNode<'hir>
pub fn item(self, id: ItemId) -> &'hir Item<'hir>
pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir>
pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir>
pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir>
pub fn body(self, id: BodyId) -> &'hir Body<'hir>
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>>
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>>
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId
sourcepub fn body_owner(self, _: BodyId) -> HirId
pub fn body_owner(self, _: BodyId) -> HirId
Returns the HirId
that corresponds to the definition of
which this is the body of, i.e., a fn
, const
or static
item (possibly associated), a closure, or a hir::AnonConst
.
pub fn body_owner_def_id(self, _: BodyId) -> LocalDefId
sourcepub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId>
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId>
Given a LocalDefId
, returns the BodyId
associated with it,
if the node is a body owner, otherwise returns None
.
sourcepub fn body_owned_by(self, id: LocalDefId) -> BodyId
pub fn body_owned_by(self, id: LocalDefId) -> BodyId
Given a body owner’s id, returns the BodyId
associated with it.
pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir
sourcepub fn body_owner_kind(self, def_id: LocalDefId) -> BodyOwnerKind
pub fn body_owner_kind(self, def_id: LocalDefId) -> BodyOwnerKind
Returns the BodyOwnerKind
of this LocalDefId
.
Panics if LocalDefId
does not have an associated body.
sourcepub fn body_const_context(self, def_id: LocalDefId) -> Option<ConstContext>
pub fn body_const_context(self, def_id: LocalDefId) -> Option<ConstContext>
Returns the ConstContext
of the body associated with this LocalDefId
.
Panics if LocalDefId
does not have an associated body.
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
,
just that it has to be checked as if it were.
sourcepub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir
Returns an iterator of the DefId
s for all body-owners in this
crate. If you would prefer to iterate over the bodies
themselves, you can do self.hir().krate().body_ids.iter()
.
pub fn par_body_owners(self, f: impl Fn(LocalDefId) + DynSend + DynSync)
pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId
pub fn ty_param_name(self, def_id: LocalDefId) -> Symbol
pub fn trait_impls(self, trait_did: DefId) -> &'hir [LocalDefId]
sourcepub fn krate_attrs(self) -> &'hir [Attribute]
pub fn krate_attrs(self) -> &'hir [Attribute]
Gets the attributes on the crate. This is preferable to
invoking krate.attrs
because it registers a tighter
dep-graph access.
pub fn rustc_coherence_is_core(self) -> bool
pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId)
sourcepub fn walk_toplevel_module(self, visitor: &mut impl Visitor<'hir>)
pub fn walk_toplevel_module(self, visitor: &mut impl Visitor<'hir>)
Walks the contents of the local crate. See also visit_all_item_likes_in_crate
.
sourcepub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>)
pub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>)
Walks the attributes in a crate.
sourcepub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V)where
V: Visitor<'hir>,
pub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V)where V: Visitor<'hir>,
Visits all item-likes in the crate in some deterministic (but unspecified) order. If you
need to process every item-like, and don’t care about visiting nested items in a particular
order then this method is the best choice. If you do care about this nesting, you should
use the tcx.hir().walk_toplevel_module
.
Note that this function will access HIR for all the item-likes in the crate. If you only
need to access some of them, it is usually better to manually loop on the iterators
provided by tcx.hir_crate_items(())
.
Please see the notes in intravisit.rs
for more information.
sourcepub fn visit_item_likes_in_module<V>(
self,
module: LocalModDefId,
visitor: &mut V
)where
V: Visitor<'hir>,
pub fn visit_item_likes_in_module<V>( self, module: LocalModDefId, visitor: &mut V )where V: Visitor<'hir>,
This method is the equivalent of visit_all_item_likes_in_crate
but restricted to
item-likes in a single module.
pub fn for_each_module(self, f: impl FnMut(LocalModDefId))
pub fn par_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync)
sourcepub fn parent_id_iter(
self,
current_id: HirId
) -> impl Iterator<Item = HirId> + 'hir
pub fn parent_id_iter( self, current_id: HirId ) -> impl Iterator<Item = HirId> + 'hir
Returns an iterator for the nodes in the ancestor tree of the current_id
until the crate root is reached. Prefer this over your own loop using parent_id
.
sourcepub fn parent_iter(
self,
current_id: HirId
) -> impl Iterator<Item = (HirId, Node<'hir>)>
pub fn parent_iter( self, current_id: HirId ) -> impl Iterator<Item = (HirId, Node<'hir>)>
Returns an iterator for the nodes in the ancestor tree of the current_id
until the crate root is reached. Prefer this over your own loop using parent_id
.
sourcepub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> ⓘ
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> ⓘ
Returns an iterator for the nodes in the ancestor tree of the current_id
until the crate root is reached. Prefer this over your own loop using parent_id
.
sourcepub fn is_inside_const_context(self, hir_id: HirId) -> bool
pub fn is_inside_const_context(self, hir_id: HirId) -> bool
Whether the expression pointed at by hir_id
belongs to a const
evaluation context.
Used exclusively for diagnostics, to avoid suggestion function calls.
sourcepub fn get_return_block(self, id: HirId) -> Option<HirId>
pub fn get_return_block(self, id: HirId) -> Option<HirId>
Retrieves the HirId
for id
’s enclosing method, unless there’s a
while
or loop
before reaching it, as block tail returns are not
available in them.
fn foo(x: usize) -> bool {
if x == 1 {
true // If `get_return_block` gets passed the `id` corresponding
} else { // to this, it will return `foo`'s `HirId`.
false
}
}
fn foo(x: usize) -> bool {
loop {
true // If `get_return_block` gets passed the `id` corresponding
} // to this, it will return `None`.
false
}
sourcepub fn get_parent_item(self, hir_id: HirId) -> OwnerId
pub fn get_parent_item(self, hir_id: HirId) -> OwnerId
Retrieves the OwnerId
for id
’s parent item, or id
itself if no
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 a module, trait, or impl.
sourcepub 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>>
When on an if expression, a match arm tail expression or a match arm, give back
the enclosing if
or match
expression.
Used by error reporting when there’s a type error in an if or match arm caused by the expression needing to be unit.
sourcepub fn get_enclosing_scope(self, hir_id: HirId) -> Option<HirId>
pub fn get_enclosing_scope(self, hir_id: HirId) -> Option<HirId>
Returns the nearest enclosing scope. A scope is roughly an item or block.
sourcepub fn get_defining_scope(self, id: HirId) -> HirId
pub fn get_defining_scope(self, id: HirId) -> HirId
Returns the defining scope for an opaque type definition.
pub fn get_foreign_abi(self, hir_id: HirId) -> Abi
pub fn expect_owner(self, def_id: LocalDefId) -> OwnerNode<'hir>
pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir>
pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir>
pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir>
pub fn get_fn_output(self, def_id: LocalDefId) -> Option<&'hir FnRetTy<'hir>>
pub fn expect_variant(self, id: HirId) -> &'hir Variant<'hir>
pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir>
pub fn expect_expr(self, id: HirId) -> &'hir Expr<'hir>
fn opt_ident(self, id: HirId) -> Option<Ident>
pub(super) fn opt_ident_span(self, id: HirId) -> Option<Span>
pub fn ident(self, id: HirId) -> Ident
pub fn opt_name(self, id: HirId) -> Option<Symbol>
pub fn name(self, id: HirId) -> Symbol
sourcepub fn attrs(self, id: HirId) -> &'hir [Attribute]
pub fn attrs(self, id: HirId) -> &'hir [Attribute]
Given a node ID, gets a list of attributes associated with the AST corresponding to the node-ID.
sourcepub fn span(self, hir_id: HirId) -> Span
pub fn span(self, hir_id: HirId) -> Span
Gets the span of the definition of the specified HIR node.
This is used by tcx.def_span
.
pub fn opt_span(self, hir_id: HirId) -> Option<Span>
sourcepub fn span_with_body(self, hir_id: HirId) -> Span
pub fn span_with_body(self, hir_id: HirId) -> Span
Like hir.span()
, but includes the body of items
(instead of just the item header)
pub fn span_if_local(self, id: DefId) -> Option<Span>
pub fn res_span(self, res: Res) -> Option<Span>
sourcepub fn node_to_string(self, id: HirId) -> String
pub fn node_to_string(self, id: HirId) -> String
Get a representation of this id
for debugging purposes.
NOTE: Do NOT use this in diagnostics!
sourcepub fn opt_const_param_default_param_def_id(
self,
anon_const: HirId
) -> Option<LocalDefId>
pub fn opt_const_param_default_param_def_id( self, anon_const: HirId ) -> Option<LocalDefId>
Returns the HirId of N
in struct Foo<const N: usize = { ... }>
when
called with the HirId for the { ... }
anon const
pub fn maybe_get_struct_pattern_shorthand_field( &self, expr: &Expr<'_> ) -> Option<Symbol>
Trait Implementations§
source§impl<'hir> Map<'hir> for Map<'hir>
impl<'hir> Map<'hir> for Map<'hir>
source§fn find(&self, hir_id: HirId) -> Option<Node<'hir>>
fn find(&self, hir_id: HirId) -> Option<Node<'hir>>
Node
corresponding to id
, returning None
if cannot be found.fn body(&self, id: BodyId) -> &'hir Body<'hir>
fn item(&self, id: ItemId) -> &'hir Item<'hir>
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>
impl<'hir> Copy for Map<'hir>
Auto Trait Implementations§
impl<'hir> !RefUnwindSafe for Map<'hir>
impl<'hir> !Send for Map<'hir>
impl<'hir> !Sync for Map<'hir>
impl<'hir> Unpin for Map<'hir>
impl<'hir> !UnwindSafe for Map<'hir>
Blanket Implementations§
source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere T: Copy,
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T
fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = T> ) -> &'a mut [T]
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<'tcx, T> ToPredicate<'tcx, T> for T
impl<'tcx, T> ToPredicate<'tcx, T> for T
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle: &[QueryInfo], _guar: ErrorGuaranteed ) -> T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes