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

Improve error message for one named, one anonymous lifetime parameters #43433

Open
gaurikholkar-zz opened this issue Jul 23, 2017 · 4 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gaurikholkar-zz
Copy link

gaurikholkar-zz commented Jul 23, 2017

For the following example

fn foo<'a>(x: &'a i32, y: Vec<&i32>) {
                       - consider changing the type of `y` to `std::vec::Vec<&'a i32>`
    y.push(x);
           ^ this reference must have lifetime 'a
}

can be refined to


fn foo<'a>(x: &'a i32, y: Vec<&i32>) {
                              ---- consider changing this type to `&'a i32`
    y.push(x);
           ^ this reference must have lifetime 'a
}

Underline &i32 instead of the whole type.

cc @nikomatsakis

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jul 26, 2017
@gaurikholkar-zz
Copy link
Author

working on this.

@gaurikholkar-zz
Copy link
Author

#43851

@gaurikholkar-zz
Copy link
Author

#43700

@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 15, 2019
@estebank
Copy link
Contributor

Current output:

error[[E0621]](https://doc.rust-lang.org/nightly/error_codes/E0621.html): explicit lifetime required in the type of `y`
 --> src/lib.rs:2:5
  |
1 | fn foo<'a>(x: &'a i32, mut y: Vec<&i32>) {
  |                               --------- help: add explicit lifetime `'a` to the type of `y`: `Vec<&'a i32>`
2 |     y.push(x);
  |     ^^^^^^^^^ lifetime `'a` required

@estebank estebank removed the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Jun 29, 2023
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-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

3 participants