-use rustc_errors::{fluent, AddSubdiagnostic, Applicability, DecorateLint, EmissionGuarantee};
+use rustc_errors::{fluent, AddToDiagnostic, Applicability, DecorateLint, EmissionGuarantee};
use rustc_hir::def_id::DefId;
-use rustc_macros::{LintDiagnostic, SessionSubdiagnostic};
+use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
-use rustc_span::{Span, Symbol};
+use rustc_span::{symbol::Ident, Span, Symbol};
use crate::LateContext;
+#[derive(LintDiagnostic)]
+#[diag(lint_array_into_iter)]
+pub struct ArrayIntoIterDiag<'a> {
+ pub target: &'a str,
+ #[suggestion(use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
+ pub suggestion: Span,
+ #[subdiagnostic]
+ pub sub: Option<ArrayIntoIterDiagSub>,
+}
+
+#[derive(Subdiagnostic)]
+pub enum ArrayIntoIterDiagSub {
+ #[suggestion(remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
+ RemoveIntoIter {
+ #[primary_span]
+ span: Span,
+ },
+ #[multipart_suggestion(use_explicit_into_iter_suggestion, applicability = "maybe-incorrect")]
+ UseExplicitIntoIter {
+ #[suggestion_part(code = "IntoIterator::into_iter(")]
+ start_span: Span,
+ #[suggestion_part(code = ")")]
+ end_span: Span,
+ },
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_enum_intrinsics_mem_discriminant)]
+pub struct EnumIntrinsicsMemDiscriminate<'a> {
+ pub ty_param: Ty<'a>,
+ #[note]
+ pub note: Span,
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_enum_intrinsics_mem_variant)]
+#[note]
+pub struct EnumIntrinsicsMemVariant<'a> {
+ pub ty_param: Ty<'a>,
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_cstring_ptr)]
+#[note]
+#[help]
+pub struct CStringPtr {
+ #[label(as_ptr_label)]
+ pub as_ptr: Span,
+ #[label(unwrap_label)]
+ pub unwrap: Span,
+}
+#[derive(LintDiagnostic)]
+#[diag(lint_identifier_non_ascii_char)]
+pub struct IdentifierNonAsciiChar;
+
+#[derive(LintDiagnostic)]
+#[diag(lint_identifier_uncommon_codepoints)]
+pub struct IdentifierUncommonCodepoints;
+
+#[derive(LintDiagnostic)]
+#[diag(lint_confusable_identifier_pair)]
+pub struct ConfusableIdentifierPair {
+ pub existing_sym: Symbol,
+ pub sym: Symbol,
+ #[label]
+ pub label: Span,
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_mixed_script_confusables)]
+#[note(includes_note)]
+#[note]
+pub struct MixedScriptConfusables {
+ pub set: String,
+ pub includes: String,
+}
+
+pub struct NonFmtPanicUnused {
+ pub count: usize,
+ pub suggestion: Option<Span>,
+}
+
+impl<G: EmissionGuarantee> DecorateLint<'_, G> for NonFmtPanicUnused {
+ fn decorate_lint(self, diag: rustc_errors::LintDiagnosticBuilder<'_, G>) {
+ let mut diag = diag.build(fluent::lint_non_fmt_panic_unused);
+ diag.set_arg("count", self.count);
+ diag.note(fluent::note);
+ if let Some(span) = self.suggestion {
+ diag.span_suggestion(
+ span.shrink_to_hi(),
+ fluent::add_args_suggestion,
+ ", ...",
+ Applicability::HasPlaceholders,
+ );
+ diag.span_suggestion(
+ span.shrink_to_lo(),
+ fluent::add_fmt_suggestion,
+ "\"{}\", ",
+ Applicability::MachineApplicable,
+ );
+ }
+ diag.emit();
+ }
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_non_fmt_panic_braces)]
+#[note]
+pub struct NonFmtPanicBraces {
+ pub count: usize,
+ #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
+ pub suggestion: Option<Span>,
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_non_camel_case_type)]
+pub struct NonCamelCaseType<'a> {
+ pub sort: &'a str,
+ pub name: &'a str,
+ #[subdiagnostic]
+ pub sub: NonCamelCaseTypeSub,
+}
+
+#[derive(Subdiagnostic)]
+pub enum NonCamelCaseTypeSub {
+ #[label(label)]
+ Label {
+ #[primary_span]
+ span: Span,
+ },
+ #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
+ Suggestion {
+ #[primary_span]
+ span: Span,
+ replace: String,
+ },
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_non_snake_case)]
+pub struct NonSnakeCaseDiag<'a> {
+ pub sort: &'a str,
+ pub name: &'a str,
+ pub sc: String,
+ #[subdiagnostic]
+ pub sub: NonSnakeCaseDiagSub,
+}
+
+pub enum NonSnakeCaseDiagSub {
+ Label { span: Span },
+ Help,
+ RenameOrConvertSuggestion { span: Span, suggestion: Ident },
+ ConvertSuggestion { span: Span, suggestion: String },
+ SuggestionAndNote { span: Span },
+}
+
+impl AddToDiagnostic for NonSnakeCaseDiagSub {
+ fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
+ where
+ F: Fn(
+ &mut rustc_errors::Diagnostic,
+ rustc_errors::SubdiagnosticMessage,
+ ) -> rustc_errors::SubdiagnosticMessage,
+ {
+ match self {
+ NonSnakeCaseDiagSub::Label { span } => {
+ diag.span_label(span, fluent::label);
+ }
+ NonSnakeCaseDiagSub::Help => {
+ diag.help(fluent::help);
+ }
+ NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
+ diag.span_suggestion(
+ span,
+ fluent::convert_suggestion,
+ suggestion,
+ Applicability::MaybeIncorrect,
+ );
+ }
+ NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
+ diag.span_suggestion(
+ span,
+ fluent::rename_or_convert_suggestion,
+ suggestion,
+ Applicability::MaybeIncorrect,
+ );
+ }
+ NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
+ diag.note(fluent::cannot_convert_note);
+ diag.span_suggestion(
+ span,
+ fluent::rename_suggestion,
+ "",
+ Applicability::MaybeIncorrect,
+ );
+ }
+ };
+ }
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_non_upper_case_global)]
+pub struct NonUpperCaseGlobal<'a> {
+ pub sort: &'a str,
+ pub name: &'a str,
+ #[subdiagnostic]
+ pub sub: NonUpperCaseGlobalSub,
+}
+
+#[derive(Subdiagnostic)]
+pub enum NonUpperCaseGlobalSub {
+ #[label(label)]
+ Label {
+ #[primary_span]
+ span: Span,
+ },
+ #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
+ Suggestion {
+ #[primary_span]
+ span: Span,
+ replace: String,
+ },
+}
+
+#[derive(LintDiagnostic)]
+#[diag(lint_noop_method_call)]
+#[note]
+pub struct NoopMethodCallDiag<'a> {
+ pub method: Symbol,
+ pub receiver_ty: Ty<'a>,
+ #[label]
+ pub label: Span,
+}
+
#[derive(LintDiagnostic)]
#[diag(lint_pass_by_value)]
pub struct PassByValueDiag {
Negative,
}
-impl AddSubdiagnostic for OverflowingBinHexSign {
- fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
+impl AddToDiagnostic for OverflowingBinHexSign {
+ fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
+ where
+ F: Fn(
+ &mut rustc_errors::Diagnostic,
+ rustc_errors::SubdiagnosticMessage,
+ ) -> rustc_errors::SubdiagnosticMessage,
+ {
match self {
OverflowingBinHexSign::Positive => {
diag.note(fluent::positive_note);
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
pub enum OverflowingBinHexSub<'a> {
#[suggestion(
suggestion,
pub sub: PathStatementDropSub,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
pub enum PathStatementDropSub {
- #[suggestion(
- suggestion,
- code = "drop({snippet});",
- applicability = "machine-applicable"
- )]
+ #[suggestion(suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
Suggestion {
#[primary_span]
span: Span,