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 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<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: 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_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_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_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 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 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> 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<'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<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T
where 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 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, 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<_>>()).

§

type Output = R

§

impl<T> Filterable for T

§

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
§

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

§

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,

§

impl<T> ErasedDestructor for T
where 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