Lighten and document partial_res_overrides.

This commit is contained in:
Camille Gillot
2026-04-21 23:46:17 +00:00
parent 9044aba8e1
commit 4433512e90
2 changed files with 12 additions and 8 deletions
@@ -39,7 +39,7 @@
use std::iter;
use ast::visit::Visitor;
use hir::def::{DefKind, PartialRes, Res};
use hir::def::{DefKind, Res};
use hir::{BodyId, HirId};
use rustc_abi::ExternAbi;
use rustc_ast as ast;
@@ -677,8 +677,7 @@ fn try_replace_id(&mut self, id: NodeId) {
&& let Some(Res::Local(sig_id)) = res.full_res()
&& sig_id == self.path_id
{
let new_res = PartialRes::new(Res::Local(self.self_param_id));
self.ctxt.partial_res_overrides.insert(id, new_res);
self.ctxt.partial_res_overrides.insert(id, self.self_param_id);
}
}
}
+10 -5
View File
@@ -145,7 +145,9 @@ struct LoweringContext<'a, 'hir> {
/// Maps the `NodeId`s created during lowering to `LocalDefId`s.
node_id_to_def_id: NodeMap<LocalDefId>,
/// Overlay over resolver's `partial_res_map` used by delegation.
partial_res_overrides: NodeMap<PartialRes>,
/// This only contains `PartialRes::new(Res::Local(self_param_id))`,
/// so we only store `self_param_id`.
partial_res_overrides: NodeMap<NodeId>,
allow_contracts: Arc<[Symbol]>,
allow_try_trait: Arc<[Symbol]>,
@@ -261,6 +263,9 @@ fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>) -> Option<Ve
return None;
}
// We do not need to look at `partial_res_overrides`. That map only contains overrides for
// `self_param` locals. And here we are looking for the function definition that `expr`
// resolves to.
let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
// We only support cross-crate argument rewriting. Uses
@@ -669,10 +674,10 @@ fn local_def_id(&self, node: NodeId) -> LocalDefId {
}
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
self.partial_res_overrides
.get(&id)
.or_else(|| self.resolver.partial_res_map.get(&id))
.copied()
match self.partial_res_overrides.get(&id) {
Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
None => self.resolver.partial_res_map.get(&id).copied(),
}
}
/// Given the id of an owner node in the AST, returns the corresponding `OwnerId`.