pub(crate) struct LoweringContext<'a, 'hir: 'a> {
Show 24 fields pub(crate) sess: &'a Session, pub(crate) resolver: &'a mut dyn ResolverAstLowering, pub(crate) nt_to_tokenstream: NtToTokenstream, pub(crate) arena: &'hir Arena<'hir>, pub(crate) bodies: Vec<(ItemLocalId, &'hir Body<'hir>)>, pub(crate) attrs: SortedMap<ItemLocalId, &'hir [Attribute]>, pub(crate) children: FxHashMap<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>, pub(crate) generator_kind: Option<GeneratorKind>, pub(crate) task_context: Option<HirId>, pub(crate) current_item: Option<Span>, pub(crate) catch_scope: Option<NodeId>, pub(crate) loop_scope: Option<NodeId>, pub(crate) is_in_loop_condition: bool, pub(crate) is_in_trait_impl: bool, pub(crate) is_in_dyn_type: bool, pub(crate) captured_lifetimes: Option<LifetimeCaptureContext>, pub(crate) current_hir_id_owner: LocalDefId, pub(crate) item_local_id_counter: ItemLocalId, pub(crate) local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>, pub(crate) trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>, pub(crate) node_id_to_local_id: FxHashMap<NodeId, ItemLocalId>, pub(crate) allow_try_trait: Option<Lrc<[Symbol]>>, pub(crate) allow_gen_future: Option<Lrc<[Symbol]>>, pub(crate) allow_into_future: Option<Lrc<[Symbol]>>,
}

Fields

sess: &'a Session

Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.

resolver: &'a mut dyn ResolverAstLoweringnt_to_tokenstream: NtToTokenstream

HACK(Centril): there is a cyclic dependency between the parser and lowering if we don’t have this function pointer. To avoid that dependency so that rustc_middle is independent of the parser, we use dynamic dispatch here.

arena: &'hir Arena<'hir>

Used to allocate HIR nodes.

bodies: Vec<(ItemLocalId, &'hir Body<'hir>)>

Bodies inside the owner being lowered.

attrs: SortedMap<ItemLocalId, &'hir [Attribute]>

Attributes inside the owner being lowered.

children: FxHashMap<LocalDefId, MaybeOwner<&'hir OwnerInfo<'hir>>>

Collect items that were created by lowering the current owner.

generator_kind: Option<GeneratorKind>task_context: Option<HirId>

When inside an async context, this is the HirId of the task_context local bound to the resume argument of the generator.

current_item: Option<Span>

Used to get the current fn’s def span to point to when using await outside of an async fn.

catch_scope: Option<NodeId>loop_scope: Option<NodeId>is_in_loop_condition: boolis_in_trait_impl: boolis_in_dyn_type: boolcaptured_lifetimes: Option<LifetimeCaptureContext>

Used to handle lifetimes appearing in impl-traits.

current_hir_id_owner: LocalDefIditem_local_id_counter: ItemLocalIdlocal_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>node_id_to_local_id: FxHashMap<NodeId, ItemLocalId>

NodeIds that are lowered inside the current HIR owner.

allow_try_trait: Option<Lrc<[Symbol]>>allow_gen_future: Option<Lrc<[Symbol]>>allow_into_future: Option<Lrc<[Symbol]>>

Implementations

Desugar try { <stmts>; <expr> } into { <stmts>; ::std::ops::Try::from_output(<expr>) }, try { <stmts>; } into { <stmts>; ::std::ops::Try::from_output(()) } and save the block id to use it as a break target for desugaring of the ? operator.

Lower an async construct to a generator that is then wrapped so it implements Future.

This results in:

std::future::from_generator(static move? |_task_context| -> <ret_ty> {
    <body>
})

Desugar <expr>.await into:

match ::std::future::IntoFuture::into_future(<expr>) {
    mut __awaitee => loop {
        match unsafe { ::std::future::Future::poll(
            <::std::pin::Pin>::new_unchecked(&mut __awaitee),
            ::std::future::get_context(task_context),
        ) } {
            ::std::task::Poll::Ready(result) => break result,
            ::std::task::Poll::Pending => {}
        }
        task_context = yield ();
    }
}

Destructure the LHS of complex assignments. For instance, lower (a, b) = t to { let (lhs1, lhs2) = t; a = lhs1; b = lhs2; }.

