Skip to content

Commit 4a56d54

Browse files
authored
Merge pull request #22032 from ChayimFriedman2/assoc-types-yet-again
fix: Allow ambiguity in assoc type shorthand if they resolve to the same assoc type, between supertraits this time
2 parents 5926ac2 + 94945e7 commit 4a56d54

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

crates/hir-ty/src/lower.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,10 +1869,14 @@ fn resolve_type_param_assoc_type_shorthand(
18691869
.skip_binder();
18701870
let args = EarlyBinder::bind(args).instantiate(interner, bounded_trait_ref.args);
18711871
let current_result = StoredEarlyBinder::bind((assoc_type, args.store()));
1872-
if let Some(this_trait_resolution) = this_trait_resolution {
1873-
return AssocTypeShorthandResolution::Ambiguous {
1874-
sub_trait_resolution: Some(this_trait_resolution),
1875-
};
1872+
if let Some(this_trait_resolution) = &this_trait_resolution {
1873+
if *this_trait_resolution == current_result {
1874+
continue;
1875+
} else {
1876+
return AssocTypeShorthandResolution::Ambiguous {
1877+
sub_trait_resolution: Some(this_trait_resolution.clone()),
1878+
};
1879+
}
18761880
} else if let Some(prev_resolution) = &supertraits_resolution {
18771881
if let AssocTypeShorthandResolution::Ambiguous {
18781882
sub_trait_resolution: Some(prev_resolution),

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,3 +2856,31 @@ fn foo<T: B>(v: T::T) {}
28562856
"#,
28572857
);
28582858
}
2859+
2860+
#[test]
2861+
fn regression_() {
2862+
check_types(
2863+
r#"
2864+
//- minicore: fn
2865+
trait Super {
2866+
type Assoc;
2867+
fn foo(self) -> Self::Assoc
2868+
where
2869+
Self: Sub,
2870+
{ loop {} }
2871+
}
2872+
trait Sub: Super {}
2873+
2874+
struct Struct;
2875+
impl Super for Struct {
2876+
type Assoc = u8;
2877+
}
2878+
impl Sub for Struct {}
2879+
2880+
fn foo() {
2881+
Struct.foo();
2882+
// ^^^^^^^^^^^^ u8
2883+
}
2884+
"#,
2885+
);
2886+
}

0 commit comments

Comments
 (0)