-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsNLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goal
Description
This is simplified from some real code I have.
use std::borrow::BorrowMut;
use std::marker::PhantomData;
trait T {}
impl<X> T for Box<X> where X: T {}
struct S<'a> {
phantom: PhantomData<&'a u32>,
}
struct U;
impl T for U {}
fn f1<'a, R>(_: R) -> impl T + 'static
where R: BorrowMut<S<'a>>
{
let f = Box::new(U);
f
}
fn f2<'a>(s: S<'a>) -> impl T + 'static {
f1::<S<'a>>(s)
}
fn f1_boxed<'a, R>(_: R) -> Box<T>
where R: BorrowMut<S<'a>>
{
let f = Box::new(U);
f
}
fn f2_boxed<'a>(s: S<'a>) -> Box<T> {
f1_boxed::<S<'a>>(s)
}
The boxed versions compile fine, but the impl Trait version fails with
error[E0477]: the type `impl T` does not fulfill the required lifetime
--> src/lib.rs:23:24
|
23 | fn f2<'a>(s: S<'a>) -> impl T + 'static {
| ^^^^^^^^^^^^^^^^
|
= note: type must satisfy the static lifetime
I see this on both stable and 1.30.0-nightly (7061b27 2018-08-28).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsNLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goal