-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Migrate rustc_lint
errors to SessionDiagnostic
#100776
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
Merged
bors
merged 10 commits into
rust-lang:master
from
Rejyr:diagnostic-migration-rustc-lint
Aug 27, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d197c1e
migrate: `UnknownTool` error to `SessionDiagnostic`
Rejyr 874a79f
migrate: `bad_attr` to `SessionDiagnostic`
Rejyr 6f83ec8
change: diagnostic `String` field to `Symbol`
Rejyr 32e445a
hotfix: add missing import
Rejyr 7a6ae23
migrate: `OverruledAttribute`
Rejyr 5d302d1
migrate: `BuiltinEllipsisInclusiveRangePatterns`
Rejyr dbe8380
rename: `UnknownTool` to `UnknownToolInScopedLint`
Rejyr 1974186
migrate: `rustc_lint::context`
Rejyr 257cf03
refactor: migrate to kind-less `SessionDiagnostic` derives
Rejyr 1693993
cleanup: commented lints
Rejyr 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed}; | ||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; | ||
use rustc_session::{lint::Level, parse::ParseSess, SessionDiagnostic}; | ||
use rustc_span::{Span, Symbol}; | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::overruled_attribute, code = "E0453")] | ||
pub struct OverruledAttribute { | ||
#[primary_span] | ||
pub span: Span, | ||
#[label] | ||
pub overruled: Span, | ||
pub lint_level: String, | ||
pub lint_source: Symbol, | ||
#[subdiagnostic] | ||
pub sub: OverruledAttributeSub, | ||
} | ||
// | ||
pub enum OverruledAttributeSub { | ||
DefaultSource { id: String }, | ||
NodeSource { span: Span, reason: Option<Symbol> }, | ||
CommandLineSource, | ||
} | ||
|
||
impl AddSubdiagnostic for OverruledAttributeSub { | ||
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { | ||
match self { | ||
OverruledAttributeSub::DefaultSource { id } => { | ||
diag.note(fluent::lint::default_source); | ||
diag.set_arg("id", id); | ||
} | ||
OverruledAttributeSub::NodeSource { span, reason } => { | ||
diag.span_label(span, fluent::lint::node_source); | ||
if let Some(rationale) = reason { | ||
diag.note(rationale.as_str()); | ||
} | ||
} | ||
OverruledAttributeSub::CommandLineSource => { | ||
diag.note(fluent::lint::command_line_source); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::malformed_attribute, code = "E0452")] | ||
pub struct MalformedAttribute { | ||
#[primary_span] | ||
pub span: Span, | ||
#[subdiagnostic] | ||
pub sub: MalformedAttributeSub, | ||
} | ||
|
||
#[derive(SessionSubdiagnostic)] | ||
pub enum MalformedAttributeSub { | ||
#[label(lint::bad_attribute_argument)] | ||
BadAttributeArgument(#[primary_span] Span), | ||
#[label(lint::reason_must_be_string_literal)] | ||
ReasonMustBeStringLiteral(#[primary_span] Span), | ||
#[label(lint::reason_must_come_last)] | ||
ReasonMustComeLast(#[primary_span] Span), | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")] | ||
pub struct UnknownToolInScopedLint { | ||
#[primary_span] | ||
pub span: Option<Span>, | ||
pub tool_name: Symbol, | ||
pub lint_name: String, | ||
#[help] | ||
pub is_nightly_build: Option<()>, | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")] | ||
pub struct BuiltinEllpisisInclusiveRangePatterns { | ||
#[primary_span] | ||
pub span: Span, | ||
#[suggestion_short(code = "{replace}", applicability = "machine-applicable")] | ||
pub suggestion: Span, | ||
pub replace: String, | ||
} | ||
|
||
pub struct RequestedLevel { | ||
pub level: Level, | ||
davidtwco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub lint_name: String, | ||
} | ||
|
||
impl AddSubdiagnostic for RequestedLevel { | ||
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { | ||
diag.note(fluent::lint::requested_level); | ||
diag.set_arg( | ||
"level", | ||
match self.level { | ||
Level::Allow => "-A", | ||
Level::Warn => "-W", | ||
Level::ForceWarn(_) => "--force-warn", | ||
Level::Deny => "-D", | ||
Level::Forbid => "-F", | ||
Level::Expect(_) => { | ||
unreachable!("lints with the level of `expect` should not run this code"); | ||
} | ||
}, | ||
); | ||
diag.set_arg("lint_name", self.lint_name); | ||
} | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::unsupported_group, code = "E0602")] | ||
pub struct UnsupportedGroup { | ||
pub lint_group: String, | ||
} | ||
|
||
pub struct CheckNameUnknown { | ||
pub lint_name: String, | ||
pub suggestion: Option<Symbol>, | ||
pub sub: RequestedLevel, | ||
} | ||
|
||
impl SessionDiagnostic<'_> for CheckNameUnknown { | ||
fn into_diagnostic( | ||
self, | ||
sess: &ParseSess, | ||
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { | ||
let mut diag = sess.struct_err(fluent::lint::check_name_unknown); | ||
diag.code(rustc_errors::error_code!(E0602)); | ||
if let Some(suggestion) = self.suggestion { | ||
diag.help(fluent::lint::help); | ||
diag.set_arg("suggestion", suggestion); | ||
} | ||
diag.set_arg("lint_name", self.lint_name); | ||
diag.subdiagnostic(self.sub); | ||
diag | ||
} | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::check_name_unknown_tool, code = "E0602")] | ||
pub struct CheckNameUnknownTool { | ||
pub tool_name: Symbol, | ||
#[subdiagnostic] | ||
pub sub: RequestedLevel, | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::check_name_warning)] | ||
pub struct CheckNameWarning { | ||
pub msg: String, | ||
#[subdiagnostic] | ||
pub sub: RequestedLevel, | ||
} | ||
|
||
#[derive(SessionDiagnostic)] | ||
#[diag(lint::check_name_deprecated)] | ||
pub struct CheckNameDeprecated { | ||
pub lint_name: String, | ||
pub new_name: String, | ||
#[subdiagnostic] | ||
pub sub: RequestedLevel, | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.