Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0dbcf6a

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

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,12 +46,14 @@ 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::{Ident, Span, Symbol};
5151
use {rustc_ast as ast, rustc_hir as hir};
5252

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

5658
pub(crate) struct DelegationResults<'hir> {
5759
pub body_id: hir::BodyId,
@@ -60,7 +62,7 @@ pub(crate) struct DelegationResults<'hir> {
6062
pub generics: &'hir hir::Generics<'hir>,
6163
}
6264

63-
impl<'hir> LoweringContext<'_,'hir> {
65+
impl<'hir> LoweringContext<'hir> {
6466
/// Defines whether the delegatee is an associated function whose first parameter is `self`.
6567
pub(crate) fn delegatee_is_method(
6668
&self,
@@ -125,8 +127,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
125127
}
126128

127129
fn get_resolution_id(&self, node_id: NodeId, span: Span) -> Result<DefId, ErrorGuaranteed> {
128-
let def_id =
129-
self.resolver.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
130+
let def_id = self.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id());
130131
def_id.ok_or_else(|| {
131132
self.tcx.dcx().span_delayed_bug(
132133
span,
@@ -281,7 +282,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
281282
&& idx == 0
282283
{
283284
let mut self_resolver = SelfResolver {
284-
resolver: this.resolver,
285+
ctxt: this,
285286
path_id: delegation.id,
286287
self_param_id: pat_node_id,
287288
};
@@ -427,25 +428,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
427428
}
428429
}
429430

430-
struct SelfResolver<'a> {
431-
resolver: &'a mut ResolverAstLowering,
431+
struct SelfResolver<'r,'hir> {
432+
ctxt: &'r mut LoweringContext<'hir>,
432433
path_id: NodeId,
433434
self_param_id: NodeId,
434435
}
435436

436-
impl<'a> SelfResolver<'a> {
437+
impl SelfResolver<'_,'_> {
437438
fn try_replace_id(&mut self, id: NodeId) {
438-
if let Some(res) = self.resolver.partial_res_map.get(&id)
439+
if let Some(res) = self.ctxt.get_partial_res(id)
439440
&& let Some(Res::Local(sig_id)) = res.full_res()
440441
&& sig_id == self.path_id
441442
{
442443
let new_res = PartialRes::new(Res::Local(self.self_param_id));
443-
self.resolver.partial_res_map.insert(id, new_res);
444+
self.ctxt.partial_res_overrides.insert(id, new_res);
444445
}
445446
}
446447
}
447448

448-
impl<'ast,'a> Visitor<'ast> for SelfResolver<'a> {
449+
impl<'ast> Visitor<'ast> for SelfResolver<'_,'_> {
449450
fn visit_id(&mut self, id: NodeId) {
450451
self.try_replace_id(id);
451452
}

‎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: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
5757
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
5858
}
@@ -1270,7 +1270,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12701270
whole_span: Span,
12711271
) -> hir::ExprKind<'hir> {
12721272
// Return early in case of an ordinary assignment.
1273-
fn is_ordinary(lower_ctx: &mut LoweringContext<'_,'_>, lhs: &Expr) -> bool {
1273+
fn is_ordinary(lower_ctx: &mut LoweringContext<'_>, lhs: &Expr) -> bool {
12741274
match &lhs.kind {
12751275
ExprKind::Array(..)
12761276
| ExprKind::Struct(..)
@@ -1330,7 +1330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13301330
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13311331
if let ExprKind::Path(qself, path) = &expr.kind {
13321332
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
1333-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1333+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13341334
if let Some(res) = partial_res.full_res()
13351335
&& !res.expected_in_tuple_struct_pat()
13361336
{
@@ -1352,7 +1352,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13521352
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
13531353
if let ExprKind::Path(qself, path) = &expr.kind {
13541354
// Does the path resolve to something disallowed in a unit struct/variant pattern?
1355-
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
1355+
if let Some(partial_res) = self.get_partial_res(expr.id) {
13561356
if let Some(res) = partial_res.full_res()
13571357
&& !res.expected_in_unit_struct_pat()
13581358
{

‎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::{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.
@@ -229,7 +229,7 @@ enum ArgumentType {
229229
/// <core::fmt::Argument>::new_...(arg)
230230
/// ```
231231
fn make_argument<'hir>(
232-
ctx: &mut LoweringContext<'_,'hir>,
232+
ctx: &mut LoweringContext<'hir>,
233233
sp: Span,
234234
arg: &'hir hir::Expr<'hir>,
235235
ty: ArgumentType,
@@ -278,7 +278,7 @@ fn make_argument<'hir>(
278278
/// <core::fmt::rt::Count>::Implied
279279
/// ```
280280
fn make_count<'hir>(
281-
ctx: &mut LoweringContext<'_,'hir>,
281+
ctx: &mut LoweringContext<'hir>,
282282
sp: Span,
283283
count: &Option<FormatCount>,
284284
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -329,7 +329,7 @@ fn make_count<'hir>(
329329
/// }
330330
/// ```
331331
fn make_format_spec<'hir>(
332-
ctx: &mut LoweringContext<'_,'hir>,
332+
ctx: &mut LoweringContext<'hir>,
333333
sp: Span,
334334
placeholder: &FormatPlaceholder,
335335
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
@@ -390,7 +390,7 @@ fn make_format_spec<'hir>(
390390
}
391391

392392
fn expand_format_args<'hir>(
393-
ctx: &mut LoweringContext<'_,'hir>,
393+
ctx: &mut LoweringContext<'hir>,
394394
macsp: Span,
395395
fmt: &FormatArgs,
396396
allow_const: bool,

‎compiler/rustc_ast_lowering/src/item.rs‎

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

2828
pub(super) struct ItemLowerer<'a, 'hir> {
2929
pub(super) tcx: TyCtxt<'hir>,
30-
pub(super) resolver: &'amut ResolverAstLowering,
30+
pub(super) resolver: &'hir ResolverAstLowering,
3131
pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
3232
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<'hir>>,
3333
}
@@ -57,7 +57,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5757
fn with_lctx(
5858
&mut self,
5959
owner: NodeId,
60-
f: impl FnOnce(&mut LoweringContext<'_,'hir>) -> hir::OwnerNode<'hir>,
60+
f: impl FnOnce(&mut LoweringContext<'hir>) -> hir::OwnerNode<'hir>,
6161
) {
6262
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
6363
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
@@ -101,7 +101,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
101101
}
102102
}
103103

104-
impl<'hir> LoweringContext<'_,'hir> {
104+
impl<'hir> LoweringContext<'hir> {
105105
pub(super) fn lower_mod(
106106
&mut self,
107107
items: &[P<Item>],
@@ -1157,7 +1157,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
11571157
}
11581158
},
11591159
trait_item_def_id: self
1160-
.resolver
11611160
.get_partial_res(i.id)
11621161
.map(|r| r.expect_full_res().opt_def_id())
11631162
.unwrap_or(None),
@@ -1395,7 +1394,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13951394
pub(crate) fn lower_coroutine_body_with_moved_arguments(
13961395
&mut self,
13971396
decl: &FnDecl,
1398-
lower_body: impl FnOnce(&mut LoweringContext<'_,'hir>) -> hir::Expr<'hir>,
1397+
lower_body: impl FnOnce(&mut LoweringContext<'hir>) -> hir::Expr<'hir>,
13991398
fn_decl_span: Span,
14001399
body_span: Span,
14011400
coroutine_kind: CoroutineKind,
@@ -1532,7 +1531,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15321531
parameters.push(new_parameter);
15331532
}
15341533

1535-
let mkbody = |this: &mut LoweringContext<'_,'hir>| {
1534+
let mkbody = |this: &mut LoweringContext<'hir>| {
15361535
// Create a block from the user's function body:
15371536
let user_body = lower_body(this);
15381537

@@ -1714,11 +1713,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17141713
};
17151714
let compute_is_param = || {
17161715
// Check if the where clause type is a plain type parameter.
1717-
match self
1718-
.resolver
1719-
.get_partial_res(bound_pred.bounded_ty.id)
1720-
.and_then(|r| r.full_res())
1721-
{
1716+
match self.get_partial_res(bound_pred.bounded_ty.id).and_then(|r| r.full_res()) {
17221717
Some(Res::Def(DefKind::TyParam, def_id))
17231718
if bound_pred.bound_generic_params.is_empty() =>
17241719
{
@@ -1785,7 +1780,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17851780

17861781
// Introduce extra lifetimes if late resolution tells us to.
17871782
let extra_lifetimes = self.resolver.extra_lifetime_params(parent_node_id);
1788-
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
1783+
params.extend(extra_lifetimes.into_iter().filter_map(|&(ident, node_id, res)| {
17891784
self.lifetime_res_to_generic_param(
17901785
ident,
17911786
node_id,
@@ -1827,7 +1822,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18271822
return;
18281823
};
18291824
let define_opaque = define_opaque.iter().filter_map(|(id, path)| {
1830-
let res = self.resolver.get_partial_res(*id);
1825+
let res = self.get_partial_res(*id);
18311826
let Some(did) = res.and_then(|res| res.expect_full_res().opt_def_id()) else {
18321827
self.dcx().span_delayed_bug(path.span, "should have errored in resolve");
18331828
return None;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /