Skip to content

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

@gaurikholkar-zz

Description

@gaurikholkar-zz

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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lifetimesArea: Lifetimes / regions
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 26, 2017
gaurikholkar-zz

gaurikholkar-zz commented on Aug 13, 2017

@gaurikholkar-zz
Author

working on this.

gaurikholkar-zz

gaurikholkar-zz commented on Aug 13, 2017

@gaurikholkar-zz
Author
gaurikholkar-zz

gaurikholkar-zz commented on Aug 13, 2017

@gaurikholkar-zz
Author
added
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Oct 15, 2019
estebank

estebank commented on Jun 29, 2023

@estebank
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @estebank@Mark-Simulacrum@gaurikholkar-zz

        Issue actions

          Improve error message for one named, one anonymous lifetime parameters · Issue #43433 · rust-lang/rust