errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
f9216b7564
commit
d1fcf61117
151 changed files with 1721 additions and 1440 deletions
|
@ -1,5 +1,7 @@
|
|||
use crate::lints::{ArrayIntoIterDiag, ArrayIntoIterDiagSub};
|
||||
use crate::{LateContext, LateLintPass, LintContext};
|
||||
use crate::{
|
||||
lints::{ArrayIntoIterDiag, ArrayIntoIterDiagSub},
|
||||
LateContext, LateLintPass, LintContext,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
//! If you define a new `LateLintPass`, you will also need to add it to the
|
||||
//! `late_lint_methods!` invocation in `lib.rs`.
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::{
|
||||
errors::BuiltinEllpisisInclusiveRangePatterns,
|
||||
lints::{
|
||||
|
@ -50,7 +51,7 @@ use rustc_ast::{self as ast, *};
|
|||
use rustc_ast_pretty::pprust::{self, expr_to_string};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{fluent, Applicability, DecorateLint, MultiSpan};
|
||||
use rustc_errors::{Applicability, DecorateLint, MultiSpan};
|
||||
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
fluent, AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
|
||||
SubdiagnosticMessage,
|
||||
AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic, SubdiagnosticMessage,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_session::lint::Level;
|
||||
|
@ -116,7 +116,7 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {
|
|||
let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
|
||||
diag.code(rustc_errors::error_code!(E0602));
|
||||
if let Some(suggestion) = self.suggestion {
|
||||
diag.help(fluent::help);
|
||||
diag.help(fluent::lint_help);
|
||||
diag.set_arg("suggestion", suggestion);
|
||||
}
|
||||
diag.set_arg("lint_name", self.lint_name);
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
use crate::context::{CheckLintNameResult, LintStore};
|
||||
use crate::late::unerased_lint_store;
|
||||
use crate::lints::{
|
||||
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAtributeLint, RenamedOrRemovedLint,
|
||||
RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
||||
use crate::{
|
||||
context::{CheckLintNameResult, LintStore},
|
||||
fluent_generated as fluent,
|
||||
late::unerased_lint_store,
|
||||
lints::{
|
||||
DeprecatedLintName, IgnoredUnlessCrateSpecified, OverruledAtributeLint,
|
||||
RenamedOrRemovedLint, RenamedOrRemovedLintSuggestion, UnknownLint, UnknownLintSuggestion,
|
||||
},
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{fluent, DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::HirId;
|
||||
|
@ -983,7 +986,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
fluent::lint_unknown_gated_lint,
|
||||
|lint| {
|
||||
lint.set_arg("name", lint_id.lint.name_lower());
|
||||
lint.note(fluent::note);
|
||||
lint.note(fluent::lint_note);
|
||||
add_feature_diagnostics(lint, &self.sess.parse_sess, feature);
|
||||
lint
|
||||
},
|
||||
|
|
|
@ -80,8 +80,10 @@ mod unused;
|
|||
pub use array_into_iter::ARRAY_INTO_ITER;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_macros::fluent_messages;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::lint::builtin::{
|
||||
|
@ -122,6 +124,8 @@ pub use rustc_session::lint::Level::{self, *};
|
|||
pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId};
|
||||
pub use rustc_session::lint::{LintArray, LintPass};
|
||||
|
||||
fluent_messages! { "../locales/en-US.ftl" }
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
levels::provide(providers);
|
||||
expect::provide(providers);
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
#![allow(rustc::diagnostic_outside_of_impl)]
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
fluent, AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage,
|
||||
DiagnosticStyledString, SuggestionStyle,
|
||||
AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage, DiagnosticStyledString,
|
||||
SuggestionStyle,
|
||||
};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
||||
|
@ -23,7 +24,7 @@ use crate::{
|
|||
#[diag(lint_array_into_iter)]
|
||||
pub struct ArrayIntoIterDiag<'a> {
|
||||
pub target: &'a str,
|
||||
#[suggestion(use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
|
||||
#[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
|
||||
pub suggestion: Span,
|
||||
#[subdiagnostic]
|
||||
pub sub: Option<ArrayIntoIterDiagSub>,
|
||||
|
@ -31,12 +32,15 @@ pub struct ArrayIntoIterDiag<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum ArrayIntoIterDiagSub {
|
||||
#[suggestion(remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
|
||||
RemoveIntoIter {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[multipart_suggestion(use_explicit_into_iter_suggestion, applicability = "maybe-incorrect")]
|
||||
#[multipart_suggestion(
|
||||
lint_use_explicit_into_iter_suggestion,
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
UseExplicitIntoIter {
|
||||
#[suggestion_part(code = "IntoIterator::into_iter(")]
|
||||
start_span: Span,
|
||||
|
@ -163,13 +167,13 @@ pub struct BuiltinDeprecatedAttrLink<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum BuiltinDeprecatedAttrLinkSuggestion<'a> {
|
||||
#[suggestion(msg_suggestion, code = "", applicability = "machine-applicable")]
|
||||
#[suggestion(lint_msg_suggestion, code = "", applicability = "machine-applicable")]
|
||||
Msg {
|
||||
#[primary_span]
|
||||
suggestion: Span,
|
||||
msg: &'a str,
|
||||
},
|
||||
#[suggestion(default_suggestion, code = "", applicability = "machine-applicable")]
|
||||
#[suggestion(lint_default_suggestion, code = "", applicability = "machine-applicable")]
|
||||
Default {
|
||||
#[primary_span]
|
||||
suggestion: Span,
|
||||
|
@ -201,9 +205,9 @@ pub struct BuiltinUnusedDocComment<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum BuiltinUnusedDocCommentSub {
|
||||
#[help(plain_help)]
|
||||
#[help(lint_plain_help)]
|
||||
PlainHelp,
|
||||
#[help(block_help)]
|
||||
#[help(lint_block_help)]
|
||||
BlockHelp,
|
||||
}
|
||||
|
||||
|
@ -242,7 +246,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
|||
self,
|
||||
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
||||
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
||||
diag.span_label(self.label, fluent::label);
|
||||
diag.span_label(self.label, fluent::lint_label);
|
||||
rustc_session::parse::add_feature_diagnostics(
|
||||
diag,
|
||||
&self.parse_sess,
|
||||
|
@ -337,7 +341,7 @@ impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
|
|||
) -> rustc_errors::SubdiagnosticMessage,
|
||||
{
|
||||
diag.multipart_suggestion(
|
||||
fluent::suggestion,
|
||||
fluent::lint_suggestion,
|
||||
self.suggestions,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
@ -388,7 +392,7 @@ pub struct BuiltinExplicitOutlives {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion(suggestion)]
|
||||
#[multipart_suggestion(lint_suggestion)]
|
||||
pub struct BuiltinExplicitOutlivesSuggestion {
|
||||
#[suggestion_part(code = "")]
|
||||
pub spans: Vec<Span>,
|
||||
|
@ -407,11 +411,11 @@ pub struct BuiltinIncompleteFeatures {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(help)]
|
||||
#[help(lint_help)]
|
||||
pub struct BuiltinIncompleteFeaturesHelp;
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(note)]
|
||||
#[note(lint_note)]
|
||||
pub struct BuiltinIncompleteFeaturesNote {
|
||||
pub n: NonZeroU32,
|
||||
}
|
||||
|
@ -482,9 +486,9 @@ pub enum BuiltinClashingExtern<'a> {
|
|||
SameName {
|
||||
this: Symbol,
|
||||
orig: Symbol,
|
||||
#[label(previous_decl_label)]
|
||||
#[label(lint_previous_decl_label)]
|
||||
previous_decl_label: Span,
|
||||
#[label(mismatch_label)]
|
||||
#[label(lint_mismatch_label)]
|
||||
mismatch_label: Span,
|
||||
#[subdiagnostic]
|
||||
sub: BuiltinClashingExternSub<'a>,
|
||||
|
@ -493,9 +497,9 @@ pub enum BuiltinClashingExtern<'a> {
|
|||
DiffName {
|
||||
this: Symbol,
|
||||
orig: Symbol,
|
||||
#[label(previous_decl_label)]
|
||||
#[label(lint_previous_decl_label)]
|
||||
previous_decl_label: Span,
|
||||
#[label(mismatch_label)]
|
||||
#[label(lint_mismatch_label)]
|
||||
mismatch_label: Span,
|
||||
#[subdiagnostic]
|
||||
sub: BuiltinClashingExternSub<'a>,
|
||||
|
@ -571,7 +575,7 @@ pub struct SupertraitAsDerefTarget<'a> {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[label(label)]
|
||||
#[label(lint_label)]
|
||||
pub struct SupertraitAsDerefTargetLabel {
|
||||
#[primary_span]
|
||||
pub label: Span,
|
||||
|
@ -604,7 +608,7 @@ pub struct Expectation {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(rationale)]
|
||||
#[note(lint_rationale)]
|
||||
pub struct ExpectationNote {
|
||||
pub rationale: Symbol,
|
||||
}
|
||||
|
@ -625,13 +629,13 @@ pub struct ForLoopsOverFalliblesDiag<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum ForLoopsOverFalliblesLoopSub<'a> {
|
||||
#[suggestion(remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
|
||||
RemoveNext {
|
||||
#[primary_span]
|
||||
suggestion: Span,
|
||||
recv_snip: String,
|
||||
},
|
||||
#[multipart_suggestion(use_while_let, applicability = "maybe-incorrect")]
|
||||
#[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")]
|
||||
UseWhileLet {
|
||||
#[suggestion_part(code = "while let {var}(")]
|
||||
start_span: Span,
|
||||
|
@ -642,14 +646,14 @@ pub enum ForLoopsOverFalliblesLoopSub<'a> {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(use_question_mark, code = "?", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")]
|
||||
pub struct ForLoopsOverFalliblesQuestionMark {
|
||||
#[primary_span]
|
||||
pub suggestion: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
|
||||
#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
|
||||
pub struct ForLoopsOverFalliblesSuggestion<'a> {
|
||||
pub var: &'a str,
|
||||
#[suggestion_part(code = "if let {var}(")]
|
||||
|
@ -708,13 +712,13 @@ impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
|
|||
match self {
|
||||
HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
|
||||
diag.multipart_suggestion_with_style(
|
||||
fluent::suggestion_remove,
|
||||
fluent::lint_suggestion_remove,
|
||||
spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
|
||||
Applicability::MachineApplicable,
|
||||
SuggestionStyle::HideCodeAlways,
|
||||
);
|
||||
diag.multipart_suggestion(
|
||||
fluent::suggestion_escape,
|
||||
fluent::lint_suggestion_escape,
|
||||
spans
|
||||
.into_iter()
|
||||
.map(|(c, span)| {
|
||||
|
@ -737,8 +741,8 @@ impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
|
|||
.collect::<Vec<String>>()
|
||||
.join(", "),
|
||||
);
|
||||
diag.note(fluent::suggestion_remove);
|
||||
diag.note(fluent::no_suggestion_note_escape);
|
||||
diag.note(fluent::lint_suggestion_remove);
|
||||
diag.note(fluent::lint_no_suggestion_note_escape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -883,7 +887,7 @@ pub struct RenamedOrRemovedLint<'a> {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(suggestion, code = "{replace}", applicability = "machine-applicable")]
|
||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
|
||||
pub struct RenamedOrRemovedLintSuggestion<'a> {
|
||||
#[primary_span]
|
||||
pub suggestion: Span,
|
||||
|
@ -899,7 +903,7 @@ pub struct UnknownLint {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
pub struct UnknownLintSuggestion {
|
||||
#[primary_span]
|
||||
pub suggestion: Span,
|
||||
|
@ -919,9 +923,9 @@ pub struct IgnoredUnlessCrateSpecified<'a> {
|
|||
#[note]
|
||||
#[help]
|
||||
pub struct CStringPtr {
|
||||
#[label(as_ptr_label)]
|
||||
#[label(lint_as_ptr_label)]
|
||||
pub as_ptr: Span,
|
||||
#[label(unwrap_label)]
|
||||
#[label(lint_unwrap_label)]
|
||||
pub unwrap: Span,
|
||||
}
|
||||
|
||||
|
@ -952,7 +956,7 @@ pub struct ConfusableIdentifierPair {
|
|||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_mixed_script_confusables)]
|
||||
#[note(includes_note)]
|
||||
#[note(lint_includes_note)]
|
||||
#[note]
|
||||
pub struct MixedScriptConfusables {
|
||||
pub set: String,
|
||||
|
@ -972,17 +976,17 @@ impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
|
|||
diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
|
||||
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
||||
diag.set_arg("count", self.count);
|
||||
diag.note(fluent::note);
|
||||
diag.note(fluent::lint_note);
|
||||
if let Some(span) = self.suggestion {
|
||||
diag.span_suggestion(
|
||||
span.shrink_to_hi(),
|
||||
fluent::add_args_suggestion,
|
||||
fluent::lint_add_args_suggestion,
|
||||
", ...",
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
diag.span_suggestion(
|
||||
span.shrink_to_lo(),
|
||||
fluent::add_fmt_suggestion,
|
||||
fluent::lint_add_fmt_suggestion,
|
||||
"\"{}\", ",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
@ -1016,12 +1020,12 @@ pub struct NonCamelCaseType<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum NonCamelCaseTypeSub {
|
||||
#[label(label)]
|
||||
#[label(lint_label)]
|
||||
Label {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
Suggestion {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -1057,15 +1061,15 @@ impl AddToDiagnostic for NonSnakeCaseDiagSub {
|
|||
{
|
||||
match self {
|
||||
NonSnakeCaseDiagSub::Label { span } => {
|
||||
diag.span_label(span, fluent::label);
|
||||
diag.span_label(span, fluent::lint_label);
|
||||
}
|
||||
NonSnakeCaseDiagSub::Help => {
|
||||
diag.help(fluent::help);
|
||||
diag.help(fluent::lint_help);
|
||||
}
|
||||
NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
|
||||
diag.span_suggestion(
|
||||
span,
|
||||
fluent::convert_suggestion,
|
||||
fluent::lint_convert_suggestion,
|
||||
suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -1073,16 +1077,16 @@ impl AddToDiagnostic for NonSnakeCaseDiagSub {
|
|||
NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
|
||||
diag.span_suggestion(
|
||||
span,
|
||||
fluent::rename_or_convert_suggestion,
|
||||
fluent::lint_rename_or_convert_suggestion,
|
||||
suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
|
||||
diag.note(fluent::cannot_convert_note);
|
||||
diag.note(fluent::lint_cannot_convert_note);
|
||||
diag.span_suggestion(
|
||||
span,
|
||||
fluent::rename_suggestion,
|
||||
fluent::lint_rename_suggestion,
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -1102,12 +1106,12 @@ pub struct NonUpperCaseGlobal<'a> {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum NonUpperCaseGlobalSub {
|
||||
#[label(label)]
|
||||
#[label(lint_label)]
|
||||
Label {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
#[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
|
||||
Suggestion {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -1225,11 +1229,11 @@ impl AddToDiagnostic for OverflowingBinHexSign {
|
|||
{
|
||||
match self {
|
||||
OverflowingBinHexSign::Positive => {
|
||||
diag.note(fluent::positive_note);
|
||||
diag.note(fluent::lint_positive_note);
|
||||
}
|
||||
OverflowingBinHexSign::Negative => {
|
||||
diag.note(fluent::negative_note);
|
||||
diag.note(fluent::negative_becomes_note);
|
||||
diag.note(fluent::lint_negative_note);
|
||||
diag.note(fluent::lint_negative_becomes_note);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1238,7 +1242,7 @@ impl AddToDiagnostic for OverflowingBinHexSign {
|
|||
#[derive(Subdiagnostic)]
|
||||
pub enum OverflowingBinHexSub<'a> {
|
||||
#[suggestion(
|
||||
suggestion,
|
||||
lint_suggestion,
|
||||
code = "{sans_suffix}{suggestion_ty}",
|
||||
applicability = "machine-applicable"
|
||||
)]
|
||||
|
@ -1248,7 +1252,7 @@ pub enum OverflowingBinHexSub<'a> {
|
|||
suggestion_ty: &'a str,
|
||||
sans_suffix: &'a str,
|
||||
},
|
||||
#[help(help)]
|
||||
#[help(lint_help)]
|
||||
Help { suggestion_ty: &'a str },
|
||||
}
|
||||
|
||||
|
@ -1265,7 +1269,7 @@ pub struct OverflowingInt<'a> {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(help)]
|
||||
#[help(lint_help)]
|
||||
pub struct OverflowingIntHelp<'a> {
|
||||
pub suggestion_ty: &'a str,
|
||||
}
|
||||
|
@ -1317,13 +1321,13 @@ impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
|
|||
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
|
||||
diag.set_arg("ty", self.ty);
|
||||
diag.set_arg("desc", self.desc);
|
||||
diag.span_label(self.label, fluent::label);
|
||||
diag.span_label(self.label, fluent::lint_label);
|
||||
if let Some(help) = self.help {
|
||||
diag.help(help);
|
||||
}
|
||||
diag.note(self.note);
|
||||
if let Some(note) = self.span_note {
|
||||
diag.span_note(note, fluent::note);
|
||||
diag.span_note(note, fluent::lint_note);
|
||||
}
|
||||
diag
|
||||
}
|
||||
|
@ -1416,7 +1420,7 @@ pub struct UnusedDef<'a, 'b> {
|
|||
#[derive(Subdiagnostic)]
|
||||
pub enum UnusedDefSuggestion {
|
||||
#[suggestion(
|
||||
suggestion,
|
||||
lint_suggestion,
|
||||
style = "verbose",
|
||||
code = "let _ = ",
|
||||
applicability = "machine-applicable"
|
||||
|
@ -1460,13 +1464,13 @@ pub struct PathStatementDrop {
|
|||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum PathStatementDropSub {
|
||||
#[suggestion(suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
|
||||
#[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
|
||||
Suggestion {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
snippet: String,
|
||||
},
|
||||
#[help(help)]
|
||||
#[help(lint_help)]
|
||||
Help {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -1487,7 +1491,7 @@ pub struct UnusedDelim<'a> {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion(suggestion, applicability = "machine-applicable")]
|
||||
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
|
||||
pub struct UnusedDelimSuggestion {
|
||||
#[suggestion_part(code = "{start_replace}")]
|
||||
pub start_span: Span,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::lints::{NonFmtPanicBraces, NonFmtPanicUnused};
|
||||
use crate::{LateContext, LateLintPass, LintContext};
|
||||
use crate::{fluent_generated as fluent, LateContext, LateLintPass, LintContext};
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{fluent, Applicability};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
|
@ -122,18 +122,18 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
|||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
cx.struct_span_lint(NON_FMT_PANICS, arg_span, fluent::lint_non_fmt_panic, |lint| {
|
||||
lint.set_arg("name", symbol);
|
||||
lint.note(fluent::note);
|
||||
lint.note(fluent::more_info_note);
|
||||
lint.note(fluent::lint_note);
|
||||
lint.note(fluent::lint_more_info_note);
|
||||
if !is_arg_inside_call(arg_span, span) {
|
||||
// No clue where this argument is coming from.
|
||||
return lint;
|
||||
}
|
||||
if arg_macro.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) {
|
||||
// A case of `panic!(format!(..))`.
|
||||
lint.note(fluent::supports_fmt_note);
|
||||
lint.note(fluent::lint_supports_fmt_note);
|
||||
if let Some((open, close, _)) = find_delimiters(cx, arg_span) {
|
||||
lint.multipart_suggestion(
|
||||
fluent::supports_fmt_suggestion,
|
||||
fluent::lint_supports_fmt_suggestion,
|
||||
vec![
|
||||
(arg_span.until(open.shrink_to_hi()), "".into()),
|
||||
(close.until(arg_span.shrink_to_hi()), "".into()),
|
||||
|
@ -179,7 +179,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
|||
if suggest_display {
|
||||
lint.span_suggestion_verbose(
|
||||
arg_span.shrink_to_lo(),
|
||||
fluent::display_suggestion,
|
||||
fluent::lint_display_suggestion,
|
||||
"\"{}\", ",
|
||||
fmt_applicability,
|
||||
);
|
||||
|
@ -187,7 +187,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
|||
lint.set_arg("ty", ty);
|
||||
lint.span_suggestion_verbose(
|
||||
arg_span.shrink_to_lo(),
|
||||
fluent::debug_suggestion,
|
||||
fluent::lint_debug_suggestion,
|
||||
"\"{:?}\", ",
|
||||
fmt_applicability,
|
||||
);
|
||||
|
@ -197,7 +197,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
|||
if let Some((open, close, del)) = find_delimiters(cx, span) {
|
||||
lint.set_arg("already_suggested", suggest_display || suggest_debug);
|
||||
lint.multipart_suggestion(
|
||||
fluent::panic_suggestion,
|
||||
fluent::lint_panic_suggestion,
|
||||
if del == '(' {
|
||||
vec![(span.until(open), "std::panic::panic_any".into())]
|
||||
} else {
|
||||
|
|
|
@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
|||
struct OpaqueHiddenInferredBoundLint<'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
proj_ty: Ty<'tcx>,
|
||||
#[label(specifically)]
|
||||
#[label(lint_specifically)]
|
||||
assoc_pred_span: Span,
|
||||
#[subdiagnostic]
|
||||
add_bound: Option<AddBound<'tcx>>,
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
use crate::lints::{
|
||||
AtomicOrderingFence, AtomicOrderingLoad, AtomicOrderingStore, ImproperCTypes,
|
||||
InvalidAtomicOrderingDiag, OnlyCastu8ToChar, OverflowingBinHex, OverflowingBinHexSign,
|
||||
OverflowingBinHexSub, OverflowingInt, OverflowingIntHelp, OverflowingLiteral, OverflowingUInt,
|
||||
RangeEndpointOutOfRange, UnusedComparisons, VariantSizeDifferencesDiag,
|
||||
use crate::{
|
||||
fluent_generated as fluent,
|
||||
lints::{
|
||||
AtomicOrderingFence, AtomicOrderingLoad, AtomicOrderingStore, ImproperCTypes,
|
||||
InvalidAtomicOrderingDiag, OnlyCastu8ToChar, OverflowingBinHex, OverflowingBinHexSign,
|
||||
OverflowingBinHexSub, OverflowingInt, OverflowingIntHelp, OverflowingLiteral,
|
||||
OverflowingUInt, RangeEndpointOutOfRange, UnusedComparisons, VariantSizeDifferencesDiag,
|
||||
},
|
||||
};
|
||||
use crate::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_ast as ast;
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{fluent, DiagnosticMessage};
|
||||
use rustc_errors::DiagnosticMessage;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::{is_range_literal, Expr, ExprKind, Node};
|
||||
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue