Struct rustc_middle::hir::map::Map

source ·
pub struct Map<'hir> {
    pub(super) tcx: TyCtxt<'hir>,
}

Fields§

§tcx: TyCtxt<'hir>

Implementations§

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

Finds the id of the parent node to this one.

If calling repeatedly and iterating over parents, prefer Map::parent_iter.

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

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

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

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

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.

Given a LocalDefId, returns the BodyId associated with it, if the node is a body owner, otherwise returns None.

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

Returns the BodyOwnerKind of this LocalDefId.

Panics if LocalDefId does not have an associated body.

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.

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().

Gets the attributes on the crate. This is preferable to invoking krate.attrs because it registers a tighter dep-graph access.

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

Walks the attributes in a crate.

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.

This method is the equivalent of visit_all_item_likes_in_crate but restricted to item-likes in a single module.

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 get_parent_node.

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 get_parent_node.

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 get_parent_node.

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

Whether the expression pointed at by hir_id belongs to a const evaluation context. Used exclusively for diagnostics, to avoid suggestion function calls.

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
}

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.

Returns the OwnerId of id’s nearest module parent, or id itself if no module parent is in this map.

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.

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

Returns the defining scope for an opaque type definition.

Given a node ID, gets a list of attributes associated with the AST corresponding to the node-ID.

Gets the span of the definition of the specified HIR node. This is used by tcx.def_span.

Like hir.span(), but includes the body of items (instead of just the item header)

Get a representation of this id for debugging purposes. NOTE: Do NOT use this in diagnostics!

Returns the HirId of N in struct Foo<const N: usize = { ... }> when called with the HirId for the { ... } anon const

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Retrieves the Node corresponding to id, returning None if cannot be found.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

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