Skip to content

Commit c52f549

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

File tree

17 files changed

+106
-97
lines changed

17 files changed

+106
-97
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,
@@ -200,7 +200,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
200200
},
201201
InlineAsmOperand::Sym { sym } => {
202202
let static_def_id = self
203-
.resolver
204203
.get_partial_res(sym.id)
205204
.and_then(|res| res.full_res())
206205
.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
@@ -5,7 +5,7 @@ use smallvec::SmallVec;
55

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

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

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
@@ -53,7 +53,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
5353
}
5454
}
5555

56-
impl<'hir> LoweringContext<'_, 'hir> {
56+
impl<'hir> LoweringContext<'hir> {
5757
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
5858
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5959
}
@@ -1267,7 +1267,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12671267
whole_span: Span,
12681268
) -> hir::ExprKind<'hir> {
12691269
// Return early in case of an ordinary assignment.
1270-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_, '_>, lhs: &Expr) -> bool {
1270+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
12711271
match &lhs.kind {
12721272
ExprKind::Array(..)
12731273
| ExprKind::Struct(..)
@@ -1327,7 +1327,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13271327
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13281328
if let ExprKind::Path(qself, path) = &expr.kind {
13291329
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
1330-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1330+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13311331
if let Some(res) = partial_res.full_res()
13321332
&& !res.expected_in_tuple_struct_pat()
13331333
{
@@ -1349,7 +1349,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13491349
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13501350
if let ExprKind::Path(qself, path) = &expr.kind {
13511351
// Does the path resolve to something disallowed in a unit struct/variant pattern?
1352-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1352+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13531353
if let Some(res) = partial_res.full_res()
13541354
&& !res.expected_in_unit_struct_pat()
13551355
{

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: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::{
2828

2929
pub(super) struct ItemLowerer<'a, 'hir> {
3030
pub(super) tcx: TyCtxt<'hir>,
31-
pub(super) resolver: &'a mut ResolverAstLowering,
31+
pub(super) resolver: &'hir ResolverAstLowering,
3232
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
3333
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
3434
}
@@ -58,7 +58,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5858
fn with_lctx(
5959
&mut self,
6060
owner: NodeId,
61-
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
61+
f: impl FnOnce(&mut LoweringContext<'hir>) -> hir::OwnerNode<'hir>,
6262
) {
6363
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
6464
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
@@ -102,7 +102,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
102102
}
103103
}
104104

105-
impl<'hir> LoweringContext<'_, 'hir> {
105+
impl<'hir> LoweringContext<'hir> {
106106
pub(super) fn lower_mod(
107107
&mut self,
108108
items: &[P<Item>],
@@ -1097,7 +1097,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
10971097
defaultness,
10981098
has_delayed_lints: !self.delayed_lints.is_empty(),
10991099
trait_item_def_id: self
1100-
.resolver
11011100
.get_partial_res(i.id)
11021101
.map(|r| r.expect_full_res().opt_def_id())
11031102
.unwrap_or(None),
@@ -1340,7 +1339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13401339
pub(crate) fn lower_coroutine_body_with_moved_arguments(
13411340
&mut self,
13421341
decl: &FnDecl,
1343-
lower_body: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::Expr<'hir>,
1342+
lower_body: impl FnOnce(&mut LoweringContext<'hir>) -> hir::Expr<'hir>,
13441343
fn_decl_span: Span,
13451344
body_span: Span,
13461345
coroutine_kind: CoroutineKind,
@@ -1477,7 +1476,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14771476
parameters.push(new_parameter);
14781477
}
14791478

1480-
let mkbody = |this: &mut LoweringContext<'_, 'hir>| {
1479+
let mkbody = |this: &mut LoweringContext<'hir>| {
14811480
// Create a block from the user's function body:
14821481
let user_body = lower_body(this);
14831482

@@ -1679,11 +1678,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16791678
};
16801679
let compute_is_param = || {
16811680
// Check if the where clause type is a plain type parameter.
1682-
match self
1683-
.resolver
1684-
.get_partial_res(bound_pred.bounded_ty.id)
1685-
.and_then(|r| r.full_res())
1686-
{
1681+
match self.get_partial_res(bound_pred.bounded_ty.id).and_then(|r| r.full_res()) {
16871682
Some(Res::Def(DefKind::TyParam, def_id))
16881683
if bound_pred.bound_generic_params.is_empty() =>
16891684
{
@@ -1750,7 +1745,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17501745

17511746
// Introduce extra lifetimes if late resolution tells us to.
17521747
let extra_lifetimes = self.resolver.extra_lifetime_params(parent_node_id);
1753-
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
1748+
params.extend(extra_lifetimes.into_iter().filter_map(|&(ident, node_id, res)| {
17541749
self.lifetime_res_to_generic_param(
17551750
ident,
17561751
node_id,
@@ -1792,7 +1787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17921787
return;
17931788
};
17941789
let define_opaque = define_opaque.iter().filter_map(|(id, path)| {
1795-
let res = self.resolver.get_partial_res(*id);
1790+
let res = self.get_partial_res(*id);
17961791
let Some(did) = res.and_then(|res| res.expect_full_res().opt_def_id()) else {
17971792
self.dcx().span_delayed_bug(path.span, "should have errored in resolve");
17981793
return None;

0 commit comments

Comments
 (0)