Skip to content

Commit 3bae927

Browse files
committed
Add LoweringContext::new.
1 parent ed2868e commit 3bae927

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use hir::definitions::DefPathData;
77
use rustc_ast::ptr::P;
88
use rustc_ast::visit::AssocCtxt;
99
use rustc_ast::*;
10-
use rustc_data_structures::sorted_map::SortedMap;
1110
use rustc_errors::ErrorGuaranteed;
1211
use rustc_hir as hir;
1312
use rustc_hir::def::{DefKind, Res};
@@ -55,42 +54,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5554
owner: NodeId,
5655
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
5756
) {
58-
let allow_gen_future = Some(if self.tcx.features().async_fn_track_caller {
59-
[sym::gen_future, sym::closure_track_caller][..].into()
60-
} else {
61-
[sym::gen_future][..].into()
62-
});
63-
let mut lctx = LoweringContext {
64-
// Pseudo-globals.
65-
tcx: self.tcx,
66-
resolver: self.resolver,
67-
arena: self.tcx.hir_arena,
68-
69-
// HirId handling.
70-
bodies: Vec::new(),
71-
attrs: SortedMap::default(),
72-
children: Vec::default(),
73-
current_hir_id_owner: hir::CRATE_OWNER_ID,
74-
item_local_id_counter: hir::ItemLocalId::new(0),
75-
node_id_to_local_id: Default::default(),
76-
trait_map: Default::default(),
77-
78-
// Lowering state.
79-
catch_scope: None,
80-
loop_scope: None,
81-
is_in_loop_condition: false,
82-
is_in_trait_impl: false,
83-
is_in_dyn_type: false,
84-
coroutine_kind: None,
85-
task_context: None,
86-
current_item: None,
87-
impl_trait_defs: Vec::new(),
88-
impl_trait_bounds: Vec::new(),
89-
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
90-
allow_gen_future,
91-
generics_def_id_map: Default::default(),
92-
host_param_id: None,
93-
};
57+
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
9458
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
9559

9660
for (def_id, info) in lctx.children {

compiler/rustc_ast_lowering/src/lib.rs

+40
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,46 @@ struct LoweringContext<'a, 'hir> {
144144
host_param_id: Option<LocalDefId>,
145145
}
146146

147+
impl<'a, 'hir> LoweringContext<'a, 'hir> {
148+
fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
149+
Self {
150+
// Pseudo-globals.
151+
tcx,
152+
resolver: resolver,
153+
arena: tcx.hir_arena,
154+
155+
// HirId handling.
156+
bodies: Vec::new(),
157+
attrs: SortedMap::default(),
158+
children: Vec::default(),
159+
current_hir_id_owner: hir::CRATE_OWNER_ID,
160+
item_local_id_counter: hir::ItemLocalId::new(0),
161+
node_id_to_local_id: Default::default(),
162+
trait_map: Default::default(),
163+
164+
// Lowering state.
165+
catch_scope: None,
166+
loop_scope: None,
167+
is_in_loop_condition: false,
168+
is_in_trait_impl: false,
169+
is_in_dyn_type: false,
170+
coroutine_kind: None,
171+
task_context: None,
172+
current_item: None,
173+
impl_trait_defs: Vec::new(),
174+
impl_trait_bounds: Vec::new(),
175+
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
176+
allow_gen_future: Some(if tcx.features().async_fn_track_caller {
177+
[sym::gen_future, sym::closure_track_caller][..].into()
178+
} else {
179+
[sym::gen_future][..].into()
180+
}),
181+
generics_def_id_map: Default::default(),
182+
host_param_id: None,
183+
}
184+
}
185+
}
186+
147187
trait ResolverAstLoweringExt {
148188
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
149189
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;

0 commit comments

Comments
 (0)