-
Notifications
You must be signed in to change notification settings - Fork 13k
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
"use of undeclared lifetime name 'static
" is misleading
#40661
Comments
I believe we'll want to check for |
The right move here would be to reject Since it would be unnecessary, would be more appropriate to reject the code telling the user to just use |
I'd like to work on this, if it is still open (and/or available for mentoring)! |
@adamransom |
I think it would appropriate to reject the code and tell the user not to use a lifetime parameter at all -- there's never a need for a parameter that must always be That being said, we also might want to allow it for consistency, perhaps with a warning (lint). |
Oh, well in that case it makes even more sense to just warn the user that the parameter is unnecessary; an error might be overkill, but a warning would seem reasonable. |
@jseyfried Great, I'll work on adding a warning as we discussed in IRC. |
Both seems reasonable. |
Add warning for use of lifetime parameter with 'static bound Previously a `'static` lifetime bound would result in an `undeclared lifetime` error when compiling, even though it could be considered valid. However, it is unnecessary to use it as a lifetime bound so we present the user with a warning instead and suggest using the `'static` lifetime directly, in place of the lifetime parameter. We can change this to an error (or warning with lint) if that's decided to be more appropriate. Example output: ``` warning: unnecessary lifetime parameter `'a` --> ../static-lifetime-bound.rs:3:10 | 3 | fn f<'a: 'static>(val: &'a i32) { | ^^^^^^^^^^^ | = help: you can use the `'static` lifetime directly, in place `'a` ``` Fixes rust-lang#40661 r? @jseyfried
Add warning for use of lifetime parameter with 'static bound Previously a `'static` lifetime bound would result in an `undeclared lifetime` error when compiling, even though it could be considered valid. However, it is unnecessary to use it as a lifetime bound so we present the user with a warning instead and suggest using the `'static` lifetime directly, in place of the lifetime parameter. We can change this to an error (or warning with lint) if that's decided to be more appropriate. Example output: ``` warning: unnecessary lifetime parameter `'a` --> ../static-lifetime-bound.rs:3:10 | 3 | fn f<'a: 'static>(val: &'a i32) { | ^^^^^^^^^^^ | = help: you can use the `'static` lifetime directly, in place `'a` ``` Fixes rust-lang#40661 r? @jseyfried
Code: https://is.gd/6L8tEl
Output:
Expectation:
<'a: 'static>
is unnecessary (you can just use'static
in place of'a
), but maybe we should accept it? At any rate, the error message is misleading -'static
is the one globally declared lifetime. If we want to reject this code, the error message should not imply'static
is undefined, but rather that you just don't need the'a
lifetime.The text was updated successfully, but these errors were encountered: