-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Cleanup unused diagnostic emission methods - part 2 #153509
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
Open
GuillaumeGomez
wants to merge
7
commits into
rust-lang:main
Choose a base branch
from
GuillaumeGomez:migrate-diag2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+602
−340
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0dbe94
Add new `rustc_errors::DiagDecorator` type
GuillaumeGomez c1c85fa
Remove `TyCtxt::node_span_lint` usage from `rustc_lint`
GuillaumeGomez c244fb5
Remove `TyCtxt::node_span_lint` usage from `rustc_middle`
GuillaumeGomez 4a9964b
Remove `TyCtxt::node_span_lint` usage from `rustc_mir_build`
GuillaumeGomez 1c0cc8e
Remove `TyCtxt::node_span_lint` usage from `rustc_mir_transform`
GuillaumeGomez a11cf60
Remove `TyCtxt::node_span_lint` usage from `rustc_trait_selection`
GuillaumeGomez c7d83eb
Remove `TyCtxt::node_span_lint` usage from `librustdoc`
GuillaumeGomez 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ use rustc_hir::lang_items::LangItem; | |
| use rustc_hir::limit::Limit; | ||
| use rustc_hir::{self as hir, CRATE_HIR_ID, HirId, Node, TraitCandidate, find_attr}; | ||
| use rustc_index::IndexVec; | ||
| use rustc_macros::Diagnostic; | ||
| use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; | ||
| use rustc_session::Session; | ||
| use rustc_session::config::CrateType; | ||
|
|
@@ -1690,6 +1691,12 @@ impl<'tcx> TyCtxt<'tcx> { | |
| } | ||
|
|
||
| pub fn report_unused_features(self) { | ||
| #[derive(Diagnostic)] | ||
| #[diag("feature `{$feature}` is declared but not used")] | ||
| struct UnusedFeature { | ||
| feature: Symbol, | ||
| } | ||
|
|
||
| // Collect first to avoid holding the lock while linting. | ||
| let used_features = self.sess.used_features.lock(); | ||
| let unused_features = self | ||
|
|
@@ -1708,13 +1715,11 @@ impl<'tcx> TyCtxt<'tcx> { | |
| .collect::<Vec<_>>(); | ||
|
|
||
| for (feature, span) in unused_features { | ||
| self.node_span_lint( | ||
| self.emit_node_span_lint( | ||
| rustc_session::lint::builtin::UNUSED_FEATURES, | ||
| CRATE_HIR_ID, | ||
| span, | ||
| |lint| { | ||
| lint.primary_message(format!("feature `{}` is declared but not used", feature)); | ||
| }, | ||
| UnusedFeature { feature }, | ||
|
Contributor
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. I don't really like how positive the diff of this PR is, the explicit
|
||
| ); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
I thought we said we'd not convert more things to the struct error style?
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.
Sorry I don't remember that. Where did we discuss it? Also, we are removing the
node_span_lintmethod to remove the duplicatedlint_levelfunction, so there isn't much of a choice, unless we simply wrap the closure in a type.Uh oh!
There was an error while loading. Please reload this page.
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.
Afaik the consensus is that we can use whatever style is prettier. In this case, I think the struct style is quite pretty. I don't like the explicit
impl Diagnosticones in this PR tho, and would like to explore the closure approach for those