# Help test and provide feedback on \`'\_\` lifetimes!

**URL:** <https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093>\
**Category:** Uncategorized\
**Created:** [July 30, 2018, 10:54pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093 "2018-07-30T22:54:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexcrichton](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alexcrichton/32/4501_2.png) [@alexcrichton](https://internals.rust-lang.org/u/alexcrichton)\
**Post date:** [July 30, 2018, 10:54pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/1 "2018-07-30T22:54:11Z")

</div>

Hot on the heels of [last week’s call to action](https://internals.rust-lang.org/t/help-test-out-the-2018-module-system-changes/8047) about the module system changes in Rust 2018, this week we’d like to draw attention to and make a call for action on **`'_` (wildcard) lifetimes** coming to Rust 2018!

One of the features of [RFC 2115](https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md#the-wildcard-lifetime) is the “wildcard lifetime”, written as `'_`. Today lifetime elision allows signatures like:

```rust
fn foo(&self) -> Ref<SomeType>
fn iter(&self) -> Iter<T>

```

but these are hiding the fact that there’s a connected lifetime there. To ergonomically convey that there’s a lifetime contained inside you can now write this as:

```rust
fn foo(&self) -> Ref<'_, SomeType>
fn iter(&self) -> Iter<'_, T>

```

and the two snippets mean the same thing!

* * *

It’s not always easy to find locations in your crate that can use from `'_`, we’re after all trying to fix the problem that they’re so hidden! To help you with the transition we’ve developed a new lint for this feature, and the easiest way to follow the lint is to use `cargo fix`. Note that **you do not need to be in the 2018 edition to test this feature**.

1. Add `#![feature(rust_2018_preview)]` to your crate (skip this if you’re already on the 2018 edition)
2. Add `#![warn(elided_lifetimes_in_paths)]` to your crate
3. Run `cargo fix`

And that’s it! If you see any bugs please report them to [rust-lang/cargo](https://github.com/rust-lang/cargo/issues/new) or [rust-lang/rust](https://github.com/rust-lang/rust/issues/new). This includes things like cases the compiler should have linted for but didn’t, lint suggestions that fail to apply, etc.

Afterwards be sure to run `cargo doc`, try it out with the RLS, run `rustfmt` to see what happens, otherwise try to stress this feature! Like the module system we want to make sure that wildcard lifetimes are as polished as they can be for the 2018 edition, and we need your help!

In addition to testing our your own code and reporting bugs, we’d love to see some community-driven tutorials/documentation/podcasts about the feature! If you’re busy this week don’t worry as well, we’ll be making a call to action for a new feature next week!

And of course, please feel free to leave feedback here as well!

---

<div class="post-metadata">

**Author:** ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)\
**Post date:** [July 30, 2018, 11:06pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/2 "2018-07-30T23:06:39Z")

</div>

workspace users: If you previously did the module system stuff last week, here’s a quick fix to get all the annotations inserted. (assuming you didn’t do anything weird like `cfg_attr`; I’ve simply been doing the migrations on a separate branch)

```rust
sed -Ei 's/(\#!\[feature\(rust_2018_preview\)\])/\1\n#![warn(elided_lifetimes_in_paths)]/' $(find -name '*.rs')

```

(it is inserting the new `warn` annotation after each appearance of the `rust_2018_preview` feature)

---

<div class="post-metadata">

**Author:** ![steveklabnik](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steveklabnik/32/4524_2.png) [@steveklabnik](https://internals.rust-lang.org/u/steveklabnik)\
**Post date:** [July 30, 2018, 11:10pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/3 "2018-07-30T23:10:56Z")

</div>

One tiny annoyance I’ve noticed so far: documentation examples rarely (if ever) include the `'_`, which means that you can get warnings or errors when copying code straight from the docs.

The error messages are pretty clear, and I haven’t found it to be too much trouble to adapt, but it is a thing that made me realize how much I’m used to code from docs just working.

---

<div class="post-metadata">

**Author:** ![mersinvald](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mersinvald/32/4083_2.png) [@mersinvald](https://internals.rust-lang.org/u/mersinvald)\
**Post date:** [July 31, 2018, 4:32am UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/4 "2018-07-31T04:32:23Z")

</div>

Until that becomes an only option with implicit syntax deprecation – it is probably a good feature to have.

Though I can’t see a usecase if explicit elided lifetimes won’t give any improvements in lifetime inference.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [July 31, 2018, 11:47pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/5 "2018-07-31T23:47:02Z")

</div>

I’d love if rustdoc displayed them this way regardless of how the source code looks like.

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [August 4, 2018, 3:03pm UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/6 "2018-08-04T15:03:24Z")

</div>

One question is whether you should be allowed to elide lifetimes on argument types that are already behind a reference, e.g. [`task::Context`](https://doc.rust-lang.org/nightly/std/task/struct.Context.html) has a lifetime so currently `rustfix` rewrites signatures in implementations of [`Future::poll`](https://doc.rust-lang.org/nightly/std/future/trait.Future.html#tymethod.poll) to

```rust
fn poll(self: PinMut<'_, Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output>

```

where the `<'_>` on `Context` is not really providing much since the reference itself already has a limited lifetime.

---

<div class="post-metadata">

**Author:** ![alexcrichton](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alexcrichton/32/4501_2.png) [@alexcrichton](https://internals.rust-lang.org/u/alexcrichton)\
**Post date:** [March 25, 2019, 8:30am UTC](https://internals.rust-lang.org/t/help-test-and-provide-feedback-on-lifetimes/8093/7 "2019-03-25T08:30:37Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
