Closed
Description
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 toself
fn foo(&self) -> Box<dyn Debug + '_>
-- links toself
, not quite the same asBox<dyn Debug>
fn 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 #45667- also, what semantics are desired here? Where is the binder?
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, preferRef<'_>
#[warn(elided_lifetimes_in_paths)]
- blocked on
elided_lifetime_in_path
triggers for theformat!
macro #48385 -- triggers forformat!
- Lifetime names used only once are deprecated:
#[warn(single_use_lifetime)]
- blocked on In-band lifetimes: Lint against single-use lifetime names #44752 -- only partially impemented
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.