-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add beginner friendly lifetime elision hint to E0623 #90170
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
arifd
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Oct 22, 2021
@rustbot claim |
We could maybe even add a suggestion for adding the explicit generic lifetime |
Noratrieb
added a commit
to Noratrieb/rust
that referenced
this issue
Oct 22, 2021
Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't Issue rust-lang#90170
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Oct 26, 2021
…-hint, r=estebank Add beginner friendly lifetime elision hint to E0623 Address rust-lang#90170 Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't. Example: ``` error[E0623]: lifetime mismatch --> $DIR/issue-90170-elision-mismatch.rs:2:35 | LL | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) { | --------- --------- these two types are declared with different lifetimes... LL | core::mem::swap(&mut slice_a, &mut slice_b); | ^^^^^^^^^^^^ ...but data from `slice_b` flows into `slice_a` here | = note: Each elided lifetime in input position becomes a distinct lifetime. help: Explicitly declare a lifetime and assign it to both | LL | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) { | ++++ ++ ++ ``` for ```rust fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) { core::mem::swap(&mut slice_a, &mut slice_b); } ```
Noratrieb
added a commit
to Noratrieb/rust
that referenced
this issue
Nov 3, 2021
Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't Issue rust-lang#90170 This also changes the tests introduced by the previous commits because of another rustc issue (rust-lang#90258)
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 4, 2021
…int, r=estebank Add beginner friendly lifetime elision hint to E0623 Address rust-lang#90170 Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't. Example: ``` error[E0623]: lifetime mismatch --> $DIR/issue-90170-elision-mismatch.rs:2:35 | LL | fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) { | --------- --------- these two types are declared with different lifetimes... LL | core::mem::swap(&mut slice_a, &mut slice_b); | ^^^^^^^^^^^^ ...but data from `slice_b` flows into `slice_a` here | = note: each elided lifetime in input position becomes a distinct lifetime help: explicitly declare a lifetime and assign it to both | LL | fn foo<'a>(slice_a: &'a mut [u8], slice_b: &'a mut [u8]) { | ++++ ++ ++ ``` for ```rust fn foo(slice_a: &mut [u8], slice_b: &mut [u8]) { core::mem::swap(&mut slice_a, &mut slice_b); } ```
I've implemented it and it has been merged, I hope you like it! (this can be closed) |
Great stuff. Congratulations and what an impressively fast turnaround! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4e10570825edd99bc5f0f03fe82fa34f
The current output is:
Ideally the output should look (something) like:
Beginners likely aren't aware of lifetime elision rules, they may be thinking "but there are NO lifetimes here"...
The text was updated successfully, but these errors were encountered: