-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggest adding undeclared lifetime parameters to struct #46135
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
Comments
In the following code: rust/src/librustc/middle/resolve_lifetime.rs Lines 1096 to 1099 in 5a2465e
suggest adding the undeclared lifetime to the appropriate parent scope(s) ( Bonus points to perform fuzzy search of the undeclared lifetime against all the parent binders to provide typo suggestion. |
I can work on this. :) |
Thinking about using lifetime parameters that haven't been initialized generically (as opposed to purely in the context of struct definitions), the two simplest cases are
A slightly more complex case is:
One could create more complicated cases by arbitrarily nesting Another minor issue is that (ideally) we should "unify" errors in the sense that
will give two errors
but it should give only one suggestion, which is replace |
You have adequately expressed the nuance when encountering nested scopes. For the case where you have nested struct X;
impl X {
fn bar(bar_arg: &'a usize) {
fn foo(foo_arg: &'a usize) {
struct Y {
y: &'a usize,
}
}
}
}
For the code example you provided, what I would do is to still emit the first error, recommend the suggestion to add the undeclared lifetime to the impl but accept it at the parser level as a valid lifetime binding. This way the second error won't be emitted (unless the
|
Do you mean
Are lifetimes parameters only allowed to be used in the children and not in further descendants? That makes things much simpler.
Got it. Just to make sure that I'm understanding correctly, the way to do it would be to call |
I believe lifetimes only get passed from
I believe that is the case. |
Triage: this error is the same today. |
I believe #68267 partially addresses this. Edit: confirmed that that PR addresses this case. |
The following code:
Generates this error:
It'd be nice to provide a suggestion to add a lifetime parameter to the struct definition.
Originally suggested here.
The text was updated successfully, but these errors were encountered: