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>(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 + Abs, +{ +} + +fn wrapped_abs>(v: T) -> T { + v.abs() +} + "#, + ); +}