about summary refs log tree commit diff
path: root/tests/codegen/patchable-function-entry/patchable-function-entry-no-flag.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-17 17:00:52 +0000
committerbors <bors@rust-lang.org>2024-08-17 17:00:52 +0000
commiteb12861e48e069e562e01da23a2755fcf67ab282 (patch)
treea8c25e678a8c8c78b861177e758b2c02b3e9a9f7 /tests/codegen/patchable-function-entry/patchable-function-entry-no-flag.rs
parentd2d41b4419c3fca5da69afa17c4136a98dd446d0 (diff)
parentc4b8c657e40076505d4da332c467214fbabe99ad (diff)
downloadrust-eb12861e48e069e562e01da23a2755fcf67ab282.tar.gz
rust-eb12861e48e069e562e01da23a2755fcf67ab282.zip
Auto merge of #17916 - ShoyuVanilla:issue-17711, r=Veykril
fix: Wrong BoundVar index when lowering impl trait parameter of parent generics

Fixes #17711

From the following test code;

```rust
//- minicore: deref
use core::ops::Deref;

struct Struct<'a, T>(&'a T);

trait Trait {}

impl<'a, T: Deref<Target = impl Trait>> Struct<'a, T> {
    fn foo(&self) -> &Self { self }

    fn bar(&self) {
        let _ = self.foo();
    }

}
```

when we call `register_obligations_for_call` for `let _ = self.foo();`,

https://github.com/rust-lang/rust-analyzer/blob/07659783fdfd4ec0a0bffa93017e33e31e567e42/crates/hir-ty/src/infer/expr.rs#L1939-L1952

we are querying `generic_predicates` and it has `T: Deref<Target = impl Trait>` predicate from the parent `impl Struct`;

https://github.com/rust-lang/rust-analyzer/blob/07659783fdfd4ec0a0bffa93017e33e31e567e42/crates/hir-ty/src/lower.rs#L375-L399

but as we can see above, lowering `TypeRef = impl Trait` doesn't take into account the parent generic parameters, so the `BoundVar` index here is `0`, as `fn 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` with `Ty`, not `Lifetime` and this makes panic inside the chalk.

This PR fixes this wrong `BoundVar` index in such cases
Diffstat (limited to 'tests/codegen/patchable-function-entry/patchable-function-entry-no-flag.rs')
0 files changed, 0 insertions, 0 deletions