Closed
Description
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; }
}
}
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
Type
Projects
Status
Done