-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 named lifetime on trait functions like we do for free functions #73931
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Changed issue title to be clearer:
|
Hey @estebank, @schuermannator and I both looked into this, but found that the error reporting for traits and free functions live in different modules. Moreover, |
@rustbot release-assignment |
Hi, |
I think the first approach might be to try and move the relevant methods to a place that can be called from both modules. If that is not possible maybe creating a PR that duplicates the code could be useful to see the extent of the needs/impact. Feel free to take this for a spin and ping me on zulip or here for help! |
@rustbot claim |
Sounds good. I will try the first approach. If it's not possible, I may be able to duplicate the code and have a PR but it depends on my bandwidth. I'll keep in touch. |
@estebank I found some inconsistencies with the hints being given in different_lifetimes.rs so I made a small change #94464. The description of the issue is in #94462. I think the changes in that PR could provide a useful hint for the case in this issue, although the hint is not exactly as you had proposed here. There are some challenges (at least for me because I am a beginner) to getting the hint requested in this issue. I'd be happy to leave some of my notes if you want. I think the change in #94464 is a good compromise and could close this issue. Let me know what you think. Given: trait T {
fn foo(&self, x: &i32, y: &i32) -> Option<&i32> {
Some(y)
}
} Output:
|
The following
fn foo
provides a structured suggestion to add a new named lifetime:But similar code in a trait, doesn't:
The method
add_missing_lifetime_specifiers_label
is the one responsible for the former suggestion and can probably be easily reused where the method lifetime issue is emitted.Thanks to https://users.rust-lang.org/t/this-parameter-and-the-return-type-are-declared-with-different-lifetimes/45200 for making me notice this discrepancy.
The text was updated successfully, but these errors were encountered: