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>

source

pub fn krate(self) -> &'hir Crate<'hir>

source

pub fn root_module(self) -> &'hir Mod<'hir>

source

pub fn items(self) -> impl Iterator<Item = ItemId> + 'hir

source

pub fn module_items( self, module: LocalModDefId ) -> impl Iterator<Item = ItemId> + 'hir

source

pub fn def_key(self, def_id: LocalDefId) -> DefKey

source

pub fn def_path(self, def_id: LocalDefId) -> DefPath

source

pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash

source

pub fn local_def_id_to_hir_id(self, def_id: impl Into<LocalDefId>) -> HirId

source

pub(super) fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind>

Do not call this function directly. The query should be called.

source

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.

source

pub fn parent_id(self, hir_id: HirId) -> HirId

source

pub fn get_parent(self, hir_id: HirId) -> Node<'hir>

source

pub fn find_parent(self, hir_id: HirId) -> Option<Node<'hir>>

source

pub fn find(self, id: HirId) -> Option<Node<'hir>>

Retrieves the Node corresponding to id, returning None if cannot be found.

source

pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>>

Retrieves the Node corresponding to id, returning None if cannot be found.

source

pub fn get(self, id: HirId) -> Node<'hir>

Retrieves the Node corresponding to id, panicking if it cannot be found.

source

pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir>

Retrieves the Node corresponding to id, panicking if it cannot be found.

source

pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>>

source

pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>>

source

pub fn owner(self, id: OwnerId) -> OwnerNode<'hir>

source

pub fn item(self, id: ItemId) -> &'hir Item<'hir>

source

pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir>

source

pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir>

source

pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir>

source

pub fn body(self, id: BodyId) -> &'hir Body<'hir>

source

pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>>

source

pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>>

source

pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId

source

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.

source

pub fn body_owner_def_id(self, _: BodyId) -> LocalDefId

source

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.

source

pub fn body_owned_by(self, id: LocalDefId) -> BodyId

Given a body owner’s id, returns the BodyId associated with it.

source

pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir

source

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.

source

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.

source

pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir

Returns an iterator of the DefIds 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().

source

pub fn par_body_owners(self, f: impl Fn(LocalDefId) + DynSend + DynSync)

source

pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId

source

pub fn ty_param_name(self, def_id: LocalDefId) -> Symbol

source

pub fn trait_impls(self, trait_did: DefId) -> &'hir [LocalDefId]

source

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.

source

pub fn rustc_coherence_is_core(self) -> bool

source

pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId)

source

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.

source

pub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>)

Walks the attributes in a crate.

source

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.

source

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.

source

pub fn for_each_module(self, f: impl FnMut(LocalModDefId))

source

pub fn par_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync)

source

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.

source

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.

source

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.

source

pub fn is_lhs(self, id: HirId) -> bool

Checks if the node is left-hand side of an assignment.

source

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.

source

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
}
source

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.

source

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.

source

pub fn get_enclosing_scope(self, hir_id: HirId) -> Option<HirId>

Returns the nearest enclosing scope. A scope is roughly an item or block.

source

pub fn get_defining_scope(self, id: HirId) -> HirId

Returns the defining scope for an opaque type definition.

source

pub fn get_foreign_abi(self, hir_id: HirId) -> Abi

source

pub fn expect_owner(self, def_id: LocalDefId) -> OwnerNode<'hir>

source

pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir>

source

pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir>

source

pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir>

source

pub fn get_fn_output(self, def_id: LocalDefId) -> Option<&'hir FnRetTy<'hir>>

source

pub fn expect_variant(self, id: HirId) -> &'hir Variant<'hir>

source

pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir>

source

pub fn expect_expr(self, id: HirId) -> &'hir Expr<'hir>

source

fn opt_ident(self, id: HirId) -> Option<Ident>

source

pub(super) fn opt_ident_span(self, id: HirId) -> Option<Span>

source

pub fn ident(self, id: HirId) -> Ident

source

pub fn opt_name(self, id: HirId) -> Option<Symbol>

source

pub fn name(self, id: HirId) -> Symbol

source

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.

source

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.

source

pub fn opt_span(self, hir_id: HirId) -> Option<Span>

source

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)

source

pub fn span_if_local(self, id: DefId) -> Option<Span>

source

pub fn res_span(self, res: Res) -> Option<Span>

source

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!

source

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

source

pub fn maybe_get_struct_pattern_shorthand_field( &self, expr: &Expr<'_> ) -> Option<Symbol>

Trait Implementations§

source§

impl<'hir> Clone for Map<'hir>

source§

fn clone(&self) -> Map<'hir>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'hir> Map<'hir> for Map<'hir>

source§

fn find(&self, hir_id: HirId) -> Option<Node<'hir>>

Retrieves the Node corresponding to id, returning None if cannot be found.
source§

fn body(&self, id: BodyId) -> &'hir Body<'hir>

source§

fn item(&self, id: ItemId) -> &'hir Item<'hir>

source§

fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>

source§

fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>

source§

fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>

source§

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<T> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere T: Copy,

source§

fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut T

source§

fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = T> ) -> &'a mut [T]

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> Rwhere I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<P> IntoQueryParam<P> for P

source§

impl<T> MaybeResult<T> for T

§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<'tcx, T> ToPredicate<'tcx, T> for T

source§

fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<Tcx, T> Value<Tcx> for Twhere Tcx: DepContext,

source§

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