Skip to content

Commit 833aa91

Browse files
authored
Merge pull request #21785 from ChayimFriedman2/dup-assoc-res
fix: Allow duplicate assoc type shorthand resolution if it points to the same assoc type
2 parents 018847f + dbab646 commit 833aa91

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

crates/hir-ty/src/lower.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,8 +1809,12 @@ fn resolve_type_param_assoc_type_shorthand(
18091809
return AssocTypeShorthandResolution::Ambiguous {
18101810
sub_trait_resolution: Some(this_trait_resolution),
18111811
};
1812-
} else if supertraits_resolution.is_some() {
1813-
return AssocTypeShorthandResolution::Ambiguous { sub_trait_resolution: None };
1812+
} else if let Some(prev_resolution) = &supertraits_resolution {
1813+
if prev_resolution == lookup_on_bounded_trait {
1814+
return AssocTypeShorthandResolution::Ambiguous { sub_trait_resolution: None };
1815+
} else {
1816+
continue;
1817+
}
18141818
} else {
18151819
let (assoc_type, args) = assoc_type_and_args
18161820
.get_with(|(assoc_type, args)| (*assoc_type, args.as_ref()))

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,3 +2815,28 @@ fn contains_0<S: Collection<Item = i32>>(points: &S) {
28152815
"#,
28162816
);
28172817
}
2818+
2819+
#[test]
2820+
fn regression_21773() {
2821+
check_no_mismatches(
2822+
r#"
2823+
trait Neg {
2824+
type Output;
2825+
}
2826+
2827+
trait Abs: Neg {
2828+
fn abs(&self) -> Self::Output;
2829+
}
2830+
2831+
trait SelfAbs: Abs + Neg
2832+
where
2833+
Self::Output: Neg<Output = Self::Output> + Abs,
2834+
{
2835+
}
2836+
2837+
fn wrapped_abs<T: SelfAbs<Output = T>>(v: T) -> T {
2838+
v.abs()
2839+
}
2840+
"#,
2841+
);
2842+
}

0 commit comments

Comments
 (0)