Unnamed repository; edit this file 'description' to name the repository.
Check for local IDs belong to same definition
iDawer 2022-07-17
parent 766c5f0 · commit a0fd58b
-rw-r--r--crates/hir-ty/src/lower.rs5
-rw-r--r--crates/hir-ty/src/tests/traits.rs17
-rw-r--r--crates/ide-completion/src/completions/dot.rs22
3 files changed, 42 insertions, 2 deletions
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index f9747f3b34..c5304c1821 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -1161,8 +1161,9 @@ pub(crate) fn generic_predicates_for_param_query(
return false;
}
}
- WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
- if *local_id != param_id.local_id {
+ &WherePredicateTypeTarget::TypeOrConstParam(local_id) => {
+ let target_id = TypeOrConstParamId { parent: def, local_id };
+ if target_id != param_id {
return false;
}
}
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index 30c67d41b7..aa8b420e98 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -467,6 +467,23 @@ fn test<T: Iterable>() {
}
#[test]
+fn associated_type_shorthand_from_self_issue_12484() {
+ check_types(
+ r#"
+trait Bar {
+ type A;
+}
+trait Foo {
+ type A;
+ fn test(a: Self::A, _: impl Bar) {
+ a;
+ //^ Foo::A<Self>
+ }
+}"#,
+ );
+}
+
+#[test]
fn infer_associated_type_bound() {
check_types(
r#"
diff --git a/crates/ide-completion/src/completions/dot.rs b/crates/ide-completion/src/completions/dot.rs
index 911ef60930..727ec6e608 100644
--- a/crates/ide-completion/src/completions/dot.rs
+++ b/crates/ide-completion/src/completions/dot.rs
@@ -918,4 +918,26 @@ fn main() {
",
)
}
+
+ #[test]
+ fn issue_12484() {
+ check(
+ r#"
+//- minicore: sized
+trait SizeUser {
+ type Size;
+}
+trait Closure: SizeUser {}
+trait Encrypt: SizeUser {
+ fn encrypt(self, _: impl Closure<Size = Self::Size>);
+}
+fn test(thing: impl Encrypt) {
+ thing.$0;
+}
+ "#,
+ expect![[r#"
+ me encrypt(…) (as Encrypt) fn(self, impl Closure<Size = <Self as SizeUser>::Size>)
+ "#]],
+ )
+ }
}