-
Notifications
You must be signed in to change notification settings - Fork 507
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
Document underscore lifetime elision #334
Conversation
src/lifetime-elision.md
Outdated
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 |
There was a problem hiding this comment.
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'_
.
There was a problem hiding this comment.
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.
Comments addressed.
The RFC says
|
1542cfa
to
0ff4f94
Compare
Ah, my bad, excellent. |
0ff4f94
to
a130835
Compare
src/lifetime-elision.md
Outdated
parameter elision rules defined above. | ||
[RFC 1156]. | ||
|
||
> These default object lifetime bounds are used instead of the lifetime |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
a130835
to
2e5c339
Compare
src/lifetime-elision.md
Outdated
*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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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)