Open
Description
Consider the following crate (test2
):
pub trait Foo { }
pub type FooDyn = dyn Foo;
pub struct Bar;
impl Bar {
pub fn bar(&self) -> &FooDyn {
unimplemented!();
}
}
Documentation for this crate says that FooDyn
and bar
signatures are the following:
type FooDyn = dyn Foo;
pub fn bar(&self) -> &FooDyn
You can assume that according to the lifetime elision rules you will get the following equivalent signature:
pub fn bar(&'a self) -> &'a FooDyn
However, it's not true. If you reexport FooDyn
and Bar
types in another crate (test1
), you will get the following signatures in test1
crate:
type FooDyn = dyn Foo + 'static;
pub fn bar(&self) -> &(dyn Foo + 'static)
One of the ways of resolving the issue is the following declaration:
pub type FooDyn<'a> = dyn 'a + Foo;
As for me, it's strange to have 'static
lifetime here by default, so maybe there should be an error if lifetime is omitted.