If the given expression is a path to a tuple struct, returns that path. It is not a complete check, but just tries to reject most paths early if they are not tuple structs. Type checking will take care of the full validation later.

If the given expression is a path to a unit struct, returns that path. It is not a complete check, but just tries to reject most paths early if they are not unit structs. Type checking will take care of the full validation later.

Convert the LHS of a destructuring assignment to a pattern. Each sub-assignment is recorded in assignments.

Destructure a sequence of expressions occurring on the LHS of an assignment. Such a sequence occurs in a tuple (struct)/slice. Return a sequence of corresponding patterns, and the index and the span of .. if it exists. Each sub-assignment is recorded in assignments.

Desugar <start>..=<end> into std::ops::RangeInclusive::new(<start>, <end>).

Desugar ExprForLoop from: [opt_ident]: for <pat> in <head> <body> into:

{
    let result = match IntoIterator::into_iter(<head>) {
        mut iter => {
            [opt_ident]: loop {
                match Iterator::next(&mut iter) {
                    None => break,
                    Some(<pat>) => <body>,
                };
            }
        }
    };
    result
}

Desugar ExprKind::Try from: <expr>? into:

match Try::branch(<expr>) {
    ControlFlow::Continue(val) => #[allow(unreachable_code)] val,,
    ControlFlow::Break(residual) =>
        #[allow(unreachable_code)]
        // If there is an enclosing `try {...}`:
        break 'catch_target Try::from_residual(residual),
        // Otherwise:
        return Try::from_residual(residual),
}

Desugar ExprKind::Yeet from: do yeet <expr> into:

// If there is an enclosing `try {...}`:
break 'catch_target FromResidual::from_residual(Yeet(residual)),
// Otherwise:
return FromResidual::from_residual(Yeet(residual)),

But to simplify this, there’s a from_yeet lang item function which handles the combined FromResidual::from_residual(Yeet(residual)).

Wrap the given expr in a terminating scope using hir::ExprKind::DropTemps.

In terms of drop order, it has the same effect as wrapping expr in { let _t = $expr; _t } but should provide better compile-time performance.

The drop order can be important in e.g. if expr { .. }.

Construct ExprKind::Err for the given span.

Lower a slice pattern of form [pat_0, ..., pat_n] into hir::PatKind::Slice(before, slice, after).

When encountering ($binding_mode $ident @)? .. (slice), this is interpreted as a sub-slice pattern semantically. Patterns that follow, which are not like slice – or an error occurs, are in after.

Construct a Pat with the HirId of p.id lowered.

Emit a friendly error for extra .. patterns in a tuple/tuple struct/slice pattern.

Used to ban the .. pattern in places it shouldn’t be semantically.

Matches '-' lit | lit (cf. parser::Parser::parse_literal_maybe_minus), or paths for ranges.

An associated type binding Output = $ty.

Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate queries which depend on the full HIR tree and those which only depend on the item signature.

This method allocates a new HirId for the given NodeId and stores it in the LoweringContext’s NodeId => HirId map. Take care not to call this method if the resulting HirId is then not actually used in the HIR, as that would trigger an assertion in the HirIdValidator later on, which makes sure that all NodeIds got mapped properly. Calling the method twice with the same NodeId is fine though.

Reuses the span but adds information like the kind of the desugaring and features that are allowed inside this span.

Intercept all spans entering HIR. Mark a span as relative to the current owning item.

Converts a lifetime into a new generic parameter.

Creates a new hir::GenericParam for every new Fresh lifetime and universal impl Trait type parameter encountered while evaluating f. Definitions are created with the provided parent_def_id.

Setup lifetime capture for and impl-trait. The captures will be added to captures.

Register a binder to be ignored for lifetime capture.

Given an associated type constraint like one of these:

T: Iterator<Item: Debug>
            ^^^^^^^^^^^
T: Iterator<Item = Debug>
            ^^^^^^^^^^^^

returns a hir::TypeBinding representing Item.

Registers a new opaque type with the proper NodeIds and returns the lowered node-ID for the opaque type.

Transforms -> T into Future<Output = T>.

Lowers a block directly to an expression, presuming that it has no attributes and is not targeted by a break.

Invoked to create the lifetime argument(s) for an elided trait object bound, like the bound in Box<dyn Debug>. This method is not invoked when the bound is written, even if it is written with '_ like in Box<dyn Debug + '_>. In those cases, lower_lifetime is invoked.

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 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: 368 bytes