fix: Wrong BoundVar index when lowering impl trait parameter of parent generics #17916
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #17711
From the following test code;
when we call
register_obligations_for_call
forlet _ = self.foo();
,rust-analyzer/crates/hir-ty/src/infer/expr.rs
Lines 1939 to 1952 in 0765978
we are querying
generic_predicates
and it hasT: Deref<Target = impl Trait>
predicate from the parentimpl Struct
;rust-analyzer/crates/hir-ty/src/lower.rs
Lines 375 to 399 in 0765978
but as we can see above, lowering
TypeRef = impl Trait
doesn't take into account the parent generic parameters, so theBoundVar
index here is0
, asfn foo
has no generic args other than parent's,But this
BoundVar
is pointing at'a
in<'a, T: Deref<Target = impl Trait>>
.So, in the first code reference
register_obligations_for_call
's L:1948 -.substitute(Interner, parameters)
, we are substituting'a
withTy
, notLifetime
and this makes panic inside the chalk.This PR fixes this wrong
BoundVar
index in such cases