Skip to content

improve case with method in trait, one named one anonymous lifetime parameter #42702

Closed
@gaurikholkar-zz

Description

@gaurikholkar-zz

In #42669 , we are currently not improving the error message for the methods in traits. For this example,

trait Foo {
  fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
              //    -  consider changing the type of `x` to `&'a i32`
        if x > y { x } else { y }
             //      ^ - lifetime `'a` required 
  }
} 
note: ...changing the signature in the trait may require changing the corresponding impls of the trait

cc @nikomatsakis

Activity

nikomatsakis

nikomatsakis commented on Jun 16, 2017

@nikomatsakis
Contributor

Actually, I think we do cover this case in #42669 -- this would be a NodeTraitItem.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-diagnosticsArea: Messages for errors, warnings, and lints
on Jun 16, 2017
nikomatsakis

nikomatsakis commented on Jun 16, 2017

@nikomatsakis
Contributor

However, I think what I was concerned about here was that we might want to give more information (i.e., the note shown, although it seems a bit wordy). Not sure if that's worth it.

steveklabnik

steveklabnik commented on Jun 28, 2020

@steveklabnik
Member

Triage: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=af0e0b47620c290c33c3aacadc83e4db

error[E0621]: explicit lifetime required in the type of `x`
 --> src/lib.rs:4:13
  |
2 |     fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
  |                   ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
3 |         if x > y {
4 |             x
  |             ^ lifetime `'a` required

error: aborting due to previous error

I am not sure if this is good enough to close the bug or not.

nikomatsakis

nikomatsakis commented on Jun 29, 2020

@nikomatsakis
Contributor

I think we can close it. Thanks.

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 lintsC-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

        @steveklabnik@nikomatsakis@Mark-Simulacrum@gaurikholkar-zz

        Issue actions

          improve case with method in trait, one named one anonymous lifetime parameter · Issue #42702 · rust-lang/rust