Skip to content

Commit ffc3232

Browse files
Merge pull request #22930 from shulaoda/07-27-fix_don_t_panic_on_a_qualified_path_whose_trait_is_not_a_trait
fix: don't panic on a qualified path whose trait is not a trait
2 parents 8f6a809 + 94af7e7 commit ffc3232

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

crates/hir-ty/src/lower/path.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,12 @@ pub(crate) fn substs_from_args_and_bindings<'db>(
12341234
};
12351235
params.next();
12361236
substs.push(self_ty);
1237+
} else if has_self_arg {
1238+
// A qualified path `<T as Trait>::Assoc` where `Trait` resolved to something without a
1239+
// `Self` parameter, e.g. a struct. `check_generic_args_len()` skips the self type
1240+
// unconditionally, so drop it here too instead of matching it against a real parameter.
1241+
// FIXME: Report a diagnostic here, rustc emits `E0404: expected trait, found struct`.
1242+
args.next();
12371243
}
12381244

12391245
loop {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,3 +3016,15 @@ fn f(s: S) { s.m(); }
30163016
"#,
30173017
);
30183018
}
3019+
3020+
#[test]
3021+
fn regression_22799() {
3022+
check_no_mismatches(
3023+
r#"
3024+
struct S;
3025+
fn f() {
3026+
<S as S>::S;
3027+
}
3028+
"#,
3029+
);
3030+
}

0 commit comments

Comments
 (0)