-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add lifetime elision information to the ownership guide. #19736
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
Conversation
fn print<'a>(s: &'a str); // expanded | ||
|
||
fn debug(lvl: uint, s: &str); // elided | ||
fn debug<'a>(lvl: uint, s: &'a str); // expanded |
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.
I think a comment here is warranted similar to this. If you don't recognize this, it is puzzling why int
doesn't get a lifetime too.
// `lvl` doesn't need a lifetime because it's not a reference (`&`). Only references need 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.
added
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.
It's not only references: struct Foo<'a> { ... }
would be fn foo<'a>(x: Foo<'a>)
.
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.
fixed
b0bb633
to
7afd56a
Compare
## Lifetime Elision | ||
|
||
Earlier, we mentioned 'lifetime elision,' a feature of Rust which allows you to | ||
not write lifetime annotations in certain circumstances. All references must |
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.
Maybe this could be "all references have a lifetime" or something else that emphasises that it is an inherent property of references.
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.
re-worded
7afd56a
to
5541207
Compare
r? @huonw |
fn foo<'a>() -> &'a str | ||
``` | ||
|
||
This one has both: |
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 has one, that is used in both input and output position.
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.
both meaning and input and output lifetime, even though they are the same one. Is it worth an extra few words?
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.
Addressed this
Fixes #19662.