Skip to content

Commit

Permalink
Auto merge of #17190 - dfireBird:dyn_trait_with_lifetimes_in_rpit, r=…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
bors committed May 5, 2024
2 parents 1a5bb27 + 8cbeb04 commit c4618fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 21 additions & 0 deletions crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
"#,
)
}

0 comments on commit c4618fe

Please sign in to comment.