Skip to content

RPITITs don't inherit outlives bounds after >1 layer of nesting #114601

Closed
@compiler-errors

Description

@compiler-errors

I tried this code:

#![feature(return_position_impl_trait_in_trait)]

trait Foo {
    fn early<'a, T: 'a>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;

    fn late<'a, T>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;
}

I expected to see it compile.

Instead, this happened:

error[E0309]: the parameter type `T` may not live long enough
 --> src/lib.rs:4:64
  |
4 |     fn early<'a, T: 'a>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;
  |                                                                ^^^^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
  |
help: consider adding an explicit lifetime bound...
  |
4 |     fn early<'a, T: 'a + 'a>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;
  |                        ++++

error[E0309]: the parameter type `T` may not live long enough
 --> src/lib.rs:6:59
  |
6 |     fn late<'a, T>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;
  |                                                           ^^^^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
  |
help: consider adding an explicit lifetime bound...
  |
6 |     fn late<'a, T: 'a>(x: &'a T) -> impl Iterator<Item = impl Into<&'a T>>;
  |                  ++++

#112682 didn't install bidirectional outlives bounds 100% correctly when the lifetimes are being inherited past one layer of impl Trait.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions