-
Notifications
You must be signed in to change notification settings - Fork 493
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
Lifetime elision #187
Lifetime elision #187
Conversation
@@ -59,50 +59,6 @@ unsafe fn bump_levels_unsafe2() -> u32 { | |||
Mutable statics have the same restrictions as normal statics, except that the | |||
type does not have to implement the `Sync` trait. | |||
|
|||
## `'static` lifetime elision |
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.
Not sure how, but it'd be nice for this page to say it's possible and link to the rules for it.
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.
There is at least a mention of this on the constant items page with a link.
bf6c2c3
to
d19507a
Compare
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.
So sorry for the very late review! This looks great-- just a couple nits.
src/lifetime-elision.md
Outdated
_default object lifetime bound_. These were defined in [RFC 599] and amended in | ||
[RFC 1156]. | ||
|
||
If the trait object is used as for a type argument of a generic type then the |
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.
"used as for a type"
src/lifetime-elision.md
Outdated
* If there is more than one bound from the containing type then an explicit | ||
bound must be specified | ||
|
||
Then the bounds on the trait 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.
The text doesn't make clear the relationship between these bullets and the previous ones.
d19507a
to
27d9924
Compare
changes made |
src/lifetime-elision.md
Outdated
In order to make common patterns more ergonomic, Rust allows lifetimes to be | ||
*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 infered. |
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.
inferred
src/lifetime-elision.md
Outdated
type FunTrait = for<'a> Fn(&'a str) -> &'a str; // expanded | ||
``` | ||
|
||
## Defaults trait object lifetimes |
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.
Default
* Don't talk about a future feature * Add examples of elision in function pointers/traits * A rule for 'static bounds on trait objects * Static lifetime elision doesn't happen in function pointers/traits
27d9924
to
1014b0d
Compare
Thanks, fixed now. |
cc @alercah |
I don't see anything that looks off to me, but I also don't have the time for a detailed read. |
Second PR to add documentation for lifetimes (next will probably moving the relevant parts of the NLL RFC text into the reference when it gets stabilised).
This is mostly existing documentation from the nomicon/reference. Significant changes from that documentation:
impl
headers)'static
is the preferred bound in trait objects with multiple bounds:const RESOLVED_STATIC: &Fn(&Foo, &Bar) -> &Baz
is invalid, not inferred with'static
lifetimes. (This matches: http://rust-lang.github.io/rfcs/1623-static.html, so I'm guessing that it's just a docs issue)cc #9 (rust-lang/rfcs#141)