-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Added detailed error code explanation for issue E0688 in Rust compiler. #72654
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
In-band lifetimes has mixed with explicit lifetime binders. | ||||||
|
||||||
Erroneous code example: | ||||||
|
||||||
```compile_fail,E0688 | ||||||
#![feature(in_band_lifetimes)] | ||||||
|
||||||
fn foo<'a>(x: &'a u32, y: &'b u32) {} // error! | ||||||
|
||||||
struct Foo<'a> { x: &'a u32 } | ||||||
|
||||||
impl Foo<'a> { | ||||||
fn bar<'b>(x: &'a u32, y: &'b u32, z: &'c u32) {} // error! | ||||||
} | ||||||
|
||||||
impl<'b> Foo<'a> { // error! | ||||||
fn baz() {} | ||||||
} | ||||||
``` | ||||||
|
||||||
We cannot mix in-band lifetimes with explicit lifetime binders. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is really just a re-phrasing of the error, it'd be great to elaborate a little - something like "a function/struct/whatever can either have explicit lifetime binders or in-band lifetimes". |
||||||
For example: | ||||||
|
||||||
``` | ||||||
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) {} // ok! | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also add another example where only in-band lifetimes are used (with a short sentence before each example explaining how they differ). |
||||||
|
||||||
struct Foo<'a> { x: &'a u32 } | ||||||
|
||||||
impl<'a> Foo<'a> { | ||||||
fn bar<'b,'c>(x: &'a u32, y: &'b u32, z: &'c u32) {} // ok! | ||||||
} | ||||||
|
||||||
impl<'a> Foo<'a> { // ok! | ||||||
fn baz() {} | ||||||
} | ||||||
``` |
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.