Skip to content

RTN paths don't induce trait object lifetime defaults #151662

@fmease

Description

@fmease

This is the RTN version of #151649 (assoc consts) and #115379 (assoc tys).
Blocking this on PR #129543 which provides fundamental fixes and the necessary framework.


The following snippet should compile but it doesn't:

#![feature(return_type_notation)]

trait Trait<'a, T: ?Sized + 'a> {
    fn f() -> impl Sized;
}

fn f<'r, T: Trait<'r, dyn Bound + 'r>>()
where
    <T as Trait<'r, dyn Bound>>::f(..):
{}

trait Bound {}
error[E0308]: mismatched types
 --> src/lib.rs:9:5
  |
9 |     <T as Trait<'r, dyn Bound>>::f(..):
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
  |
  = note: expected trait `Trait<'r, (dyn Bound + 'static)>`
             found trait `Trait<'r, (dyn Bound + 'r)>`
note: the lifetime `'r` as defined here...
 --> src/lib.rs:7:6
  |
7 | fn f<'r, T: Trait<'r, dyn Bound + 'r>>()
  |      ^^
  = note: ...does not necessarily outlive the static lifetime

dyn Bound in the RTN path should get elaborated to dyn Bound + 'r but it gets elaborated to dyn Bound + 'static instead because associated functions aren't considered eligible containers.

Metadata

Metadata

Assignees

Labels

A-dyn-traitArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-return_type_notation`#[feature(return_type_notation)]`S-blockedStatus: Blocked on something else such as an RFC or other implementation work.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions