-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Convert a hard-warning about named static lifetimes into a lint #98079
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
23cf5dd
Define the `named_static_lifetimes` lint
jeremydavis519 cc9f4c2
Replace the named static lifetime hard-warning with the new lint
jeremydavis519 47ed1a3
Update the UI tests for the `named_static_lifetimes` lint
jeremydavis519 897f4d5
Remove the direct dependency on `rustc_lint_defs`
jeremydavis519 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ use rustc_hir::def_id::{DefIdMap, LocalDefId}; | |
use rustc_hir::intravisit::{self, Visitor}; | ||
use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node}; | ||
use rustc_hir::{GenericParamKind, HirIdMap}; | ||
use rustc_lint_defs::builtin::NAMED_STATIC_LIFETIMES; | ||
use rustc_middle::hir::map::Map; | ||
use rustc_middle::hir::nested_filter; | ||
use rustc_middle::middle::resolve_lifetime::*; | ||
|
@@ -1255,20 +1256,24 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { | |
continue; | ||
} | ||
this.insert_lifetime(lt, Region::Static); | ||
this.tcx | ||
.sess | ||
.struct_span_warn( | ||
lifetime.span, | ||
&format!( | ||
this.tcx.struct_span_lint_hir( | ||
NAMED_STATIC_LIFETIMES, | ||
lifetime.hir_id, | ||
lifetime.span, | ||
|lint| { | ||
let msg = &format!( | ||
"unnecessary lifetime parameter `{}`", | ||
lifetime.name.ident(), | ||
), | ||
) | ||
.help(&format!( | ||
"you can use the `'static` lifetime directly, in place of `{}`", | ||
lifetime.name.ident(), | ||
)) | ||
.emit(); | ||
); | ||
let help = &format!( | ||
"you can use the `'static` lifetime directly, in place of `{}`", | ||
lifetime.name.ident(), | ||
); | ||
lint.build(msg) | ||
.help(help) | ||
Comment on lines
+1268
to
+1273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily something to do on this PR, but we have enough context to turn the
|
||
.emit(); | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustc_resolve
typically uses lints throughrustc_session::lint
, so adding this shouldn't be necessary.