Skip to content

Commit 87f950b

Browse files
committed
Keep stealing ResolverAstLowering.
1 parent fe48ff4 commit 87f950b

21 files changed

Lines changed: 58 additions & 66 deletions

File tree

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::errors::{
2020
};
2121
use crate::{AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode};
2222

23-
impl<'hir> LoweringContext<'hir> {
23+
impl<'hir> LoweringContext<'_, 'hir> {
2424
pub(crate) fn lower_inline_asm(
2525
&mut self,
2626
sp: Span,

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use smallvec::SmallVec;
66

77
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
88

9-
impl<'hir> LoweringContext<'hir> {
9+
impl<'hir> LoweringContext<'_, 'hir> {
1010
pub(super) fn lower_block(
1111
&mut self,
1212
b: &Block,

compiler/rustc_ast_lowering/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use thin_vec::thin_vec;
44

55
use crate::LoweringContext;
66

7-
impl<'hir> LoweringContext<'hir> {
7+
impl<'hir> LoweringContext<'_, 'hir> {
88
/// Lowered contracts are guarded with the `contract_checks` compiler flag,
99
/// i.e. the flag turns into a boolean guard in the lowered HIR. The reason
1010
/// for not eliminating the contract code entirely when the `contract_checks`

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static ATTRS_ADDITIONS: &[AttrAdditionInfo] = &[
105105
},
106106
];
107107

108-
impl<'hir> LoweringContext<'hir> {
108+
impl<'hir> LoweringContext<'_, 'hir> {
109109
fn is_method(&self, def_id: DefId, span: Span) -> bool {
110110
match self.tcx.def_kind(def_id) {
111111
DefKind::Fn => false,
@@ -661,13 +661,13 @@ impl<'hir> LoweringContext<'hir> {
661661
}
662662
}
663663

664-
struct SelfResolver<'a, 'hir> {
665-
ctxt: &'a mut LoweringContext<'hir>,
664+
struct SelfResolver<'a, 'b, 'hir> {
665+
ctxt: &'a mut LoweringContext<'b, 'hir>,
666666
path_id: NodeId,
667667
self_param_id: NodeId,
668668
}
669669

670-
impl SelfResolver<'_, '_> {
670+
impl SelfResolver<'_, '_, '_> {
671671
fn try_replace_id(&mut self, id: NodeId) {
672672
if let Some(res) = self.ctxt.get_partial_res(id)
673673
&& let Some(Res::Local(sig_id)) = res.full_res()
@@ -679,7 +679,7 @@ impl SelfResolver<'_, '_> {
679679
}
680680
}
681681

682-
impl<'ast> Visitor<'ast> for SelfResolver<'_, '_> {
682+
impl<'ast> Visitor<'ast> for SelfResolver<'_, '_, '_> {
683683
fn visit_id(&mut self, id: NodeId) {
684684
self.try_replace_id(id);
685685
}

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl DelegationGenericsKind {
9797
impl<'hir> HirOrTyGenerics<'hir> {
9898
pub(super) fn into_hir_generics(
9999
&mut self,
100-
ctx: &mut LoweringContext<'hir>,
100+
ctx: &mut LoweringContext<'_, 'hir>,
101101
span: Span,
102102
) -> &mut HirOrTyGenerics<'hir> {
103103
if let HirOrTyGenerics::Ty(ty) = self {
@@ -117,7 +117,7 @@ impl<'hir> HirOrTyGenerics<'hir> {
117117

118118
pub(super) fn into_generic_args(
119119
&self,
120-
ctx: &mut LoweringContext<'hir>,
120+
ctx: &mut LoweringContext<'_, 'hir>,
121121
add_lifetimes: bool,
122122
span: Span,
123123
) -> &'hir hir::GenericArgs<'hir> {
@@ -151,7 +151,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
151151
pub(super) fn all_params(
152152
&mut self,
153153
span: Span,
154-
ctx: &mut LoweringContext<'hir>,
154+
ctx: &mut LoweringContext<'_, 'hir>,
155155
) -> impl Iterator<Item = hir::GenericParam<'hir>> {
156156
// Now we always call `into_hir_generics` both on child and parent,
157157
// however in future we would not do that, when scenarios like
@@ -185,7 +185,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
185185
pub(super) fn all_predicates(
186186
&mut self,
187187
span: Span,
188-
ctx: &mut LoweringContext<'hir>,
188+
ctx: &mut LoweringContext<'_, 'hir>,
189189
) -> impl Iterator<Item = hir::WherePredicate<'hir>> {
190190
// Now we always call `into_hir_generics` both on child and parent,
191191
// however in future we would not do that, when scenarios like
@@ -203,7 +203,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
203203
}
204204
}
205205

206-
impl<'hir> LoweringContext<'hir> {
206+
impl<'hir> LoweringContext<'_, 'hir> {
207207
pub(super) fn uplift_delegation_generics(
208208
&mut self,
209209
delegation: &Delegation,

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
5151
}
5252
}
5353

54-
impl<'hir> LoweringContext<'hir> {
54+
impl<'hir> LoweringContext<'_, 'hir> {
5555
fn lower_exprs(&mut self, exprs: &[Box<Expr>]) -> &'hir [hir::Expr<'hir>] {
5656
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5757
}
@@ -1235,7 +1235,7 @@ impl<'hir> LoweringContext<'hir> {
12351235
whole_span: Span,
12361236
) -> hir::ExprKind<'hir> {
12371237
// Return early in case of an ordinary assignment.
1238-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
1238+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
12391239
match &lhs.kind {
12401240
ExprKind::Array(..)
12411241
| ExprKind::Struct(..)

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{ByteSymbol, DesugaringKind, Ident, Span, Symbol, sym};
88

99
use super::LoweringContext;
1010

11-
impl<'hir> LoweringContext<'hir> {
11+
impl<'hir> LoweringContext<'_, 'hir> {
1212
pub(crate) fn lower_format_args(&mut self, sp: Span, fmt: &FormatArgs) -> hir::ExprKind<'hir> {
1313
// Never call the const constructor of `fmt::Arguments` if the
1414
// format_args!() had any arguments _before_ flattening/inlining.
@@ -230,7 +230,7 @@ enum ArgumentType {
230230
/// <core::fmt::Argument>::new_…(arg)
231231
/// ```
232232
fn make_argument<'hir>(
233-
ctx: &mut LoweringContext<'hir>,
233+
ctx: &mut LoweringContext<'_, 'hir>,
234234
sp: Span,
235235
arg: &'hir hir::Expr<'hir>,
236236
ty: ArgumentType,
@@ -277,7 +277,7 @@ fn make_count(
277277
}
278278

279279
fn expand_format_args<'hir>(
280-
ctx: &mut LoweringContext<'hir>,
280+
ctx: &mut LoweringContext<'_, 'hir>,
281281
macsp: Span,
282282
fmt: &FormatArgs,
283283
allow_const: bool,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'hir> Owners<'_, 'hir> {
5050

5151
pub(super) struct ItemLowerer<'a, 'hir> {
5252
pub(super) tcx: TyCtxt<'hir>,
53-
pub(super) resolver: &'hir ResolverAstLowering<'hir>,
53+
pub(super) resolver: &'a ResolverAstLowering<'hir>,
5454
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
5555
pub(super) owners: Owners<'a, 'hir>,
5656
}
@@ -78,7 +78,7 @@ impl<'hir> ItemLowerer<'_, 'hir> {
7878
fn with_lctx(
7979
&mut self,
8080
owner: NodeId,
81-
f: impl FnOnce(&mut LoweringContext<'hir>) -> hir::OwnerNode<'hir>,
81+
f: impl for<'a> FnOnce(&mut LoweringContext<'a, 'hir>) -> hir::OwnerNode<'hir>,
8282
) {
8383
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
8484
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
@@ -122,7 +122,7 @@ impl<'hir> ItemLowerer<'_, 'hir> {
122122
}
123123
}
124124

125-
impl<'hir> LoweringContext<'hir> {
125+
impl<'hir> LoweringContext<'_, 'hir> {
126126
pub(super) fn lower_mod(
127127
&mut self,
128128
items: &[Box<Item>],
@@ -1531,7 +1531,7 @@ impl<'hir> LoweringContext<'hir> {
15311531
pub(crate) fn lower_coroutine_body_with_moved_arguments(
15321532
&mut self,
15331533
decl: &FnDecl,
1534-
lower_body: impl FnOnce(&mut LoweringContext<'hir>) -> hir::Expr<'hir>,
1534+
lower_body: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::Expr<'hir>,
15351535
fn_decl_span: Span,
15361536
body_span: Span,
15371537
coroutine_kind: CoroutineKind,
@@ -1668,7 +1668,7 @@ impl<'hir> LoweringContext<'hir> {
16681668
parameters.push(new_parameter);
16691669
}
16701670

1671-
let mkbody = |this: &mut LoweringContext<'hir>| {
1671+
let mkbody = |this: &mut LoweringContext<'_, 'hir>| {
16721672
// Create a block from the user's function body:
16731673
let user_body = lower_body(this);
16741674

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ mod pat;
9191
mod path;
9292
pub mod stability;
9393

94-
struct LoweringContext<'hir> {
94+
struct LoweringContext<'a, 'hir> {
9595
tcx: TyCtxt<'hir>,
96-
resolver: &'hir ResolverAstLowering<'hir>,
96+
resolver: &'a ResolverAstLowering<'hir>,
9797
current_disambiguator: PerParentDisambiguatorState,
9898

9999
/// Used to allocate HIR nodes.
@@ -161,8 +161,8 @@ struct LoweringContext<'hir> {
161161
attribute_parser: AttributeParser<'hir>,
162162
}
163163

164-
impl<'hir> LoweringContext<'hir> {
165-
fn new(tcx: TyCtxt<'hir>, resolver: &'hir ResolverAstLowering<'hir>) -> Self {
164+
impl<'a, 'hir> LoweringContext<'a, 'hir> {
165+
fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>) -> Self {
166166
let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
167167
Self {
168168
tcx,
@@ -531,8 +531,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
531531
tcx.ensure_done().early_lint_checks(());
532532
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
533533
tcx.ensure_done().get_lang_items(());
534-
let (resolver, krate) = tcx.resolver_for_lowering();
535-
let krate = krate.steal();
534+
let (resolver, krate) = tcx.resolver_for_lowering().steal();
536535

537536
let ast_index = index_crate(&resolver, &krate);
538537
let mut owners = IndexVec::from_fn_n(
@@ -542,7 +541,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
542541

543542
let mut lowerer = item::ItemLowerer {
544543
tcx,
545-
resolver,
544+
resolver: &resolver,
546545
ast_index: &ast_index,
547546
owners: Owners::IndexVec(&mut owners),
548547
};
@@ -563,16 +562,15 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
563562
let opt_hir_hash =
564563
if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
565564

566-
let ast_krate = Steal::new(krate);
567-
mid_hir::Crate::new(owners, delayed_ids, ast_krate, opt_hir_hash)
565+
let delayed_resolver = Steal::new((resolver, krate));
566+
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)
568567
}
569568

570569
/// Lowers an AST owner corresponding to `def_id`, now only delegations are lowered this way.
571570
pub fn lower_delayed_owner(tcx: TyCtxt<'_>, def_id: LocalDefId) {
572571
let krate = tcx.hir_crate(());
573572

574-
let (resolver, _) = tcx.resolver_for_lowering();
575-
let krate = &*krate.ast_krate.borrow();
573+
let (resolver, krate) = &*krate.delayed_resolver.borrow();
576574

577575
// FIXME!!!(fn_delegation): make ast index lifetime same as resolver,
578576
// as it is too bad to reindex whole crate on each delegation lowering.
@@ -620,7 +618,7 @@ enum GenericArgsMode {
620618
Silence,
621619
}
622620

623-
impl<'hir> LoweringContext<'hir> {
621+
impl<'hir> LoweringContext<'_, 'hir> {
624622
fn create_def(
625623
&mut self,
626624
node_id: ast::NodeId,
@@ -3029,7 +3027,7 @@ impl<'hir> GenericArgsCtor<'hir> {
30293027
&& self.parenthesized == hir::GenericArgsParentheses::No
30303028
}
30313029

3032-
fn into_generic_args(self, this: &LoweringContext<'hir>) -> &'hir hir::GenericArgs<'hir> {
3030+
fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
30333031
let ga = hir::GenericArgs {
30343032
args: this.arena.alloc_from_iter(self.args),
30353033
constraints: self.constraints,

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{
1414
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
1515
};
1616

17-
impl<'hir> LoweringContext<'hir> {
17+
impl<'hir> LoweringContext<'_, 'hir> {
1818
pub(crate) fn lower_pat(&mut self, pattern: &Pat) -> &'hir hir::Pat<'hir> {
1919
self.arena.alloc(self.lower_pat_mut(pattern))
2020
}

0 commit comments

Comments
 (0)