Struct rustc_ast_lowering::LoweringContext
source · [−]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 ResolverAstLowering
nt_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: bool
is_in_trait_impl: bool
is_in_dyn_type: bool
captured_lifetimes: Option<LifetimeCaptureContext>
Used to handle lifetimes appearing in impl-traits.
current_hir_id_owner: LocalDefId
item_local_id_counter: ItemLocalId
local_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
sourceimpl<'a, 'hir> LoweringContext<'a, 'hir>
impl<'a, 'hir> LoweringContext<'a, 'hir>
pub(crate) fn lower_inline_asm(
&mut self,
sp: Span,
asm: &InlineAsm
) -> &'hir InlineAsm<'hir>
sourceimpl<'a, 'hir> LoweringContext<'a, 'hir>
impl<'a, 'hir> LoweringContext<'a, 'hir>
pub(crate) fn lower_block(
&mut self,
b: &Block,
targeted_by_break: bool
) -> &'hir Block<'hir>
pub(crate) fn lower_block_noalloc(
&mut self,
b: &Block,
targeted_by_break: bool
) -> Block<'hir>
fn lower_stmts(
&mut self,
ast_stmts: &[Stmt]
) -> (&'hir [Stmt<'hir>], Option<&'hir Expr<'hir>>)
fn lower_local(&mut self, l: &Local) -> &'hir Local<'hir>
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> BlockCheckMode
fn lower_let_else(
&mut self,
stmt_hir_id: HirId,
local: &Local,
init: &Expr,
els: &Block,
tail: &[Stmt]
) -> &'hir Expr<'hir>
sourceimpl<'hir> LoweringContext<'_, 'hir>
impl<'hir> LoweringContext<'_, 'hir>
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [Expr<'hir>]
pub(crate) fn lower_expr(&mut self, e: &Expr) -> &'hir Expr<'hir>
pub(crate) fn lower_expr_mut(&mut self, e: &Expr) -> Expr<'hir>
fn lower_unop(&mut self, u: UnOp) -> UnOp
fn lower_binop(&mut self, b: BinOp) -> BinOp
fn lower_legacy_const_generics(
&mut self,
f: Expr,
args: Vec<AstP<Expr>>,
legacy_args_idx: &[usize]
) -> ExprKind<'hir>
fn lower_expr_if(
&mut self,
cond: &Expr,
then: &Block,
else_opt: Option<&Expr>
) -> ExprKind<'hir>
fn manage_let_cond(&mut self, cond: &'hir Expr<'hir>) -> &'hir Expr<'hir>
fn lower_expr_while_in_loop_scope(
&mut self,
span: Span,
cond: &Expr,
body: &Block,
opt_label: Option<Label>
) -> ExprKind<'hir>
sourcefn lower_expr_try_block(&mut self, body: &Block) -> ExprKind<'hir>
fn lower_expr_try_block(&mut self, body: &Block) -> ExprKind<'hir>
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.
fn wrap_in_try_constructor(
&mut self,
lang_item: LangItem,
method_span: Span,
expr: &'hir Expr<'hir>,
overall_span: Span
) -> &'hir Expr<'hir>
fn lower_arm(&mut self, arm: &Arm) -> Arm<'hir>
sourcepub(crate) fn make_async_expr(
&mut self,
capture_clause: CaptureBy,
closure_node_id: NodeId,
ret_ty: Option<AstP<Ty>>,
span: Span,
async_gen_kind: AsyncGeneratorKind,
body: impl FnOnce(&mut Self) -> Expr<'hir>
) -> ExprKind<'hir>
pub(crate) fn make_async_expr(
&mut self,
capture_clause: CaptureBy,
closure_node_id: NodeId,
ret_ty: Option<AstP<Ty>>,
span: Span,
async_gen_kind: AsyncGeneratorKind,
body: impl FnOnce(&mut Self) -> Expr<'hir>
) -> ExprKind<'hir>
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>
})
sourcefn lower_expr_await(
&mut self,
dot_await_span: Span,
expr: &Expr
) -> ExprKind<'hir>
fn lower_expr_await(
&mut self,
dot_await_span: Span,
expr: &Expr
) -> ExprKind<'hir>
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 ();
}
}
fn lower_expr_closure(
&mut self,
capture_clause: CaptureBy,
movability: Movability,
decl: &FnDecl,
body: &Expr,
fn_decl_span: Span
) -> ExprKind<'hir>
fn generator_movability_for_fn(
&mut self,
decl: &FnDecl,
fn_decl_span: Span,
generator_kind: Option<GeneratorKind>,
movability: Movability
) -> Option<Movability>
fn lower_expr_async_closure(
&mut self,
capture_clause: CaptureBy,
closure_id: NodeId,
decl: &FnDecl,
body: &Expr,
fn_decl_span: Span
) -> ExprKind<'hir>
sourcefn lower_expr_assign(
&mut self,
lhs: &Expr,
rhs: &Expr,
eq_sign_span: Span,
whole_span: Span
) -> ExprKind<'hir>
fn lower_expr_assign(
&mut self,
lhs: &Expr,
rhs: &Expr,
eq_sign_span: Span,
whole_span: Span
) -> ExprKind<'hir>
Destructure the LHS of complex assignments.
For instance, lower (a, b) = t
to { let (lhs1, lhs2) = t; a = lhs1; b = lhs2; }
.
sourcefn extract_tuple_struct_path<'a>(
&mut self,
expr: &'a Expr
) -> Option<(&'a Option<QSelf>, &'a Path)>
fn extract_tuple_struct_path<'a>(
&mut self,
expr: &'a Expr
) -> Option<(&'a Option<QSelf>, &'a Path)>
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.
sourcefn extract_unit_struct_path<'a>(
&mut self,
expr: &'a Expr
) -> Option<(&'a Option<QSelf>, &'a Path)>
fn extract_unit_struct_path<'a>(
&mut self,
expr: &'a Expr
) -> Option<(&'a Option<QSelf>, &'a Path)>
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.
sourcefn destructure_assign(
&mut self,
lhs: &Expr,
eq_sign_span: Span,
assignments: &mut Vec<Stmt<'hir>>
) -> &'hir Pat<'hir>
fn destructure_assign(
&mut self,
lhs: &Expr,
eq_sign_span: Span,
assignments: &mut Vec<Stmt<'hir>>
) -> &'hir Pat<'hir>
Convert the LHS of a destructuring assignment to a pattern.
Each sub-assignment is recorded in assignments
.
fn destructure_assign_mut(
&mut self,
lhs: &Expr,
eq_sign_span: Span,
assignments: &mut Vec<Stmt<'hir>>
) -> Pat<'hir>
sourcefn destructure_sequence(
&mut self,
elements: &[AstP<Expr>],
ctx: &str,
eq_sign_span: Span,
assignments: &mut Vec<Stmt<'hir>>
) -> (&'hir [Pat<'hir>], Option<(usize, Span)>)
fn destructure_sequence(
&mut self,
elements: &[AstP<Expr>],
ctx: &str,
eq_sign_span: Span,
assignments: &mut Vec<Stmt<'hir>>
) -> (&'hir [Pat<'hir>], Option<(usize, Span)>)
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
.
sourcefn lower_expr_range_closed(
&mut self,
span: Span,
e1: &Expr,
e2: &Expr
) -> ExprKind<'hir>
fn lower_expr_range_closed(
&mut self,
span: Span,
e1: &Expr,
e2: &Expr
) -> ExprKind<'hir>
Desugar <start>..=<end>
into std::ops::RangeInclusive::new(<start>, <end>)
.
fn lower_expr_range(
&mut self,
span: Span,
e1: Option<&Expr>,
e2: Option<&Expr>,
lims: RangeLimits
) -> ExprKind<'hir>
fn lower_label(&self, opt_label: Option<Label>) -> Option<Label>
fn lower_loop_destination(
&mut self,
destination: Option<(NodeId, Label)>
) -> Destination
fn lower_jump_destination(
&mut self,
id: NodeId,
opt_label: Option<Label>
) -> Destination
fn with_catch_scope<T>(
&mut self,
catch_id: NodeId,
f: impl FnOnce(&mut Self) -> T
) -> T
fn with_loop_scope<T>(
&mut self,
loop_id: NodeId,
f: impl FnOnce(&mut Self) -> T
) -> T
fn with_loop_condition_scope<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T
fn lower_expr_field(&mut self, f: &ExprField) -> ExprField<'hir>
fn lower_expr_yield(
&mut self,
span: Span,
opt_expr: Option<&Expr>
) -> ExprKind<'hir>
sourcefn lower_expr_for(
&mut self,
e: &Expr,
pat: &Pat,
head: &Expr,
body: &Block,
opt_label: Option<Label>
) -> Expr<'hir>
fn lower_expr_for(
&mut self,
e: &Expr,
pat: &Pat,
head: &Expr,
body: &Block,
opt_label: Option<Label>
) -> Expr<'hir>
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
}
sourcefn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> ExprKind<'hir>
fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> ExprKind<'hir>
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),
}
sourcefn lower_expr_yeet(
&mut self,
span: Span,
sub_expr: Option<&Expr>
) -> ExprKind<'hir>
fn lower_expr_yeet(
&mut self,
span: Span,
sub_expr: Option<&Expr>
) -> ExprKind<'hir>
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))
.
sourcepub(crate) fn expr_drop_temps(
&mut self,
span: Span,
expr: &'hir Expr<'hir>,
attrs: AttrVec
) -> &'hir Expr<'hir>
pub(crate) fn expr_drop_temps(
&mut self,
span: Span,
expr: &'hir Expr<'hir>,
attrs: AttrVec
) -> &'hir Expr<'hir>
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 { .. }
.
pub(crate) fn expr_drop_temps_mut(
&mut self,
span: Span,
expr: &'hir Expr<'hir>,
attrs: AttrVec
) -> Expr<'hir>
fn expr_match(
&mut self,
span: Span,
arg: &'hir Expr<'hir>,
arms: &'hir [Arm<'hir>],
source: MatchSource
) -> Expr<'hir>
fn expr_break(&mut self, span: Span, attrs: AttrVec) -> Expr<'hir>
fn expr_break_alloc(&mut self, span: Span, attrs: AttrVec) -> &'hir Expr<'hir>
fn expr_mut_addr_of(&mut self, span: Span, e: &'hir Expr<'hir>) -> Expr<'hir>
fn expr_unit(&mut self, sp: Span) -> &'hir Expr<'hir>
fn expr_call_mut(
&mut self,
span: Span,
e: &'hir Expr<'hir>,
args: &'hir [Expr<'hir>]
) -> Expr<'hir>
fn expr_call(
&mut self,
span: Span,
e: &'hir Expr<'hir>,
args: &'hir [Expr<'hir>]
) -> &'hir Expr<'hir>
fn expr_call_lang_item_fn_mut(
&mut self,
span: Span,
lang_item: LangItem,
args: &'hir [Expr<'hir>],
hir_id: Option<HirId>
) -> Expr<'hir>
fn expr_call_lang_item_fn(
&mut self,
span: Span,
lang_item: LangItem,
args: &'hir [Expr<'hir>],
hir_id: Option<HirId>
) -> &'hir Expr<'hir>
fn expr_lang_item_path(
&mut self,
span: Span,
lang_item: LangItem,
attrs: AttrVec,
hir_id: Option<HirId>
) -> Expr<'hir>
pub(crate) fn expr_ident(
&mut self,
sp: Span,
ident: Ident,
binding: HirId
) -> &'hir Expr<'hir>
pub(crate) fn expr_ident_mut(
&mut self,
sp: Span,
ident: Ident,
binding: HirId
) -> Expr<'hir>
fn expr_ident_with_attrs(
&mut self,
span: Span,
ident: Ident,
binding: HirId,
attrs: AttrVec
) -> Expr<'hir>
fn expr_unsafe(&mut self, expr: &'hir Expr<'hir>) -> Expr<'hir>
fn expr_block_empty(&mut self, span: Span) -> &'hir Expr<'hir>
pub(crate) fn expr_block(
&mut self,
b: &'hir Block<'hir>,
attrs: AttrVec
) -> Expr<'hir>
pub(crate) fn expr(
&mut self,
span: Span,
kind: ExprKind<'hir>,
attrs: AttrVec
) -> Expr<'hir>
fn expr_field(
&mut self,
ident: Ident,
expr: &'hir Expr<'hir>,
span: Span
) -> ExprField<'hir>
fn arm(&mut self, pat: &'hir Pat<'hir>, expr: &'hir Expr<'hir>) -> Arm<'hir>
sourceimpl<'hir> LoweringContext<'_, 'hir>
impl<'hir> LoweringContext<'_, 'hir>
pub(crate) fn lower_mod(
&mut self,
items: &[P<Item>],
spans: &ModSpans
) -> Mod<'hir>
pub(crate) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[ItemId; 1]>
fn lower_item_id_use_tree(
&mut self,
tree: &UseTree,
base_id: NodeId,
vec: &mut SmallVec<[ItemId; 1]>
)
fn lower_item(&mut self, i: &Item) -> &'hir Item<'hir>
fn lower_item_kind(
&mut self,
span: Span,
id: NodeId,
hir_id: HirId,
ident: &mut Ident,
attrs: Option<&'hir [Attribute]>,
vis_span: Span,
i: &ItemKind
) -> ItemKind<'hir>
fn lower_const_item(
&mut self,
ty: &Ty,
span: Span,
body: Option<&Expr>
) -> (&'hir Ty<'hir>, BodyId)
fn lower_use_tree(
&mut self,
tree: &UseTree,
prefix: &Path,
id: NodeId,
vis_span: Span,
ident: &mut Ident,
attrs: Option<&'hir [Attribute]>
) -> ItemKind<'hir>
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir ForeignItem<'hir>
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> ForeignItemRef
fn lower_variant(&mut self, v: &Variant) -> Variant<'hir>
fn lower_variant_data(
&mut self,
parent_id: HirId,
vdata: &VariantData
) -> VariantData<'hir>
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> FieldDef<'hir>
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir TraitItem<'hir>
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> TraitItemRef
sourcepub(crate) fn expr_err(&mut self, span: Span) -> Expr<'hir>
pub(crate) fn expr_err(&mut self, span: Span) -> Expr<'hir>
Construct ExprKind::Err
for the given span
.
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir ImplItem<'hir>
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> ImplItemRef
fn lower_defaultness(
&self,
d: Defaultness,
has_value: bool
) -> (Defaultness, Option<Span>)
fn record_body(
&mut self,
params: &'hir [Param<'hir>],
value: Expr<'hir>
) -> BodyId
pub(crate) fn lower_body(
&mut self,
f: impl FnOnce(&mut Self) -> (&'hir [Param<'hir>], Expr<'hir>)
) -> BodyId
fn lower_param(&mut self, param: &Param) -> Param<'hir>
pub(crate) fn lower_fn_body(
&mut self,
decl: &FnDecl,
body: impl FnOnce(&mut Self) -> Expr<'hir>
) -> BodyId
fn lower_fn_body_block(
&mut self,
span: Span,
decl: &FnDecl,
body: Option<&Block>
) -> BodyId
fn lower_block_expr_opt(
&mut self,
span: Span,
block: Option<&Block>
) -> Expr<'hir>
pub(crate) fn lower_const_body(
&mut self,
span: Span,
expr: Option<&Expr>
) -> BodyId
fn lower_maybe_async_body(
&mut self,
span: Span,
decl: &FnDecl,
asyncness: Async,
body: Option<&Block>
) -> BodyId
fn lower_method_sig(
&mut self,
generics: &Generics,
sig: &FnSig,
id: NodeId,
kind: FnDeclKind,
is_async: Option<NodeId>
) -> (&'hir Generics<'hir>, FnSig<'hir>)
fn lower_fn_header(&mut self, h: FnHeader) -> FnHeader
pub(crate) fn lower_abi(&mut self, abi: StrLit) -> Abi
pub(crate) fn lower_extern(&mut self, ext: Extern) -> Abi
fn error_on_invalid_abi(&self, abi: StrLit)
fn lower_asyncness(&mut self, a: Async) -> IsAsync
fn lower_constness(&mut self, c: Const) -> Constness
pub(crate) fn lower_unsafety(&mut self, u: Unsafe) -> Unsafety
pub(crate) fn lower_generics_mut(
&mut self,
generics: &Generics,
itctx: ImplTraitContext<'_, 'hir>
) -> GenericsCtor<'hir>
pub(crate) fn lower_generics(
&mut self,
generics: &Generics,
itctx: ImplTraitContext<'_, 'hir>
) -> &'hir Generics<'hir>
pub(crate) fn lower_generic_bound_predicate(
&mut self,
ident: Ident,
id: NodeId,
kind: &GenericParamKind,
bounds: &'hir [GenericBound<'hir>],
origin: PredicateOrigin
) -> Option<WherePredicate<'hir>>
fn lower_where_predicate(
&mut self,
pred: &WherePredicate
) -> WherePredicate<'hir>
sourceimpl<'a, 'hir> LoweringContext<'a, 'hir>
impl<'a, 'hir> LoweringContext<'a, 'hir>
pub(crate) fn lower_pat(&mut self, pattern: &Pat) -> &'hir Pat<'hir>
pub(crate) fn lower_pat_mut(&mut self, pattern: &Pat) -> Pat<'hir>
fn lower_pat_tuple(
&mut self,
pats: &[P<Pat>],
ctx: &str
) -> (&'hir [Pat<'hir>], Option<usize>)
sourcefn lower_pat_slice(&mut self, pats: &[P<Pat>]) -> PatKind<'hir>
fn lower_pat_slice(&mut self, pats: &[P<Pat>]) -> PatKind<'hir>
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
.
fn lower_pat_ident(
&mut self,
p: &Pat,
binding_mode: &BindingMode,
ident: Ident,
lower_sub: impl FnOnce(&mut Self) -> Option<&'hir Pat<'hir>>
) -> PatKind<'hir>
fn lower_binding_mode(&mut self, b: &BindingMode) -> BindingAnnotation
fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> &'hir Pat<'hir>
sourcefn pat_with_node_id_of(&mut self, p: &Pat, kind: PatKind<'hir>) -> Pat<'hir>
fn pat_with_node_id_of(&mut self, p: &Pat, kind: PatKind<'hir>) -> Pat<'hir>
Construct a Pat
with the HirId
of p.id
lowered.
sourcepub(crate) fn ban_extra_rest_pat(&self, sp: Span, prev_sp: Span, ctx: &str)
pub(crate) fn ban_extra_rest_pat(&self, sp: Span, prev_sp: Span, ctx: &str)
Emit a friendly error for extra ..
patterns in a tuple/tuple struct/slice pattern.
sourcefn ban_illegal_rest_pat(&self, sp: Span) -> PatKind<'hir>
fn ban_illegal_rest_pat(&self, sp: Span) -> PatKind<'hir>
Used to ban the ..
pattern in places it shouldn’t be semantically.
fn lower_range_end(&mut self, e: &RangeEnd, has_end: bool) -> RangeEnd
sourcefn lower_expr_within_pat(
&mut self,
expr: &Expr,
allow_paths: bool
) -> &'hir Expr<'hir>
fn lower_expr_within_pat(
&mut self,
expr: &Expr,
allow_paths: bool
) -> &'hir Expr<'hir>
Matches '-' lit | lit (cf. parser::Parser::parse_literal_maybe_minus)
,
or paths for ranges.
sourceimpl<'a, 'hir> LoweringContext<'a, 'hir>
impl<'a, 'hir> LoweringContext<'a, 'hir>
pub(crate) fn lower_qpath(
&mut self,
id: NodeId,
qself: &Option<QSelf>,
p: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext<'_, 'hir>
) -> QPath<'hir>
pub(crate) fn lower_path_extra(
&mut self,
res: Res,
p: &Path,
param_mode: ParamMode
) -> &'hir Path<'hir>
pub(crate) fn lower_path(
&mut self,
id: NodeId,
p: &Path,
param_mode: ParamMode
) -> &'hir Path<'hir>
pub(crate) fn lower_path_segment(
&mut self,
path_span: Span,
segment: &PathSegment,
param_mode: ParamMode,
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext<'_, 'hir>
) -> PathSegment<'hir>
fn maybe_insert_elided_lifetimes_in_path(
&mut self,
path_span: Span,
segment_id: NodeId,
segment_ident_span: Span,
generic_args: &mut GenericArgsCtor<'hir>
)
pub(crate) fn lower_angle_bracketed_parameter_data(
&mut self,
data: &AngleBracketedArgs,
param_mode: ParamMode,
itctx: ImplTraitContext<'_, 'hir>
) -> (GenericArgsCtor<'hir>, bool)
fn lower_parenthesized_parameter_data(
&mut self,
id: NodeId,
data: &ParenthesizedArgs
) -> (GenericArgsCtor<'hir>, bool)
sourcepub(crate) fn output_ty_binding(
&mut self,
span: Span,
ty: &'hir Ty<'hir>
) -> TypeBinding<'hir>
pub(crate) fn output_ty_binding(
&mut self,
span: Span,
ty: &'hir Ty<'hir>
) -> TypeBinding<'hir>
An associated type binding Output = $ty
.
sourceimpl<'a, 'hir> LoweringContext<'a, 'hir>
impl<'a, 'hir> LoweringContext<'a, 'hir>
pub(crate) fn with_hir_id_owner(
&mut self,
owner: NodeId,
f: impl FnOnce(&mut Self) -> OwnerNode<'hir>
)
pub(crate) fn make_owner_info(
&mut self,
node: OwnerNode<'hir>
) -> &'hir OwnerInfo<'hir>
sourcepub(crate) fn hash_owner(
&mut self,
node: OwnerNode<'hir>,
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>
) -> (Fingerprint, Fingerprint)
pub(crate) fn hash_owner(
&mut self,
node: OwnerNode<'hir>,
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>
) -> (Fingerprint, Fingerprint)
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.
sourcepub(crate) fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId
pub(crate) fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId
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 NodeId
s got mapped
properly. Calling the method twice with the same NodeId
is fine though.
pub(crate) fn next_id(&mut self) -> HirId
pub(crate) fn lower_res(&mut self, res: Res<NodeId>) -> Res
pub(crate) fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId>
pub(crate) fn expect_full_res_from_use(
&mut self,
id: NodeId
) -> impl Iterator<Item = Res<NodeId>>
pub(crate) fn diagnostic(&self) -> &Handler
sourcepub(crate) fn mark_span_with_reason(
&self,
reason: DesugaringKind,
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>
) -> Span
pub(crate) fn mark_span_with_reason(
&self,
reason: DesugaringKind,
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>
) -> Span
Reuses the span but adds information like the kind of the desugaring and features that are allowed inside this span.
sourcepub(crate) fn lower_span(&self, span: Span) -> Span
pub(crate) fn lower_span(&self, span: Span) -> Span
Intercept all spans entering HIR. Mark a span as relative to the current owning item.
pub(crate) fn lower_ident(&self, ident: Ident) -> Ident
sourcepub(crate) fn lifetime_res_to_generic_param(
&mut self,
ident: Ident,
node_id: NodeId,
res: LifetimeRes
) -> Option<GenericParam<'hir>>
pub(crate) fn lifetime_res_to_generic_param(
&mut self,
ident: Ident,
node_id: NodeId,
res: LifetimeRes
) -> Option<GenericParam<'hir>>
Converts a lifetime into a new generic parameter.
sourcepub(crate) fn add_implicit_generics<T>(
&mut self,
generics: &Generics,
parent_node_id: NodeId,
f: impl FnOnce(&mut Self, &mut Vec<GenericParam<'hir>>, &mut Vec<WherePredicate<'hir>>) -> T
) -> (&'hir Generics<'hir>, T)
pub(crate) fn add_implicit_generics<T>(
&mut self,
generics: &Generics,
parent_node_id: NodeId,
f: impl FnOnce(&mut Self, &mut Vec<GenericParam<'hir>>, &mut Vec<WherePredicate<'hir>>) -> T
) -> (&'hir Generics<'hir>, T)
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
.
sourcepub(crate) fn while_capturing_lifetimes<T>(
&mut self,
parent_def_id: LocalDefId,
captures: &mut FxHashMap<LocalDefId, (Span, NodeId, ParamName, LifetimeRes)>,
f: impl FnOnce(&mut Self) -> T
) -> T
pub(crate) fn while_capturing_lifetimes<T>(
&mut self,
parent_def_id: LocalDefId,
captures: &mut FxHashMap<LocalDefId, (Span, NodeId, ParamName, LifetimeRes)>,
f: impl FnOnce(&mut Self) -> T
) -> T
Setup lifetime capture for and impl-trait.
The captures will be added to captures
.
sourcepub(crate) fn with_lifetime_binder<T>(
&mut self,
binder: NodeId,
f: impl FnOnce(&mut Self) -> T
) -> T
pub(crate) fn with_lifetime_binder<T>(
&mut self,
binder: NodeId,
f: impl FnOnce(&mut Self) -> T
) -> T
Register a binder to be ignored for lifetime capture.
pub(crate) fn with_dyn_type_scope<T>(
&mut self,
in_scope: bool,
f: impl FnOnce(&mut Self) -> T
) -> T
pub(crate) fn with_new_scopes<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T
pub(crate) fn lower_attrs(
&mut self,
id: HirId,
attrs: &[Attribute]
) -> Option<&'hir [Attribute]>
pub(crate) fn lower_attr(&self, attr: &Attribute) -> Attribute
pub(crate) fn alias_attrs(&mut self, id: HirId, target_id: HirId)
pub(crate) fn lower_mac_args(&self, args: &MacArgs) -> MacArgs
pub(crate) fn lower_token_stream(
&self,
tokens: TokenStream,
synthesize_tokens: CanSynthesizeMissingTokens
) -> TokenStream
sourcepub(crate) fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocConstraint,
itctx: ImplTraitContext<'_, 'hir>
) -> TypeBinding<'hir>
pub(crate) fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocConstraint,
itctx: ImplTraitContext<'_, 'hir>
) -> TypeBinding<'hir>
Given an associated type constraint like one of these:
T: Iterator<Item: Debug>
^^^^^^^^^^^
T: Iterator<Item = Debug>
^^^^^^^^^^^^
returns a hir::TypeBinding
representing Item
.
pub(crate) fn lower_generic_arg(
&mut self,
arg: &GenericArg,
itctx: ImplTraitContext<'_, 'hir>
) -> GenericArg<'hir>
pub(crate) fn lower_ty(
&mut self,
t: &Ty,
itctx: ImplTraitContext<'_, 'hir>
) -> &'hir Ty<'hir>
pub(crate) fn lower_path_ty(
&mut self,
t: &Ty,
qself: &Option<QSelf>,
path: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext<'_, 'hir>
) -> Ty<'hir>
pub(crate) fn ty(&mut self, span: Span, kind: TyKind<'hir>) -> Ty<'hir>
pub(crate) fn ty_tup(&mut self, span: Span, tys: &'hir [Ty<'hir>]) -> Ty<'hir>
pub(crate) fn lower_ty_direct(
&mut self,
t: &Ty,
itctx: ImplTraitContext<'_, 'hir>
) -> Ty<'hir>
pub(crate) fn lower_opaque_impl_trait(
&mut self,
span: Span,
origin: OpaqueTyOrigin,
opaque_ty_node_id: NodeId,
lower_bounds: impl FnOnce(&mut Self) -> GenericBounds<'hir>
) -> TyKind<'hir>
sourcepub(crate) fn generate_opaque_type(
&mut self,
opaque_ty_id: LocalDefId,
opaque_ty_item: OpaqueTy<'hir>,
span: Span,
opaque_ty_span: Span
) -> OwnerNode<'hir>
pub(crate) fn generate_opaque_type(
&mut self,
opaque_ty_id: LocalDefId,
opaque_ty_item: OpaqueTy<'hir>,
span: Span,
opaque_ty_span: Span
) -> OwnerNode<'hir>
Registers a new opaque type with the proper NodeId
s and
returns the lowered node-ID for the opaque type.
pub(crate) fn lower_fn_params_to_names(
&mut self,
decl: &FnDecl
) -> &'hir [Ident]
pub(crate) fn lower_fn_decl(
&mut self,
decl: &FnDecl,
in_band_ty_params: Option<(NodeId, &mut Vec<GenericParam<'hir>>, &mut Vec<WherePredicate<'hir>>)>,
kind: FnDeclKind,
make_ret_async: Option<NodeId>
) -> &'hir FnDecl<'hir>
pub(crate) fn lower_async_fn_ret_ty(
&mut self,
output: &FnRetTy,
fn_node_id: NodeId,
opaque_ty_node_id: NodeId
) -> FnRetTy<'hir>
sourcepub(crate) fn lower_async_fn_output_type_to_future_bound(
&mut self,
output: &FnRetTy,
fn_def_id: LocalDefId,
span: Span
) -> GenericBound<'hir>
pub(crate) fn lower_async_fn_output_type_to_future_bound(
&mut self,
output: &FnRetTy,
fn_def_id: LocalDefId,
span: Span
) -> GenericBound<'hir>
Transforms -> T
into Future<Output = T>
.
pub(crate) fn lower_param_bound(
&mut self,
tpb: &GenericBound,
itctx: ImplTraitContext<'_, 'hir>
) -> GenericBound<'hir>
pub(crate) fn lower_lifetime(&mut self, l: &Lifetime) -> Lifetime
pub(crate) fn new_named_lifetime_with_res(
&mut self,
id: NodeId,
span: Span,
ident: Ident,
res: LifetimeRes
) -> Lifetime
pub(crate) fn lower_generic_params_mut<'s>(
&'s mut self,
params: &'s [GenericParam]
) -> impl Iterator<Item = GenericParam<'hir>> + Captures<'a> + Captures<'s>
pub(crate) fn lower_generic_params(
&mut self,
params: &[GenericParam]
) -> &'hir [GenericParam<'hir>]
pub(crate) fn lower_generic_param(
&mut self,
param: &GenericParam
) -> GenericParam<'hir>
pub(crate) fn lower_trait_ref(
&mut self,
p: &TraitRef,
itctx: ImplTraitContext<'_, 'hir>
) -> TraitRef<'hir>
pub(crate) fn lower_poly_trait_ref(
&mut self,
p: &PolyTraitRef,
itctx: ImplTraitContext<'_, 'hir>
) -> PolyTraitRef<'hir>
pub(crate) fn lower_mt(
&mut self,
mt: &MutTy,
itctx: ImplTraitContext<'_, 'hir>
) -> MutTy<'hir>
pub(crate) fn lower_param_bounds(
&mut self,
bounds: &[GenericBound],
itctx: ImplTraitContext<'_, 'hir>
) -> GenericBounds<'hir>
pub(crate) fn lower_param_bounds_mut<'s>(
&'s mut self,
bounds: &'s [GenericBound],
itctx: ImplTraitContext<'s, 'hir>
) -> impl Iterator<Item = GenericBound<'hir>> + Captures<'s> + Captures<'a>
sourcepub(crate) fn lower_block_expr(&mut self, b: &Block) -> Expr<'hir>
pub(crate) fn lower_block_expr(&mut self, b: &Block) -> Expr<'hir>
Lowers a block directly to an expression, presuming that it
has no attributes and is not targeted by a break
.
pub(crate) fn lower_array_length(&mut self, c: &AnonConst) -> ArrayLen
pub(crate) fn lower_anon_const(&mut self, c: &AnonConst) -> AnonConst
pub(crate) fn lower_unsafe_source(&mut self, u: UnsafeSource) -> UnsafeSource
pub(crate) fn lower_trait_bound_modifier(
&mut self,
f: TraitBoundModifier
) -> TraitBoundModifier
pub(crate) fn stmt(&mut self, span: Span, kind: StmtKind<'hir>) -> Stmt<'hir>
pub(crate) fn stmt_expr(&mut self, span: Span, expr: Expr<'hir>) -> Stmt<'hir>
pub(crate) fn stmt_let_pat(
&mut self,
attrs: Option<&'hir [Attribute]>,
span: Span,
init: Option<&'hir Expr<'hir>>,
pat: &'hir Pat<'hir>,
source: LocalSource
) -> Stmt<'hir>
pub(crate) fn block_expr(&mut self, expr: &'hir Expr<'hir>) -> &'hir Block<'hir>
pub(crate) fn block_all(
&mut self,
span: Span,
stmts: &'hir [Stmt<'hir>],
expr: Option<&'hir Expr<'hir>>
) -> &'hir Block<'hir>
pub(crate) fn pat_cf_continue(
&mut self,
span: Span,
pat: &'hir Pat<'hir>
) -> &'hir Pat<'hir>
pub(crate) fn pat_cf_break(
&mut self,
span: Span,
pat: &'hir Pat<'hir>
) -> &'hir Pat<'hir>
pub(crate) fn pat_some(
&mut self,
span: Span,
pat: &'hir Pat<'hir>
) -> &'hir Pat<'hir>
pub(crate) fn pat_none(&mut self, span: Span) -> &'hir Pat<'hir>
pub(crate) fn single_pat_field(
&mut self,
span: Span,
pat: &'hir Pat<'hir>
) -> &'hir [PatField<'hir>]
pub(crate) fn pat_lang_item_variant(
&mut self,
span: Span,
lang_item: LangItem,
fields: &'hir [PatField<'hir>],
hir_id: Option<HirId>
) -> &'hir Pat<'hir>
pub(crate) fn pat_ident(
&mut self,
span: Span,
ident: Ident
) -> (&'hir Pat<'hir>, HirId)
pub(crate) fn pat_ident_mut(
&mut self,
span: Span,
ident: Ident
) -> (Pat<'hir>, HirId)
pub(crate) fn pat_ident_binding_mode(
&mut self,
span: Span,
ident: Ident,
bm: BindingAnnotation
) -> (&'hir Pat<'hir>, HirId)
pub(crate) fn pat_ident_binding_mode_mut(
&mut self,
span: Span,
ident: Ident,
bm: BindingAnnotation
) -> (Pat<'hir>, HirId)
pub(crate) fn pat(&mut self, span: Span, kind: PatKind<'hir>) -> &'hir Pat<'hir>
pub(crate) fn pat_without_dbm(
&mut self,
span: Span,
kind: PatKind<'hir>
) -> Pat<'hir>
pub(crate) fn ty_path(
&mut self,
hir_id: HirId,
span: Span,
qpath: QPath<'hir>
) -> Ty<'hir>
sourcepub(crate) fn elided_dyn_bound(&mut self, span: Span) -> Lifetime
pub(crate) fn elided_dyn_bound(&mut self, span: Span) -> Lifetime
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
impl<'a, 'hir> !RefUnwindSafe for LoweringContext<'a, 'hir>
impl<'a, 'hir> !Send for LoweringContext<'a, 'hir>
impl<'a, 'hir> !Sync for LoweringContext<'a, 'hir>
impl<'a, 'hir> Unpin for LoweringContext<'a, 'hir>
impl<'a, 'hir> !UnwindSafe for LoweringContext<'a, 'hir>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<'a, T> Captures<'a> for T where
T: ?Sized,
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