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 get_if_local(self, id: DefId) -> Option<Node<'hir>>
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'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<&'hir Body<'hir>>
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<&'hir Body<'hir>>
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) -> &'hir Body<'hir>
pub fn body_owned_by(self, id: LocalDefId) -> &'hir Body<'hir>
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: impl Into<DefId>) -> BodyOwnerKind
pub fn body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind
Returns the BodyOwnerKind
of this LocalDefId
.
Panics if LocalDefId
does not have an associated body.
sourcepub fn body_const_context(
self,
def_id: impl Into<DefId>,
) -> Option<ConstContext>
pub fn body_const_context( self, def_id: impl Into<DefId>, ) -> 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<V>(self, visitor: &mut V) -> V::Resultwhere
V: Visitor<'hir>,
pub fn walk_toplevel_module<V>(self, visitor: &mut V) -> V::Resultwhere
V: Visitor<'hir>,
Walks the contents of the local crate. See also visit_all_item_likes_in_crate
.
sourcepub fn walk_attributes<V>(self, visitor: &mut V) -> V::Resultwhere
V: Visitor<'hir>,
pub fn walk_attributes<V>(self, visitor: &mut V) -> V::Resultwhere
V: Visitor<'hir>,
Walks the attributes in a crate.
sourcepub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V) -> V::Resultwhere
V: Visitor<'hir>,
pub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V) -> V::Resultwhere
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,
) -> V::Resultwhere
V: Visitor<'hir>,
pub fn visit_item_likes_in_module<V>(
self,
module: LocalModDefId,
visitor: &mut V,
) -> V::Resultwhere
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)
pub fn try_par_for_each_module( self, f: impl Fn(LocalModDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, ) -> Result<(), ErrorGuaranteed>
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_fn_id_for_return_block(self, id: HirId) -> Option<HirId>
pub fn get_fn_id_for_return_block(self, id: HirId) -> Option<HirId>
Retrieves the HirId
for id
’s enclosing function if the id
block or return is
in the “tail” position of the function, in other words if it’s likely to correspond
to the return type of the function.
fn foo(x: usize) -> bool {
if x == 1 {
true // If `get_fn_id_for_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_fn_id_for_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_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_field(self, id: HirId) -> &'hir FieldDef<'hir>
pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir>
pub fn expect_expr(self, id: HirId) -> &'hir Expr<'hir>
pub fn opt_delegation_sig_id(self, def_id: LocalDefId) -> Option<DefId>
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
.
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>
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> Freeze for Map<'hir>
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<'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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§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<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> 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_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for 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