rustc_middle::hir::map

Struct 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 get_if_local(self, id: DefId) -> Option<Node<'hir>>

Source

pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'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<&'hir Body<'hir>>

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) -> &'hir Body<'hir>

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: impl Into<DefId>) -> 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: 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.

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<V>(self, visitor: &mut V) -> V::Result
where V: Visitor<'hir>,

Walks the contents of the local crate. See also visit_all_item_likes_in_crate.

Source

pub fn walk_attributes<V>(self, visitor: &mut V) -> V::Result
where V: Visitor<'hir>,

Walks the attributes in a crate.

Source

pub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V) -> V::Result
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, ) -> V::Result
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 try_par_for_each_module( self, f: impl Fn(LocalModDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, ) -> Result<(), ErrorGuaranteed>

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_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
}
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) -> ExternAbi

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_field(self, id: HirId) -> &'hir FieldDef<'hir>

Source

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

Source

pub fn expect_opaque_ty(self, id: LocalDefId) -> &'hir OpaqueTy<'hir>

Source

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

Source

pub fn opt_delegation_sig_id(self, def_id: LocalDefId) -> Option<DefId>

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 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 hir_node(&self, hir_id: HirId) -> Node<'hir>

Retrieves the Node corresponding to id.
Source§

fn hir_node_by_def_id(&self, def_id: LocalDefId) -> Node<'hir>

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> DynSend for Map<'hir>

§

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

§

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

Source§

const ALIGN: Alignment = _

Alignment of Self.
Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

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

Source§

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

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

Source§

type Output = R

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<P> IntoQueryParam<P> for P

Source§

impl<T> MaybeResult<T> for T

Source§

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

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

Source§

fn upcast(self, interner: I) -> U

Source§

impl<I, T> UpcastFrom<I, T> for T

Source§

fn upcast_from(from: T, _tcx: I) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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