mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-06 04:06:31 +00:00

When given ```rust trait Original { fn f() -> impl Fn(); } trait Erased { fn f(&self) -> Box<dyn Fn()>; } impl<T: Original> Erased for T { fn f(&self) -> Box<dyn Fn()> { Box::new(<T as Original>::f()) } } ``` avoid suggestion to restrict the `Trait::{opaque}` type in a `where` clause: ``` error[E0310]: the associated type `<T as Original>::{opaque#0}` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(<T as Original>::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the associated type `<T as Original>::{opaque#0}` must be valid for the static lifetime... | ...so that the type `impl Fn()` will meet its required lifetime bounds ``` CC #119773.
17 lines
321 B
Rust
17 lines
321 B
Rust
trait Original {
|
|
fn f() -> impl Fn();
|
|
}
|
|
|
|
trait Erased {
|
|
fn f(&self) -> Box<dyn Fn()>;
|
|
}
|
|
|
|
impl<T: Original> Erased for T {
|
|
fn f(&self) -> Box<dyn Fn()> {
|
|
Box::new(<T as Original>::f())
|
|
//~^ ERROR the associated type `<T as Original>::{opaque#0}` may not live long enough
|
|
}
|
|
}
|
|
|
|
fn main () {}
|