Skip to content

Commit c9109f2

Browse files
committed
Auto merge of #17789 - ShoyuVanilla:issue-17191, r=Veykril
fix: Insert a generic arg for `impl Trait` when lowering generic args Fixes #17191 We are not inserting a generic arg when lowering generics like ```rust fn foo<T: B<impl A>(..) { ... } ``` but when we are lowering predicates we do; https://github.com/rust-lang/rust-analyzer/blob/aa00ddcf654a35ba0eafe17247cf189958d33182/crates/hir-ty/src/lower.rs#L1697-L1718 https://github.com/rust-lang/rust-analyzer/blob/aa00ddcf654a35ba0eafe17247cf189958d33182/crates/hir-ty/src/lower.rs#L310 and this mismatch causes index out of bound panic while substituting the predicates
2 parents aa00ddc + 8fa454d commit c9109f2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ pub(super) fn lower_generic_args(
194194
match generic_arg {
195195
ast::GenericArg::TypeArg(type_arg) => {
196196
let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty());
197+
type_ref.walk(&mut |tr| {
198+
if let TypeRef::ImplTrait(bounds) = tr {
199+
lower_ctx.update_impl_traits_bounds(bounds.clone());
200+
}
201+
});
197202
args.push(GenericArg::Type(type_ref));
198203
}
199204
ast::GenericArg::AssocTypeArg(assoc_type_arg) => {

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

+19
Original file line numberDiff line numberDiff line change
@@ -2122,3 +2122,22 @@ fn test() {
21222122
"#,
21232123
)
21242124
}
2125+
2126+
#[test]
2127+
fn issue_17191() {
2128+
check_types(
2129+
r#"
2130+
trait A {
2131+
type Item;
2132+
}
2133+
2134+
trait B<T> {}
2135+
2136+
fn foo<T: B<impl A>>() {}
2137+
2138+
fn test() {
2139+
let f = foo;
2140+
//^ fn foo<{unknown}>()
2141+
}"#,
2142+
);
2143+
}

0 commit comments

Comments
 (0)