Skip to content
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

Suggest adding a generic lifetime parameter #64579

Open
varkor opened this issue Sep 18, 2019 · 1 comment
Open

Suggest adding a generic lifetime parameter #64579

varkor opened this issue Sep 18, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Sep 18, 2019

fn foo(
    mut x: &(),
    y: &(),
) {
    x = y;
}

gives the error:

error[E0623]: lifetime mismatch
 --> src/lib.rs:5:9
  |
2 |     mut x: &(),
  |            ---
3 |     y: &(),
  |        --- these two types are declared with different lifetimes...
4 | ) {
5 |     x = y;
  |         ^ ...but data from `y` flows into `x` here

but does not suggest the solution: adding a new lifetime parameter 'a to foo and giving both variables the same lifetime.

@varkor varkor 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. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Sep 18, 2019
@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Sep 18, 2019
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 7, 2019
@BGR360
Copy link
Contributor

BGR360 commented Dec 29, 2021

Looks like the gods of time have granted your wish (in this case, @Nilstrieb ): #90179

Current output on nightly:

error[E0623]: lifetime mismatch
 --> src/lib.rs:5:9
  |
2 |     mut x: &(),
  |            ---
3 |     y: &(),
  |        --- these two types are declared with different lifetimes...
4 | ) {
5 |     x = y;
  |         ^ ...but data from `y` flows into `x` here
  |
  = note: each elided lifetime in input position becomes a distinct lifetime
help: consider introducing a named lifetime parameter
  |
1 ~ fn foo<'a>(
2 ~     mut x: &'a (),
3 ~     y: &'a (),
  |

Can we close this?

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants