diff options
| author | bors <bors@rust-lang.org> | 2024-05-05 19:20:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-05-05 19:20:35 +0000 |
| commit | c50b357efe81c4632ce3875496029fc596be0e8b (patch) | |
| tree | a4fe1dcc089fe8788f3a84b88a4dc866e5917f73 | |
| parent | fb230553d8ca52fde52f1c59643f8e9ecd63cb2d (diff) | |
| parent | 4de215ad634c2e99104de7319b6fb8fc7da7390d (diff) | |
| download | rust-c50b357efe81c4632ce3875496029fc596be0e8b.tar.gz rust-c50b357efe81c4632ce3875496029fc596be0e8b.zip | |
Auto merge of #17190 - dfireBird:dyn_trait_with_lifetimes_in_rpit, r=Veykril
Fix: Lifetime's Bound Var Debrujin Index in Dyn Traits Surely fixes #17182 I have tried running the analysis-stats in some of the repos mentioned in #17080. No panic in almost all of them.
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/lower.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs | 21 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs index f1315f6c814..04ace382021 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs @@ -1311,11 +1311,10 @@ impl<'a> TyLoweringContext<'a> { bounds, lifetime: match lifetime { Some(it) => match it.bound_var(Interner) { - Some(bound_var) => LifetimeData::BoundVar(BoundVar::new( - DebruijnIndex::INNERMOST, - bound_var.index, - )) - .intern(Interner), + Some(bound_var) => bound_var + .shifted_out_to(DebruijnIndex::new(2)) + .map(|bound_var| LifetimeData::BoundVar(bound_var).intern(Interner)) + .unwrap_or(it), None => it, }, None => static_lifetime(), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs index 7a318877b72..18fc8afd183 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs @@ -4803,3 +4803,24 @@ fn foo() { "#, ); } + +#[test] +fn dyn_trait_with_lifetime_in_rpit() { + check_types( + r#" +//- minicore: future +pub struct Box<T> {} + +trait Trait {} + +pub async fn foo_async<'a>() -> Box<dyn Trait + 'a> { + Box {} +} + +fn foo() { + foo_async(); + //^^^^^^^^^^^impl Future<Output = Box<dyn Trait>> + ?Sized +} +"#, + ) +} |
