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.
This commit is contained in:
Camille GILLOT
2022-01-12 20:04:04 +01:00
parent 554aceba49
commit 7b285925c8

View File

@@ -1240,15 +1240,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
); );
let res = res.base_res(); let res = res.base_res();
if res != Res::Err { if res != Res::Err {
new_id = Some(res.def_id());
let span = trait_ref.path.span;
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = self.resolve_path( if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = self.resolve_path(
&path, &path,
Some(TypeNS), Some(TypeNS),
false, true,
span, trait_ref.path.span,
CrateLint::SimplePath(trait_ref.ref_id), CrateLint::SimplePath(trait_ref.ref_id),
) { ) {
new_id = Some(res.def_id());
new_val = Some((module, trait_ref.clone())); new_val = Some((module, trait_ref.clone()));
} }
} }
@@ -1413,7 +1412,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
fn check_trait_item<F>( fn check_trait_item<F>(
&mut self, &mut self,
id: NodeId, id: NodeId,
ident: Ident, mut ident: Ident,
kind: &AssocItemKind, kind: &AssocItemKind,
ns: Namespace, ns: Namespace,
span: Span, span: Span,
@@ -1423,15 +1422,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
{ {
// If there is a TraitRef in scope for an impl, then the method must be in the trait. // If there is a TraitRef in scope for an impl, then the method must be in the trait.
let Some((module, _)) = &self.current_trait_ref else { return; }; let Some((module, _)) = &self.current_trait_ref else { return; };
let mut binding = self.r.resolve_ident_in_module( ident.span.normalize_to_macros_2_0_and_adjust(module.expansion);
ModuleOrUniformRoot::Module(module), let key = self.r.new_key(ident, ns);
ident, let mut binding = self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.binding);
ns, debug!(?binding);
&self.parent_scope, if binding.is_none() {
false,
span,
);
if binding.is_err() {
// We could not find the trait item in the correct namespace. // We could not find the trait item in the correct namespace.
// Check the other namespace to report an error. // Check the other namespace to report an error.
let ns = match ns { let ns = match ns {
@@ -1439,16 +1434,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
TypeNS => ValueNS, TypeNS => ValueNS,
_ => ns, _ => ns,
}; };
binding = self.r.resolve_ident_in_module( let key = self.r.new_key(ident, ns);
ModuleOrUniformRoot::Module(module), binding = self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.binding);
ident, debug!(?binding);
ns,
&self.parent_scope,
false,
span,
);
} }
let Ok(binding) = binding else { let Some(binding) = binding else {
// We could not find the method: report an error. // We could not find the method: report an error.
let candidate = self.find_similarly_named_assoc_item(ident.name, kind); let candidate = self.find_similarly_named_assoc_item(ident.name, kind);
let path = &self.current_trait_ref.as_ref().unwrap().1.path; let path = &self.current_trait_ref.as_ref().unwrap().1.path;