Skip to content

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

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

Closed
gaurikholkar-zz opened this issue Jun 16, 2017 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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 Jun 16, 2017

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

@nikomatsakis
Copy link
Contributor

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

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints labels Jun 16, 2017
@nikomatsakis
Copy link
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.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@steveklabnik
Copy link
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
Copy link
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
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

4 participants