Disallow access to free BoundVars outside TyLoweringContext

This commit is contained in:
Ryo Yoshida 2022-12-07 23:22:37 +09:00
parent f9bd487708
commit 46e1486a90
No known key found for this signature in database
GPG key ID: E25698A930586171
3 changed files with 7 additions and 4 deletions

View file

@ -1190,9 +1190,9 @@ pub fn associated_type_shorthand_candidates<R>(
db: &dyn HirDatabase, db: &dyn HirDatabase,
def: GenericDefId, def: GenericDefId,
res: TypeNs, res: TypeNs,
cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option<R>, mut cb: impl FnMut(&Name, TypeAliasId) -> Option<R>,
) -> Option<R> { ) -> Option<R> {
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<R>( fn named_associated_type_shorthand_candidates<R>(
@ -1202,6 +1202,9 @@ fn named_associated_type_shorthand_candidates<R>(
def: GenericDefId, def: GenericDefId,
res: TypeNs, res: TypeNs,
assoc_name: Option<Name>, assoc_name: Option<Name>,
// 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<R>, mut cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option<R>,
) -> Option<R> { ) -> Option<R> {
let mut search = |t| { let mut search = |t| {

View file

@ -1600,7 +1600,7 @@ impl<'a> SemanticsScope<'a> {
self.db, self.db,
def, def,
resolution.in_type_ns()?, resolution.in_type_ns()?,
|name, _, id| cb(name, id.into()), |name, id| cb(name, id.into()),
) )
} }
} }

View file

@ -967,7 +967,7 @@ fn resolve_hir_path_(
db, db,
def, def,
res.in_type_ns()?, res.in_type_ns()?,
|name, _, id| (name == unresolved.name).then(|| id), |name, id| (name == unresolved.name).then(|| id),
) )
}) })
.map(TypeAlias::from) .map(TypeAlias::from)