Skip to content

Commit 14a40e2

Browse files
fee1-deadcjgillot
andcommitted
Do not modify resolver outputs during lowering
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
1 parent 2888098 commit 14a40e2

File tree

19 files changed

+109
-96
lines changed

19 files changed

+109
-96
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use super::errors::{
2020
};
2121
use crate::{
2222
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, ParamMode,
23-
ResolverAstLoweringExt, fluent_generated as fluent,
23+
fluent_generated as fluent,
2424
};
2525

26-
impl<'a, 'hir> LoweringContext<'a, 'hir> {
26+
impl<'hir> LoweringContext<'hir> {
2727
pub(crate) fn lower_inline_asm(
2828
&mut self,
2929
sp: Span,
@@ -201,7 +201,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
201201
},
202202
InlineAsmOperand::Sym { sym } => {
203203
let static_def_id = self
204-
.resolver
205204
.get_partial_res(sym.id)
206205
.and_then(|res| res.full_res())
207206
.and_then(|res| match res {

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<'a, 'hir> LoweringContext<'a, '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
@@ -2,7 +2,7 @@ use thin_vec::thin_vec;
22

33
use crate::LoweringContext;
44

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

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ use rustc_ast::*;
4646
use rustc_errors::ErrorGuaranteed;
4747
use rustc_hir::def_id::DefId;
4848
use rustc_middle::span_bug;
49-
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
49+
use rustc_middle::ty::Asyncness;
5050
use rustc_span::symbol::kw;
5151
use rustc_span::{Ident, Span, Symbol};
5252
use {rustc_ast as ast, rustc_hir as hir};
5353

54-
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
55-
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
54+
use super::{
55+
AllowReturnTypeNotation, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext,
56+
ParamMode,
57+
};
5658

5759
pub(crate) struct DelegationResults<'hir> {
5860
pub body_id: hir::BodyId,
@@ -61,7 +63,7 @@ pub(crate) struct DelegationResults<'hir> {
6163
pub generics: &'hir hir::Generics<'hir>,
6264
}
6365

64-
impl<'hir> LoweringContext<'_, 'hir> {
66+
impl<'hir> LoweringContext<'hir> {
6567
fn is_method(&self, def_id: DefId, span: Span) -> bool {
6668
match self.tcx.def_kind(def_id) {
6769
DefKind::Fn => false,
@@ -112,8 +114,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
112114
}
113115

114116
fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
115-
let def_id =
116-
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
117+
let def_id = self.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
117118
def_id.ok_or_else(|| {
118119
self.tcx.dcx().span_delayed_bug(
119120
span,
@@ -292,7 +293,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
292293
&& idx == 0
293294
{
294295
let mut self_resolver = SelfResolver {
295-
resolver: this.resolver,
296+
ctxt: this,
296297
path_id: delegation.id,
297298
self_param_id: pat_node_id,
298299
};
@@ -438,25 +439,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
438439
}
439440
}
440441

441-
struct SelfResolver<'a> {
442-
resolver: &'a mut ResolverAstLowering,
442+
struct SelfResolver<'r, 'hir> {
443+
ctxt: &'r mut LoweringContext<'hir>,
443444
path_id: NodeId,
444445
self_param_id: NodeId,
445446
}
446447

447-
impl<'a> SelfResolver<'a> {
448+
impl SelfResolver<'_, '_> {
448449
fn try_replace_id(&mut self, id: NodeId) {
449-
if let Some(res) = self.resolver.partial_res_map.get(&id)
450+
if let Some(res) = self.ctxt.get_partial_res(id)
450451
&& let Some(Res::Local(sig_id)) = res.full_res()
451452
&& sig_id == self.path_id
452453
{
453454
let new_res = PartialRes::new(Res::Local(self.self_param_id));
454-
self.resolver.partial_res_map.insert(id, new_res);
455+
self.ctxt.partial_res_overrides.insert(id, new_res);
455456
}
456457
}
457458
}
458459

459-
impl<'ast, 'a> Visitor<'ast> for SelfResolver<'a> {
460+
impl<'ast> Visitor<'ast> for SelfResolver<'_, '_> {
460461
fn visit_id(&mut self, id: NodeId) {
461462
self.try_replace_id(id);
462463
}

compiler/rustc_ast_lowering/src/expr.rs

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

55-
impl<'hir> LoweringContext<'_, 'hir> {
55+
impl<'hir> LoweringContext<'hir> {
5656
fn lower_exprs(&mut self, exprs: &[Box<Expr>]) -> &'hir [hir::Expr<'hir>] {
5757
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5858
}
@@ -1205,7 +1205,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12051205
whole_span: Span,
12061206
) -> hir::ExprKind<'hir> {
12071207
// Return early in case of an ordinary assignment.
1208-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
1208+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
12091209
match &lhs.kind {
12101210
ExprKind::Array(..)
12111211
| ExprKind::Struct(..)
@@ -1265,7 +1265,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12651265
) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> {
12661266
if let ExprKind::Path(qself, path) = &expr.kind {
12671267
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
1268-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1268+
if let Some(partial_res) = self.get_partial_res(expr.id) {
12691269
if let Some(res) = partial_res.full_res()
12701270
&& !res.expected_in_tuple_struct_pat()
12711271
{
@@ -1287,7 +1287,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12871287
) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> {
12881288
if let ExprKind::Path(qself, path) = &expr.kind {
12891289
// Does the path resolve to something disallowed in a unit struct/variant pattern?
1290-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1290+
if let Some(partial_res) = self.get_partial_res(expr.id) {
12911291
if let Some(res) = partial_res.full_res()
12921292
&& !res.expected_in_unit_struct_pat()
12931293
{

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{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.
@@ -236,7 +236,7 @@ enum ArgumentType {
236236
/// <core::fmt::Argument>::new_…(arg)
237237
/// ```
238238
fn make_argument<'hir>(
239-
ctx: &mut LoweringContext<'_, 'hir>,
239+
ctx: &mut LoweringContext<'hir>,
240240
sp: Span,
241241
arg: &'hir hir::Expr<'hir>,
242242
ty: ArgumentType,
@@ -285,7 +285,7 @@ fn make_argument<'hir>(
285285
/// <core::fmt::rt::Count>::Implied
286286
/// ```
287287
fn make_count<'hir>(
288-
ctx: &mut LoweringContext<'_, 'hir>,
288+
ctx: &mut LoweringContext<'hir>,
289289
sp: Span,
290290
count: &Option<FormatCount>,
291291
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -336,7 +336,7 @@ fn make_count<'hir>(
336336
/// }
337337
/// ```
338338
fn make_format_spec<'hir>(
339-
ctx: &mut LoweringContext<'_, 'hir>,
339+
ctx: &mut LoweringContext<'hir>,
340340
sp: Span,
341341
placeholder: &FormatPlaceholder,
342342
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -397,7 +397,7 @@ fn make_format_spec<'hir>(
397397
}
398398

399399
fn expand_format_args<'hir>(
400-
ctx: &mut LoweringContext<'_, 'hir>,
400+
ctx: &mut LoweringContext<'hir>,
401401
macsp: Span,
402402
fmt: &FormatArgs,
403403
allow_const: bool,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::{
2626

2727
pub(super) struct ItemLowerer<'a, 'hir> {
2828
pub(super) tcx: TyCtxt<'hir>,
29-
pub(super) resolver: &'a mut ResolverAstLowering,
29+
pub(super) resolver: &'hir ResolverAstLowering,
3030
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
3131
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
3232
}
@@ -54,7 +54,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5454
fn with_lctx(
5555
&mut self,
5656
owner: NodeId,
57-
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
57+
f: impl FnOnce(&mut LoweringContext<'hir>) -> hir::OwnerNode<'hir>,
5858
) {
5959
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
6060
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
@@ -98,7 +98,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
9898
}
9999
}
100100

101-
impl<'hir> LoweringContext<'_, 'hir> {
101+
impl<'hir> LoweringContext<'hir> {
102102
pub(super) fn lower_mod(
103103
&mut self,
104104
items: &[Box<Item>],
@@ -1133,7 +1133,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
11331133
ImplItemImplKind::Trait {
11341134
defaultness,
11351135
trait_item_def_id: self
1136-
.resolver
11371136
.get_partial_res(i.id)
11381137
.and_then(|r| r.expect_full_res().opt_def_id())
11391138
.ok_or_else(|| {
@@ -1321,7 +1320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13211320
pub(crate) fn lower_coroutine_body_with_moved_arguments(
13221321
&mut self,
13231322
decl: &FnDecl,
1324-
lower_body: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::Expr<'hir>,
1323+
lower_body: impl FnOnce(&mut LoweringContext<'hir>) -> hir::Expr<'hir>,
13251324
fn_decl_span: Span,
13261325
body_span: Span,
13271326
coroutine_kind: CoroutineKind,
@@ -1458,7 +1457,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14581457
parameters.push(new_parameter);
14591458
}
14601459

1461-
let mkbody = |this: &mut LoweringContext<'_, 'hir>| {
1460+
let mkbody = |this: &mut LoweringContext<'hir>| {
14621461
// Create a block from the user's function body:
14631462
let user_body = lower_body(this);
14641463

@@ -1677,7 +1676,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16771676

16781677
// Introduce extra lifetimes if late resolution tells us to.
16791678
let extra_lifetimes = self.resolver.extra_lifetime_params(parent_node_id);
1680-
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
1679+
params.extend(extra_lifetimes.into_iter().filter_map(|&(ident, node_id, res)| {
16811680
self.lifetime_res_to_generic_param(
16821681
ident,
16831682
node_id,
@@ -1719,7 +1718,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17191718
return;
17201719
};
17211720
let define_opaque = define_opaque.iter().filter_map(|(id, path)| {
1722-
let res = self.resolver.get_partial_res(*id);
1721+
let res = self.get_partial_res(*id);
17231722
let Some(did) = res.and_then(|res| res.expect_full_res().opt_def_id()) else {
17241723
self.dcx().span_delayed_bug(path.span, "should have errored in resolve");
17251724
return None;

0 commit comments

Comments
 (0)