From 8cbeb04ba2184bf834e11e7deabae269eeca644d Mon Sep 17 00:00:00 2001 From: dfireBird Date: Sun, 5 May 2024 23:40:34 +0530 Subject: [PATCH] fix lifetime bound var index in dyn trait --- crates/hir-ty/src/lower.rs | 9 ++++----- crates/hir-ty/src/tests/traits.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index f1315f6c8149..04ace3820219 100644 --- a/crates/hir-ty/src/lower.rs +++ b/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/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index 7a318877b723..18fc8afd183d 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/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 {} + +trait Trait {} + +pub async fn foo_async<'a>() -> Box { + Box {} +} + +fn foo() { + foo_async(); + //^^^^^^^^^^^impl Future> + ?Sized +} +"#, + ) +}