This is a sub-issue of #44524, tracking the desire to stabilize '_ (and the lints around its usage).
Covered areas
The '_ can be used anywhere that a region can be elided. It (typically) carries the same meaning as having no region at all. This section summarizes its usage, giving pointers to tests, and also listing known blocking issues.
fn foo(x: Ref<'_>) -- fresh name
fn foo(&self) -> Ref<'_> -- links to self
fn foo(&self) -> Box<dyn Debug + '_> -- links to self, not quite the same as Box<dyn Debug>
fn foo(&self) -> Box<impl Debug + '_> -- links to self, not quite the same as Box<impl Debug>
Some areas where elision ought to be supported are not yet:
There are also several linted scenarios to nudge the user in the right direction:
- Eliding parameters of a lifetime-parameterized struct (e.g.,
Ref) is deprecated, prefer Ref<'_>
- Lifetime names used only once are deprecated:
Changes or clarifications to the RFC
The behavior around dyn Trait is probably worth highlighting, since it is one case where '_ differs from writing nothing at all.
This is a sub-issue of #44524, tracking the desire to stabilize
'_(and the lints around its usage).Covered areas
The
'_can be used anywhere that a region can be elided. It (typically) carries the same meaning as having no region at all. This section summarizes its usage, giving pointers to tests, and also listing known blocking issues.fn foo(x: Ref<'_>)-- fresh namefn foo(&self) -> Ref<'_>-- links toselffn foo(&self) -> Box<dyn Debug + '_>-- links toself, not quite the same asBox<dyn Debug>'_arounddyn Traitis wrong #48468fn foo(&self) -> Box<impl Debug + '_>-- links toself, not quite the same asBox<impl Debug>Some areas where elision ought to be supported are not yet:
impl Foo for Ref<'_>-- not yet implemented, this is Tracking issue for lifetime elision for impl headers (feature impl_header_lifetime_elision) #15872where T: Trait<'_>-- not yet implemented, this is enable elision in where-clauses on functions #45667There are also several linted scenarios to nudge the user in the right direction:
Ref) is deprecated, preferRef<'_>#[warn(elided_lifetimes_in_paths)]elided_lifetime_in_pathtriggers for theformat!macro #48385 -- triggers forformat!#[warn(single_use_lifetime)]Changes or clarifications to the RFC
The behavior around
dyn Traitis probably worth highlighting, since it is one case where'_differs from writing nothing at all.