Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document underscore lifetime elision #334

Merged
merged 3 commits into from
Jun 4, 2018

Conversation

matthewjasper
Copy link
Contributor

cc #278 There don't seem to be any cases where '_ could be used outside of this chapter.

'_ can also be used for inferred lifetimes, but I don't think there is any documentation for them yet.

Also uses dyn trait in the elision chapter (cc #279)

The following rules are used to infer lifetime parameters for elided lifetimes.
It is an error to elide lifetime parameters that cannot be inferred.
An elided lifetime can be specified either by omitting it, or by using `'_`.
For lifetimes in paths, using `'_` is preferred. The following rules are used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things here:

  • What is a lifetime in a path? Do you mean as a parameter?
  • Should probably mention that omitting a lifetime in a trait object type is equivalent to 'static, not '_.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is '_ not preferred for references as well? I thought omitting lifetimes was going to be deprecated.

@matthewjasper
Copy link
Contributor Author

Comments addressed.

Also, is '_ not preferred for references as well? I thought omitting lifetimes was going to be deprecated.

The RFC says

When referring to a type (other than &/&mut) that requires lifetime arguments, it is deprecated to leave off those parameters.

@matthewjasper matthewjasper force-pushed the underscore-lifetime branch from 1542cfa to 0ff4f94 Compare May 13, 2018 17:46
@alercah
Copy link
Contributor

alercah commented May 13, 2018

Ah, my bad, excellent.

@matthewjasper matthewjasper force-pushed the underscore-lifetime branch from 0ff4f94 to a130835 Compare May 29, 2018 19:01
parameter elision rules defined above.
[RFC 1156].

> These default object lifetime bounds are used instead of the lifetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be a Note?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was intentional. I've changed it back to normal prose now.

@matthewjasper matthewjasper force-pushed the underscore-lifetime branch from a130835 to 2e5c339 Compare June 3, 2018 21:45
*elided* in [function item], [function pointer] and [closure trait] signatures.
The following rules are used to infer lifetime parameters for elided lifetimes.
It is an error to elide lifetime parameters that cannot be inferred.
In order to make common patterns more ergonomic, Rust allows lifetime argument
Copy link
Contributor

@Havvy Havvy Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the "Rust allows" here? Would have to change the wording a bit too. I can do it in a follow up PR if you don't want to.

Copy link
Contributor

@Havvy Havvy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. If you want to make the one change I suggested, do so. Otherwise, r+ = me and you can merge it yourself.

@matthewjasper matthewjasper merged commit 320c8e7 into rust-lang:master Jun 4, 2018
@matthewjasper matthewjasper deleted the underscore-lifetime branch October 18, 2018 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants