Skip to content

Commit 667fd25

Browse files
committed
Auto merge of #12781 - iDawer:hir_display.stack_overflow, r=lnicola
fix: Stack overflows and wrong type inference of associated type shorthands This fixes `generic_predicates_for_param_query` comparing local IDs that belong to different definitions. As the query is used in multiple places this fix affects various r-a features when an associated type shorthand and `impl Trait` involved. Notably inference, goto, completion, hover. Fixes #12484
2 parents 766c5f0 + a0fd58b commit 667fd25

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

crates/hir-ty/src/lower.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,9 @@ pub(crate) fn generic_predicates_for_param_query(
11611161
return false;
11621162
}
11631163
}
1164-
WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
1165-
if *local_id != param_id.local_id {
1164+
&WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
1165+
let target_id = TypeOrConstParamId { parent: def, local_id };
1166+
if target_id != param_id {
11661167
return false;
11671168
}
11681169
}

crates/hir-ty/src/tests/traits.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ fn test<T: Iterable>() {
466466
);
467467
}
468468

469+
#[test]
470+
fn associated_type_shorthand_from_self_issue_12484() {
471+
check_types(
472+
r#"
473+
trait Bar {
474+
type A;
475+
}
476+
trait Foo {
477+
type A;
478+
fn test(a: Self::A, _: impl Bar) {
479+
a;
480+
//^ Foo::A<Self>
481+
}
482+
}"#,
483+
);
484+
}
485+
469486
#[test]
470487
fn infer_associated_type_bound() {
471488
check_types(

crates/ide-completion/src/completions/dot.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,4 +918,26 @@ fn main() {
918918
",
919919
)
920920
}
921+
922+
#[test]
923+
fn issue_12484() {
924+
check(
925+
r#"
926+
//- minicore: sized
927+
trait SizeUser {
928+
type Size;
929+
}
930+
trait Closure: SizeUser {}
931+
trait Encrypt: SizeUser {
932+
fn encrypt(self, _: impl Closure<Size = Self::Size>);
933+
}
934+
fn test(thing: impl Encrypt) {
935+
thing.$0;
936+
}
937+
"#,
938+
expect![[r#"
939+
me encrypt(…) (as Encrypt) fn(self, impl Closure<Size = <Self as SizeUser>::Size>)
940+
"#]],
941+
)
942+
}
921943
}

0 commit comments

Comments
 (0)