Skip to content

Commit 7b28592

Browse files
committed
Ensure res and module are consistent with each other.
The `record_used` parameter changes the result, so we must pass the same value for initial and module resolution.
1 parent 554aceb commit 7b28592

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,15 +1240,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12401240
);
12411241
let res = res.base_res();
12421242
if res != Res::Err {
1243-
new_id = Some(res.def_id());
1244-
let span = trait_ref.path.span;
12451243
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = self.resolve_path(
12461244
&path,
12471245
Some(TypeNS),
1248-
false,
1249-
span,
1246+
true,
1247+
trait_ref.path.span,
12501248
CrateLint::SimplePath(trait_ref.ref_id),
12511249
) {
1250+
new_id = Some(res.def_id());
12521251
new_val = Some((module, trait_ref.clone()));
12531252
}
12541253
}
@@ -1413,7 +1412,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14131412
fn check_trait_item<F>(
14141413
&mut self,
14151414
id: NodeId,
1416-
ident: Ident,
1415+
mut ident: Ident,
14171416
kind: &AssocItemKind,
14181417
ns: Namespace,
14191418
span: Span,
@@ -1423,32 +1422,23 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14231422
{
14241423
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
14251424
let Some((module, _)) = &self.current_trait_ref else { return; };
1426-
let mut binding = self.r.resolve_ident_in_module(
1427-
ModuleOrUniformRoot::Module(module),
1428-
ident,
1429-
ns,
1430-
&self.parent_scope,
1431-
false,
1432-
span,
1433-
);
1434-
if binding.is_err() {
1425+
ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
1426+
let key = self.r.new_key(ident, ns);
1427+
let mut binding = self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.binding);
1428+
debug!(?binding);
1429+
if binding.is_none() {
14351430
// We could not find the trait item in the correct namespace.
14361431
// Check the other namespace to report an error.
14371432
let ns = match ns {
14381433
ValueNS => TypeNS,
14391434
TypeNS => ValueNS,
14401435
_ => ns,
14411436
};
1442-
binding = self.r.resolve_ident_in_module(
1443-
ModuleOrUniformRoot::Module(module),
1444-
ident,
1445-
ns,
1446-
&self.parent_scope,
1447-
false,
1448-
span,
1449-
);
1437+
let key = self.r.new_key(ident, ns);
1438+
binding = self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.binding);
1439+
debug!(?binding);
14501440
}
1451-
let Ok(binding) = binding else {
1441+
let Some(binding) = binding else {
14521442
// We could not find the method: report an error.
14531443
let candidate = self.find_similarly_named_assoc_item(ident.name, kind);
14541444
let path = &self.current_trait_ref.as_ref().unwrap().1.path;

0 commit comments

Comments
 (0)