Skip to content

TAIT regression: requires new lifetime bounds #95922

Closed
@aliemjay

Description

@aliemjay

Edit: The original example was indeed unsound so it's thankfully rejected now. See this comment for a sound example that gets rejected.

Original unsound code

#![feature(type_alias_impl_trait)]
use core::future::Future;

trait Service<'a, Req> {
    type Future: Future;
    fn call(req: &'a Req) -> Self::Future;
}

impl<'a, Req> Service<'a, Req> for u8 {
    type Future = impl Future;
    fn call(req: &'a Req) -> Self::Future {
        async move { let x = req; }
    }
}

(Playground)

This code used to compile fine prior to #95519. It now requires an explicit lifetime bound Req: 'a to the impl.

Unfortunately, adding a lifetime bound may not be an option when used with HRTBS due to limitations like #95921. This caused a major breakage on my part.

Meta

regressed in the nightly version 1.62.0-nightly (f4a7ce997 2022-04-08)

Error Output

   Compiling rust-ci v0.1.0 (/home/runner/work/rust-ci/rust-ci)
error[E0309]: the parameter type `Req` may not live long enough
Error:   --> src/lib.rs:10:19
   |
10 |     type Future = impl Future;
   |                   ^^^^^^^^^^^
   |
   = help: consider adding an explicit lifetime bound `Req: 'a`...
   = note: ...so that the reference type `&'a Req` does not outlive the data it points at

For more information about this error, try `rustc --explain E0309`.
error: could not compile `rust-ci` due to previous error

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions