Skip to content

Commit 4d5b6b5

Browse files
committed
Lighten and document partial_res_overrides.
1 parent e0fc019 commit 4d5b6b5

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use std::iter;
4040

4141
use ast::visit::Visitor;
42-
use hir::def::{DefKind, PartialRes, Res};
42+
use hir::def::{DefKind, Res};
4343
use hir::{BodyId, HirId};
4444
use rustc_abi::ExternAbi;
4545
use rustc_ast as ast;
@@ -673,8 +673,7 @@ impl SelfResolver<'_, '_, '_> {
673673
&& let Some(Res::Local(sig_id)) = res.full_res()
674674
&& sig_id == self.path_id
675675
{
676-
let new_res = PartialRes::new(Res::Local(self.self_param_id));
677-
self.ctxt.partial_res_overrides.insert(id, new_res);
676+
self.ctxt.partial_res_overrides.insert(id, self.self_param_id);
678677
}
679678
}
680679
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ struct LoweringContext<'a, 'hir> {
145145
/// Maps the `NodeId`s created during lowering to `LocalDefId`s.
146146
node_id_to_def_id: NodeMap<LocalDefId>,
147147
/// Overlay over resolver's `partial_res_map` used by delegation.
148-
partial_res_overrides: NodeMap<PartialRes>,
148+
/// This only contains `PartialRes::new(Res::Local(self_param_id))`,
149+
/// so we only store `self_param_id`.
150+
partial_res_overrides: NodeMap<NodeId>,
149151

150152
allow_contracts: Arc<[Symbol]>,
151153
allow_try_trait: Arc<[Symbol]>,
@@ -261,6 +263,9 @@ impl<'tcx> ResolverAstLowering<'tcx> {
261263
return None;
262264
}
263265

266+
// We do not need to look at `partial_res_overrides`. That map only contains overrides for
267+
// `self_param` locals. And here we are looking for the function definition that `expr`
268+
// resolves to.
264269
let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
265270

266271
// We only support cross-crate argument rewriting. Uses
@@ -669,10 +674,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
669674
}
670675

671676
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
672-
self.partial_res_overrides
673-
.get(&id)
674-
.or_else(|| self.resolver.partial_res_map.get(&id))
675-
.copied()
677+
match self.partial_res_overrides.get(&id) {
678+
Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
679+
None => self.resolver.partial_res_map.get(&id).copied(),
680+
}
676681
}
677682

678683
/// Given the id of an owner node in the AST, returns the corresponding `OwnerId`.

0 commit comments

Comments
 (0)