Unnamed repository; edit this file 'description' to name the repository.
fix: don't panic on a qualified path whose trait is not a trait
| -rw-r--r-- | crates/hir-ty/src/lower/path.rs | 6 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/regression.rs | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index 554a191d9d..c67c69520d 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -1234,6 +1234,12 @@ pub(crate) fn substs_from_args_and_bindings<'db>( }; params.next(); substs.push(self_ty); + } else if has_self_arg { + // A qualified path `<T as Trait>::Assoc` where `Trait` resolved to something without a + // `Self` parameter, e.g. a struct. `check_generic_args_len()` skips the self type + // unconditionally, so drop it here too instead of matching it against a real parameter. + // FIXME: Report a diagnostic here, rustc emits `E0404: expected trait, found struct`. + args.next(); } loop { diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index c580841244..2836f977a9 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -3016,3 +3016,15 @@ fn f(s: S) { s.m(); } "#, ); } + +#[test] +fn regression_22799() { + check_no_mismatches( + r#" +struct S; +fn f() { + <S as S>::S; +} + "#, + ); +} |