Unnamed repository; edit this file 'description' to name the repository.
Allow duplicate assoc type shorthand resolution if it points to the same assoc type
And with the same generic args.
Chayim Refael Friedman 6 weeks ago
parent 789ad51 · commit dbab646
-rw-r--r--crates/hir-ty/src/lower.rs8
-rw-r--r--crates/hir-ty/src/tests/regression.rs25
2 files changed, 31 insertions, 2 deletions
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index c49e943437..83b67bf1fe 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -1809,8 +1809,12 @@ fn resolve_type_param_assoc_type_shorthand(
return AssocTypeShorthandResolution::Ambiguous {
sub_trait_resolution: Some(this_trait_resolution),
};
- } else if supertraits_resolution.is_some() {
- return AssocTypeShorthandResolution::Ambiguous { sub_trait_resolution: None };
+ } else if let Some(prev_resolution) = &supertraits_resolution {
+ if prev_resolution == lookup_on_bounded_trait {
+ return AssocTypeShorthandResolution::Ambiguous { sub_trait_resolution: None };
+ } else {
+ continue;
+ }
} else {
let (assoc_type, args) = assoc_type_and_args
.get_with(|(assoc_type, args)| (*assoc_type, args.as_ref()))
diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs
index 1939db0ef5..d88801a57b 100644
--- a/crates/hir-ty/src/tests/regression.rs
+++ b/crates/hir-ty/src/tests/regression.rs
@@ -2815,3 +2815,28 @@ fn contains_0<S: Collection<Item = i32>>(points: &S) {
"#,
);
}
+
+#[test]
+fn regression_21773() {
+ check_no_mismatches(
+ r#"
+trait Neg {
+ type Output;
+}
+
+trait Abs: Neg {
+ fn abs(&self) -> Self::Output;
+}
+
+trait SelfAbs: Abs + Neg
+where
+ Self::Output: Neg<Output = Self::Output> + Abs,
+{
+}
+
+fn wrapped_abs<T: SelfAbs<Output = T>>(v: T) -> T {
+ v.abs()
+}
+ "#,
+ );
+}