Skip to content

Commit 46e1486

Browse files
committed
Disallow access to free BoundVars outside TyLoweringContext
1 parent f9bd487 commit 46e1486

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

crates/hir-ty/src/lower.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,9 @@ pub fn associated_type_shorthand_candidates<R>(
11901190
db: &dyn HirDatabase,
11911191
def: GenericDefId,
11921192
res: TypeNs,
1193-
cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option<R>,
1193+
mut cb: impl FnMut(&Name, TypeAliasId) -> Option<R>,
11941194
) -> Option<R> {
1195-
named_associated_type_shorthand_candidates(db, def, res, None, cb)
1195+
named_associated_type_shorthand_candidates(db, def, res, None, |name, _, id| cb(name, id))
11961196
}
11971197

11981198
fn named_associated_type_shorthand_candidates<R>(
@@ -1202,6 +1202,9 @@ fn named_associated_type_shorthand_candidates<R>(
12021202
def: GenericDefId,
12031203
res: TypeNs,
12041204
assoc_name: Option<Name>,
1205+
// Do NOT let `cb` touch `TraitRef` outside of `TyLoweringContext`. Its substitution contains
1206+
// free `BoundVar`s that need to be shifted and only `TyLoweringContext` knows how to do that
1207+
// properly (see `TyLoweringContext::select_associated_type()`).
12051208
mut cb: impl FnMut(&Name, &TraitRef, TypeAliasId) -> Option<R>,
12061209
) -> Option<R> {
12071210
let mut search = |t| {

crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'a> SemanticsScope<'a> {
16001600
self.db,
16011601
def,
16021602
resolution.in_type_ns()?,
1603-
|name, _, id| cb(name, id.into()),
1603+
|name, id| cb(name, id.into()),
16041604
)
16051605
}
16061606
}

crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ fn resolve_hir_path_(
967967
db,
968968
def,
969969
res.in_type_ns()?,
970-
|name, _, id| (name == unresolved.name).then(|| id),
970+
|name, id| (name == unresolved.name).then(|| id),
971971
)
972972
})
973973
.map(TypeAlias::from)

0 commit comments

Comments
 (0)