diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index baf9842d5f..5b0c1a6375 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -1190,9 +1190,9 @@ pub fn associated_type_shorthand_candidates( db: &dyn HirDatabase, def: GenericDefId, res: TypeNs, - cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option, + mut cb: impl FnMut(&Name, TypeAliasId) -> Option, ) -> Option { - named_associated_type_shorthand_candidates(db, def, res, None, cb) + named_associated_type_shorthand_candidates(db, def, res, None, |name, _, id| cb(name, id)) } fn named_associated_type_shorthand_candidates( @@ -1202,6 +1202,9 @@ fn named_associated_type_shorthand_candidates( def: GenericDefId, res: TypeNs, assoc_name: Option, + // Do NOT let `cb` touch `TraitRef` outside of `TyLoweringContext`. Its substitution contains + // free `BoundVar`s that need to be shifted and only `TyLoweringContext` knows how to do that + // properly (see `TyLoweringContext::select_associated_type()`). mut cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option, ) -> Option { let mut search = |t| { diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 2e1f88ba09..f887c75984 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -1600,7 +1600,7 @@ impl<'a> SemanticsScope<'a> { self.db, def, resolution.in_type_ns()?, - |name, _, id| cb(name, id.into()), + |name, id| cb(name, id.into()), ) } } diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 91ea1c24d1..38950b12a1 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -967,7 +967,7 @@ fn resolve_hir_path_( db, def, res.in_type_ns()?, - |name, _, id| (name == unresolved.name).then(|| id), + |name, id| (name == unresolved.name).then(|| id), ) }) .map(TypeAlias::from)