1 #![allow(rustc::untranslatable_diagnostic)]
2 #![allow(rustc::diagnostic_outside_of_impl)]
3 use std::num::NonZeroU32;
6 fluent, AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage,
7 DiagnosticStyledString, SuggestionStyle,
9 use rustc_hir::def_id::DefId;
10 use rustc_macros::{LintDiagnostic, Subdiagnostic};
11 use rustc_middle::ty::{Predicate, Ty, TyCtxt};
12 use rustc_session::parse::ParseSess;
13 use rustc_span::{edition::Edition, sym, symbol::Ident, Span, Symbol};
16 builtin::InitError, builtin::TypeAliasBounds, errors::OverruledAttributeSub, LateContext,
20 #[derive(LintDiagnostic)]
21 #[diag(lint_array_into_iter)]
22 pub struct ArrayIntoIterDiag<'a> {
24 #[suggestion(use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
27 pub sub: Option<ArrayIntoIterDiagSub>,
30 #[derive(Subdiagnostic)]
31 pub enum ArrayIntoIterDiagSub {
32 #[suggestion(remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
37 #[multipart_suggestion(use_explicit_into_iter_suggestion, applicability = "maybe-incorrect")]
39 #[suggestion_part(code = "IntoIterator::into_iter(")]
41 #[suggestion_part(code = ")")]
47 #[derive(LintDiagnostic)]
48 #[diag(lint_builtin_while_true)]
49 pub struct BuiltinWhileTrue {
50 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
55 #[derive(LintDiagnostic)]
56 #[diag(lint_builtin_box_pointers)]
57 pub struct BuiltinBoxPointers<'a> {
61 #[derive(LintDiagnostic)]
62 #[diag(lint_builtin_non_shorthand_field_patterns)]
63 pub struct BuiltinNonShorthandFieldPatterns {
65 #[suggestion(code = "{prefix}{ident}", applicability = "machine-applicable")]
67 pub prefix: &'static str,
70 #[derive(LintDiagnostic)]
71 pub enum BuiltinUnsafe {
72 #[diag(lint_builtin_allow_internal_unsafe)]
74 #[diag(lint_builtin_unsafe_block)]
76 #[diag(lint_builtin_unsafe_trait)]
78 #[diag(lint_builtin_unsafe_impl)]
80 #[diag(lint_builtin_no_mangle_fn)]
81 #[note(lint_builtin_overridden_symbol_name)]
83 #[diag(lint_builtin_export_name_fn)]
84 #[note(lint_builtin_overridden_symbol_name)]
86 #[diag(lint_builtin_link_section_fn)]
87 #[note(lint_builtin_overridden_symbol_section)]
89 #[diag(lint_builtin_no_mangle_static)]
90 #[note(lint_builtin_overridden_symbol_name)]
92 #[diag(lint_builtin_export_name_static)]
93 #[note(lint_builtin_overridden_symbol_name)]
95 #[diag(lint_builtin_link_section_static)]
96 #[note(lint_builtin_overridden_symbol_section)]
98 #[diag(lint_builtin_no_mangle_method)]
99 #[note(lint_builtin_overridden_symbol_name)]
101 #[diag(lint_builtin_export_name_method)]
102 #[note(lint_builtin_overridden_symbol_name)]
104 #[diag(lint_builtin_decl_unsafe_fn)]
106 #[diag(lint_builtin_decl_unsafe_method)]
108 #[diag(lint_builtin_impl_unsafe_method)]
112 #[derive(LintDiagnostic)]
113 #[diag(lint_builtin_missing_doc)]
114 pub struct BuiltinMissingDoc<'a> {
115 pub article: &'a str,
119 #[derive(LintDiagnostic)]
120 #[diag(lint_builtin_missing_copy_impl)]
121 pub struct BuiltinMissingCopyImpl;
123 pub struct BuiltinMissingDebugImpl<'a> {
128 // Needed for def_path_str
129 impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> {
130 fn decorate_lint<'b>(
132 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
133 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
134 diag.set_arg("debug", self.tcx.def_path_str(self.def_id));
138 fn msg(&self) -> DiagnosticMessage {
139 fluent::lint_builtin_missing_debug_impl
143 #[derive(LintDiagnostic)]
144 #[diag(lint_builtin_anonymous_params)]
145 pub struct BuiltinAnonymousParams<'a> {
146 #[suggestion(code = "_: {ty_snip}")]
147 pub suggestion: (Span, Applicability),
148 pub ty_snip: &'a str,
151 // FIXME(davidtwco) translatable deprecated attr
152 #[derive(LintDiagnostic)]
153 #[diag(lint_builtin_deprecated_attr_link)]
154 pub struct BuiltinDeprecatedAttrLink<'a> {
159 pub suggestion: BuiltinDeprecatedAttrLinkSuggestion<'a>,
162 #[derive(Subdiagnostic)]
163 pub enum BuiltinDeprecatedAttrLinkSuggestion<'a> {
164 #[suggestion(msg_suggestion, code = "", applicability = "machine-applicable")]
170 #[suggestion(default_suggestion, code = "", applicability = "machine-applicable")]
177 #[derive(LintDiagnostic)]
178 #[diag(lint_builtin_deprecated_attr_used)]
179 pub struct BuiltinDeprecatedAttrUsed {
182 lint_builtin_deprecated_attr_default_suggestion,
185 applicability = "machine-applicable"
187 pub suggestion: Span,
190 #[derive(LintDiagnostic)]
191 #[diag(lint_builtin_unused_doc_comment)]
192 pub struct BuiltinUnusedDocComment<'a> {
197 pub sub: BuiltinUnusedDocCommentSub,
200 #[derive(Subdiagnostic)]
201 pub enum BuiltinUnusedDocCommentSub {
208 #[derive(LintDiagnostic)]
209 #[diag(lint_builtin_no_mangle_generic)]
210 pub struct BuiltinNoMangleGeneric {
211 // Use of `#[no_mangle]` suggests FFI intent; correct
212 // fix may be to monomorphize source by hand
213 #[suggestion(style = "short", code = "", applicability = "maybe-incorrect")]
214 pub suggestion: Span,
217 #[derive(LintDiagnostic)]
218 #[diag(lint_builtin_const_no_mangle)]
219 pub struct BuiltinConstNoMangle {
220 #[suggestion(code = "pub static", applicability = "machine-applicable")]
221 pub suggestion: Span,
224 #[derive(LintDiagnostic)]
225 #[diag(lint_builtin_mutable_transmutes)]
226 pub struct BuiltinMutablesTransmutes;
228 #[derive(LintDiagnostic)]
229 #[diag(lint_builtin_unstable_features)]
230 pub struct BuiltinUnstableFeatures;
232 // lint_ungated_async_fn_track_caller
233 pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
235 pub parse_sess: &'a ParseSess,
238 impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
239 fn decorate_lint<'b>(
241 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
242 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
243 diag.span_label(self.label, fluent::label);
244 rustc_session::parse::add_feature_diagnostics(
247 sym::closure_track_caller,
252 fn msg(&self) -> DiagnosticMessage {
253 fluent::lint_ungated_async_fn_track_caller
257 #[derive(LintDiagnostic)]
258 #[diag(lint_builtin_unreachable_pub)]
259 pub struct BuiltinUnreachablePub<'a> {
261 #[suggestion(code = "pub(crate)")]
262 pub suggestion: (Span, Applicability),
264 pub help: Option<()>,
267 pub struct SuggestChangingAssocTypes<'a, 'b> {
268 pub ty: &'a rustc_hir::Ty<'b>,
271 impl AddToDiagnostic for SuggestChangingAssocTypes<'_, '_> {
272 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
275 &mut rustc_errors::Diagnostic,
276 rustc_errors::SubdiagnosticMessage,
277 ) -> rustc_errors::SubdiagnosticMessage,
279 // Access to associates types should use `<T as Bound>::Assoc`, which does not need a
280 // bound. Let's see if this type does that.
282 // We use a HIR visitor to walk the type.
283 use rustc_hir::intravisit::{self, Visitor};
284 struct WalkAssocTypes<'a> {
285 err: &'a mut rustc_errors::Diagnostic,
287 impl Visitor<'_> for WalkAssocTypes<'_> {
290 qpath: &rustc_hir::QPath<'_>,
291 id: rustc_hir::HirId,
294 if TypeAliasBounds::is_type_variable_assoc(qpath) {
295 self.err.span_help(span, fluent::lint_builtin_type_alias_bounds_help);
297 intravisit::walk_qpath(self, qpath, id)
301 // Let's go for a walk!
302 let mut visitor = WalkAssocTypes { err: diag };
303 visitor.visit_ty(self.ty);
307 #[derive(LintDiagnostic)]
308 #[diag(lint_builtin_type_alias_where_clause)]
309 pub struct BuiltinTypeAliasWhereClause<'a, 'b> {
310 #[suggestion(code = "", applicability = "machine-applicable")]
311 pub suggestion: Span,
313 pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
316 #[derive(LintDiagnostic)]
317 #[diag(lint_builtin_type_alias_generic_bounds)]
318 pub struct BuiltinTypeAliasGenericBounds<'a, 'b> {
320 pub suggestion: BuiltinTypeAliasGenericBoundsSuggestion,
322 pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
325 pub struct BuiltinTypeAliasGenericBoundsSuggestion {
326 pub suggestions: Vec<(Span, String)>,
329 impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
330 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
333 &mut rustc_errors::Diagnostic,
334 rustc_errors::SubdiagnosticMessage,
335 ) -> rustc_errors::SubdiagnosticMessage,
337 diag.multipart_suggestion(
340 Applicability::MachineApplicable,
345 #[derive(LintDiagnostic)]
346 #[diag(lint_builtin_trivial_bounds)]
347 pub struct BuiltinTrivialBounds<'a> {
348 pub predicate_kind_name: &'a str,
349 pub predicate: Predicate<'a>,
352 #[derive(LintDiagnostic)]
353 pub enum BuiltinEllipsisInclusiveRangePatternsLint {
354 #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
356 #[suggestion(code = "{replace}", applicability = "machine-applicable")]
360 #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
362 #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")]
367 #[derive(LintDiagnostic)]
368 #[diag(lint_builtin_unnameable_test_items)]
369 pub struct BuiltinUnnameableTestItems;
371 #[derive(LintDiagnostic)]
372 #[diag(lint_builtin_keyword_idents)]
373 pub struct BuiltinKeywordIdents {
376 #[suggestion(code = "r#{kw}", applicability = "machine-applicable")]
377 pub suggestion: Span,
380 #[derive(LintDiagnostic)]
381 #[diag(lint_builtin_explicit_outlives)]
382 pub struct BuiltinExplicitOutlives {
385 pub suggestion: BuiltinExplicitOutlivesSuggestion,
388 #[derive(Subdiagnostic)]
389 #[multipart_suggestion(suggestion)]
390 pub struct BuiltinExplicitOutlivesSuggestion {
391 #[suggestion_part(code = "")]
392 pub spans: Vec<Span>,
394 pub applicability: Applicability,
397 #[derive(LintDiagnostic)]
398 #[diag(lint_builtin_incomplete_features)]
399 pub struct BuiltinIncompleteFeatures {
402 pub note: Option<BuiltinIncompleteFeaturesNote>,
404 pub help: Option<BuiltinIncompleteFeaturesHelp>,
407 #[derive(Subdiagnostic)]
409 pub struct BuiltinIncompleteFeaturesHelp;
411 #[derive(Subdiagnostic)]
413 pub struct BuiltinIncompleteFeaturesNote {
417 pub struct BuiltinUnpermittedTypeInit<'a> {
418 pub msg: DiagnosticMessage,
421 pub sub: BuiltinUnpermittedTypeInitSub,
424 impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
425 fn decorate_lint<'b>(
427 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
428 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
429 diag.set_arg("ty", self.ty);
430 diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
431 diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label_suggestion);
432 self.sub.add_to_diagnostic(diag);
436 fn msg(&self) -> rustc_errors::DiagnosticMessage {
441 // FIXME(davidtwco): make translatable
442 pub struct BuiltinUnpermittedTypeInitSub {
446 impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub {
447 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
450 &mut rustc_errors::Diagnostic,
451 rustc_errors::SubdiagnosticMessage,
452 ) -> rustc_errors::SubdiagnosticMessage,
454 let mut err = self.err;
456 if let Some(span) = err.span {
457 diag.span_note(span, err.message);
459 diag.note(err.message);
461 if let Some(e) = err.nested {
470 #[derive(LintDiagnostic)]
471 pub enum BuiltinClashingExtern<'a> {
472 #[diag(lint_builtin_clashing_extern_same_name)]
476 #[label(previous_decl_label)]
477 previous_decl_label: Span,
478 #[label(mismatch_label)]
479 mismatch_label: Span,
481 sub: BuiltinClashingExternSub<'a>,
483 #[diag(lint_builtin_clashing_extern_diff_name)]
487 #[label(previous_decl_label)]
488 previous_decl_label: Span,
489 #[label(mismatch_label)]
490 mismatch_label: Span,
492 sub: BuiltinClashingExternSub<'a>,
496 // FIXME(davidtwco): translatable expected/found
497 pub struct BuiltinClashingExternSub<'a> {
499 pub expected: Ty<'a>,
503 impl AddToDiagnostic for BuiltinClashingExternSub<'_> {
504 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
507 &mut rustc_errors::Diagnostic,
508 rustc_errors::SubdiagnosticMessage,
509 ) -> rustc_errors::SubdiagnosticMessage,
511 let mut expected_str = DiagnosticStyledString::new();
512 expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
513 let mut found_str = DiagnosticStyledString::new();
514 found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
515 diag.note_expected_found(&"", expected_str, &"", found_str);
519 #[derive(LintDiagnostic)]
520 #[diag(lint_builtin_deref_nullptr)]
521 pub struct BuiltinDerefNullptr {
526 // FIXME: migrate fluent::lint::builtin_asm_labels
528 #[derive(LintDiagnostic)]
529 pub enum BuiltinSpecialModuleNameUsed {
530 #[diag(lint_builtin_special_module_name_used_lib)]
534 #[diag(lint_builtin_special_module_name_used_main)]
539 #[derive(LintDiagnostic)]
540 #[diag(lint_builtin_unexpected_cli_config_name)]
542 pub struct BuiltinUnexpectedCliConfigName {
546 #[derive(LintDiagnostic)]
547 #[diag(lint_builtin_unexpected_cli_config_value)]
549 pub struct BuiltinUnexpectedCliConfigValue {
554 // deref_into_dyn_supertrait.rs
555 #[derive(LintDiagnostic)]
556 #[diag(lint_supertrait_as_deref_target)]
557 pub struct SupertraitAsDerefTarget<'a> {
559 pub target_principal: String,
560 // pub target_principal: Binder<'a, ExistentialTraitRef<'b>>,
562 pub label: Option<SupertraitAsDerefTargetLabel>,
565 #[derive(Subdiagnostic)]
567 pub struct SupertraitAsDerefTargetLabel {
572 // enum_intrinsics_non_enums.rs
573 #[derive(LintDiagnostic)]
574 #[diag(lint_enum_intrinsics_mem_discriminant)]
575 pub struct EnumIntrinsicsMemDiscriminate<'a> {
576 pub ty_param: Ty<'a>,
581 #[derive(LintDiagnostic)]
582 #[diag(lint_enum_intrinsics_mem_variant)]
584 pub struct EnumIntrinsicsMemVariant<'a> {
585 pub ty_param: Ty<'a>,
589 #[derive(LintDiagnostic)]
590 #[diag(lint_expectation)]
591 pub struct Expectation {
593 pub rationale: Option<ExpectationNote>,
595 pub note: Option<()>,
598 #[derive(Subdiagnostic)]
600 pub struct ExpectationNote {
601 pub rationale: Symbol,
604 // for_loops_over_fallibles.rs
605 #[derive(LintDiagnostic)]
606 #[diag(lint_for_loops_over_fallibles)]
607 pub struct ForLoopsOverFalliblesDiag<'a> {
608 pub article: &'static str,
609 pub ty: &'static str,
611 pub sub: ForLoopsOverFalliblesLoopSub<'a>,
613 pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>,
615 pub suggestion: ForLoopsOverFalliblesSuggestion<'a>,
618 #[derive(Subdiagnostic)]
619 pub enum ForLoopsOverFalliblesLoopSub<'a> {
620 #[suggestion(remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
626 #[multipart_suggestion(use_while_let, applicability = "maybe-incorrect")]
628 #[suggestion_part(code = "while let {var}(")]
630 #[suggestion_part(code = ") = ")]
636 #[derive(Subdiagnostic)]
637 #[suggestion(use_question_mark, code = "?", applicability = "maybe-incorrect")]
638 pub struct ForLoopsOverFalliblesQuestionMark {
640 pub suggestion: Span,
643 #[derive(Subdiagnostic)]
644 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
645 pub struct ForLoopsOverFalliblesSuggestion<'a> {
647 #[suggestion_part(code = "if let {var}(")]
648 pub start_span: Span,
649 #[suggestion_part(code = ") = ")]
653 // hidden_unicode_codepoints.rs
654 #[derive(LintDiagnostic)]
655 #[diag(lint_hidden_unicode_codepoints)]
657 pub struct HiddenUnicodeCodepointsDiag<'a> {
661 pub span_label: Span,
663 pub labels: Option<HiddenUnicodeCodepointsDiagLabels>,
665 pub sub: HiddenUnicodeCodepointsDiagSub,
668 pub struct HiddenUnicodeCodepointsDiagLabels {
669 pub spans: Vec<(char, Span)>,
672 impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels {
673 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
676 &mut rustc_errors::Diagnostic,
677 rustc_errors::SubdiagnosticMessage,
678 ) -> rustc_errors::SubdiagnosticMessage,
680 for (c, span) in self.spans {
681 diag.span_label(span, format!("{:?}", c));
686 pub enum HiddenUnicodeCodepointsDiagSub {
687 Escape { spans: Vec<(char, Span)> },
688 NoEscape { spans: Vec<(char, Span)> },
691 // Used because of multiple multipart_suggestion and note
692 impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub {
693 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
696 &mut rustc_errors::Diagnostic,
697 rustc_errors::SubdiagnosticMessage,
698 ) -> rustc_errors::SubdiagnosticMessage,
701 HiddenUnicodeCodepointsDiagSub::Escape { spans } => {
702 diag.multipart_suggestion_with_style(
703 fluent::suggestion_remove,
704 spans.iter().map(|(_, span)| (*span, "".to_string())).collect(),
705 Applicability::MachineApplicable,
706 SuggestionStyle::HideCodeAlways,
708 diag.multipart_suggestion(
709 fluent::suggestion_escape,
713 let c = format!("{:?}", c);
714 (span, c[1..c.len() - 1].to_string())
717 Applicability::MachineApplicable,
720 HiddenUnicodeCodepointsDiagSub::NoEscape { spans } => {
721 // FIXME: in other suggestions we've reversed the inner spans of doc comments. We
722 // should do the same here to provide the same good suggestions as we do for
728 .map(|(c, _)| format!("{:?}", c))
729 .collect::<Vec<String>>()
732 diag.note(fluent::suggestion_remove);
733 diag.note(fluent::no_suggestion_note_escape);
740 #[derive(LintDiagnostic)]
741 #[diag(lint_default_hash_types)]
743 pub struct DefaultHashTypesDiag<'a> {
744 pub preferred: &'a str,
748 #[derive(LintDiagnostic)]
749 #[diag(lint_query_instability)]
751 pub struct QueryInstability {
755 #[derive(LintDiagnostic)]
756 #[diag(lint_tykind_kind)]
757 pub struct TykindKind {
758 #[suggestion(code = "ty", applicability = "maybe-incorrect")]
759 pub suggestion: Span,
762 #[derive(LintDiagnostic)]
765 pub struct TykindDiag;
767 #[derive(LintDiagnostic)]
768 #[diag(lint_ty_qualified)]
769 pub struct TyQualified {
771 #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
772 pub suggestion: Span,
775 #[derive(LintDiagnostic)]
776 #[diag(lint_lintpass_by_hand)]
778 pub struct LintPassByHand;
780 #[derive(LintDiagnostic)]
781 #[diag(lint_non_existant_doc_keyword)]
783 pub struct NonExistantDocKeyword {
787 #[derive(LintDiagnostic)]
788 #[diag(lint_diag_out_of_impl)]
789 pub struct DiagOutOfImpl;
791 #[derive(LintDiagnostic)]
792 #[diag(lint_untranslatable_diag)]
793 pub struct UntranslatableDiag;
795 #[derive(LintDiagnostic)]
796 #[diag(lint_bad_opt_access)]
797 pub struct BadOptAccessDiag<'a> {
802 #[derive(LintDiagnostic)]
803 pub enum NonBindingLet {
804 #[diag(lint_non_binding_let_on_sync_lock)]
807 sub: NonBindingLetSub,
809 #[diag(lint_non_binding_let_on_drop_type)]
812 sub: NonBindingLetSub,
816 pub struct NonBindingLetSub {
817 pub suggestion: Span,
818 pub multi_suggestion_start: Span,
819 pub multi_suggestion_end: Span,
822 impl AddToDiagnostic for NonBindingLetSub {
823 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
826 &mut rustc_errors::Diagnostic,
827 rustc_errors::SubdiagnosticMessage,
828 ) -> rustc_errors::SubdiagnosticMessage,
830 diag.span_suggestion_verbose(
832 fluent::lint_non_binding_let_suggestion,
834 Applicability::MachineApplicable,
836 diag.multipart_suggestion(
837 fluent::lint_non_binding_let_multi_suggestion,
839 (self.multi_suggestion_start, "drop(".to_string()),
840 (self.multi_suggestion_end, ")".to_string()),
842 Applicability::MachineApplicable,
848 #[derive(LintDiagnostic)]
849 #[diag(lint_overruled_attribute)]
850 pub struct OverruledAtributeLint<'a> {
853 pub lint_level: &'a str,
854 pub lint_source: Symbol,
856 pub sub: OverruledAttributeSub,
859 #[derive(LintDiagnostic)]
860 #[diag(lint_deprecated_lint_name)]
861 pub struct DeprecatedLintName<'a> {
863 #[suggestion(code = "{replace}", applicability = "machine-applicable")]
864 pub suggestion: Span,
865 pub replace: &'a str,
868 // FIXME: Non-translatable msg
869 #[derive(LintDiagnostic)]
870 #[diag(lint_renamed_or_removed_lint)]
871 pub struct RenamedOrRemovedLint<'a> {
874 pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>,
877 #[derive(Subdiagnostic)]
878 #[suggestion(suggestion, code = "{replace}", applicability = "machine-applicable")]
879 pub struct RenamedOrRemovedLintSuggestion<'a> {
881 pub suggestion: Span,
882 pub replace: &'a str,
885 #[derive(LintDiagnostic)]
886 #[diag(lint_unknown_lint)]
887 pub struct UnknownLint {
890 pub suggestion: Option<UnknownLintSuggestion>,
893 #[derive(Subdiagnostic)]
894 #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
895 pub struct UnknownLintSuggestion {
897 pub suggestion: Span,
901 #[derive(LintDiagnostic)]
902 #[diag(lint_ignored_unless_crate_specified)]
903 pub struct IgnoredUnlessCrateSpecified<'a> {
909 #[derive(LintDiagnostic)]
910 #[diag(lint_cstring_ptr)]
913 pub struct CStringPtr {
914 #[label(as_ptr_label)]
916 #[label(unwrap_label)]
920 // multiple_supertrait_upcastable.rs
921 #[derive(LintDiagnostic)]
922 #[diag(lint_multple_supertrait_upcastable)]
923 pub struct MultipleSupertraitUpcastable {
927 // non_ascii_idents.rs
928 #[derive(LintDiagnostic)]
929 #[diag(lint_identifier_non_ascii_char)]
930 pub struct IdentifierNonAsciiChar;
932 #[derive(LintDiagnostic)]
933 #[diag(lint_identifier_uncommon_codepoints)]
934 pub struct IdentifierUncommonCodepoints;
936 #[derive(LintDiagnostic)]
937 #[diag(lint_confusable_identifier_pair)]
938 pub struct ConfusableIdentifierPair {
939 pub existing_sym: Symbol,
945 #[derive(LintDiagnostic)]
946 #[diag(lint_mixed_script_confusables)]
947 #[note(includes_note)]
949 pub struct MixedScriptConfusables {
951 pub includes: String,
955 pub struct NonFmtPanicUnused {
957 pub suggestion: Option<Span>,
960 // Used because of two suggestions based on one Option<Span>
961 impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
962 fn decorate_lint<'b>(
964 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
965 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
966 diag.set_arg("count", self.count);
967 diag.note(fluent::note);
968 if let Some(span) = self.suggestion {
969 diag.span_suggestion(
971 fluent::add_args_suggestion,
973 Applicability::HasPlaceholders,
975 diag.span_suggestion(
977 fluent::add_fmt_suggestion,
979 Applicability::MachineApplicable,
985 fn msg(&self) -> rustc_errors::DiagnosticMessage {
986 fluent::lint_non_fmt_panic_unused
990 #[derive(LintDiagnostic)]
991 #[diag(lint_non_fmt_panic_braces)]
993 pub struct NonFmtPanicBraces {
995 #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
996 pub suggestion: Option<Span>,
999 // nonstandard_style.rs
1000 #[derive(LintDiagnostic)]
1001 #[diag(lint_non_camel_case_type)]
1002 pub struct NonCamelCaseType<'a> {
1006 pub sub: NonCamelCaseTypeSub,
1009 #[derive(Subdiagnostic)]
1010 pub enum NonCamelCaseTypeSub {
1016 #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1024 #[derive(LintDiagnostic)]
1025 #[diag(lint_non_snake_case)]
1026 pub struct NonSnakeCaseDiag<'a> {
1031 pub sub: NonSnakeCaseDiagSub,
1034 pub enum NonSnakeCaseDiagSub {
1035 Label { span: Span },
1037 RenameOrConvertSuggestion { span: Span, suggestion: Ident },
1038 ConvertSuggestion { span: Span, suggestion: String },
1039 SuggestionAndNote { span: Span },
1042 impl AddToDiagnostic for NonSnakeCaseDiagSub {
1043 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
1046 &mut rustc_errors::Diagnostic,
1047 rustc_errors::SubdiagnosticMessage,
1048 ) -> rustc_errors::SubdiagnosticMessage,
1051 NonSnakeCaseDiagSub::Label { span } => {
1052 diag.span_label(span, fluent::label);
1054 NonSnakeCaseDiagSub::Help => {
1055 diag.help(fluent::help);
1057 NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
1058 diag.span_suggestion(
1060 fluent::convert_suggestion,
1062 Applicability::MaybeIncorrect,
1065 NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
1066 diag.span_suggestion(
1068 fluent::rename_or_convert_suggestion,
1070 Applicability::MaybeIncorrect,
1073 NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
1074 diag.note(fluent::cannot_convert_note);
1075 diag.span_suggestion(
1077 fluent::rename_suggestion,
1079 Applicability::MaybeIncorrect,
1086 #[derive(LintDiagnostic)]
1087 #[diag(lint_non_upper_case_global)]
1088 pub struct NonUpperCaseGlobal<'a> {
1092 pub sub: NonUpperCaseGlobalSub,
1095 #[derive(Subdiagnostic)]
1096 pub enum NonUpperCaseGlobalSub {
1102 #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1110 // noop_method_call.rs
1111 #[derive(LintDiagnostic)]
1112 #[diag(lint_noop_method_call)]
1114 pub struct NoopMethodCallDiag<'a> {
1116 pub receiver_ty: Ty<'a>,
1122 #[derive(LintDiagnostic)]
1123 #[diag(lint_pass_by_value)]
1124 pub struct PassByValueDiag {
1126 #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
1127 pub suggestion: Span,
1130 // redundant_semicolon.rs
1131 #[derive(LintDiagnostic)]
1132 #[diag(lint_redundant_semicolons)]
1133 pub struct RedundantSemicolonsDiag {
1135 #[suggestion(code = "", applicability = "maybe-incorrect")]
1136 pub suggestion: Span,
1140 pub struct DropTraitConstraintsDiag<'a> {
1141 pub predicate: Predicate<'a>,
1142 pub tcx: TyCtxt<'a>,
1146 // Needed for def_path_str
1147 impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
1148 fn decorate_lint<'b>(
1150 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1151 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1152 diag.set_arg("predicate", self.predicate);
1153 diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
1156 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1157 fluent::lint_drop_trait_constraints
1161 pub struct DropGlue<'a> {
1162 pub tcx: TyCtxt<'a>,
1166 // Needed for def_path_str
1167 impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
1168 fn decorate_lint<'b>(
1170 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1171 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1172 diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
1175 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1176 fluent::lint_drop_glue
1181 #[derive(LintDiagnostic)]
1182 #[diag(lint_range_endpoint_out_of_range)]
1183 pub struct RangeEndpointOutOfRange<'a> {
1185 #[suggestion(code = "{start}..={literal}{suffix}", applicability = "machine-applicable")]
1186 pub suggestion: Span,
1189 pub suffix: &'a str,
1192 #[derive(LintDiagnostic)]
1193 #[diag(lint_overflowing_bin_hex)]
1194 pub struct OverflowingBinHex<'a> {
1198 pub actually: String,
1200 pub sign: OverflowingBinHexSign,
1202 pub sub: Option<OverflowingBinHexSub<'a>>,
1205 pub enum OverflowingBinHexSign {
1210 impl AddToDiagnostic for OverflowingBinHexSign {
1211 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
1214 &mut rustc_errors::Diagnostic,
1215 rustc_errors::SubdiagnosticMessage,
1216 ) -> rustc_errors::SubdiagnosticMessage,
1219 OverflowingBinHexSign::Positive => {
1220 diag.note(fluent::positive_note);
1222 OverflowingBinHexSign::Negative => {
1223 diag.note(fluent::negative_note);
1224 diag.note(fluent::negative_becomes_note);
1230 #[derive(Subdiagnostic)]
1231 pub enum OverflowingBinHexSub<'a> {
1234 code = "{sans_suffix}{suggestion_ty}",
1235 applicability = "machine-applicable"
1240 suggestion_ty: &'a str,
1241 sans_suffix: &'a str,
1244 Help { suggestion_ty: &'a str },
1247 #[derive(LintDiagnostic)]
1248 #[diag(lint_overflowing_int)]
1250 pub struct OverflowingInt<'a> {
1256 pub help: Option<OverflowingIntHelp<'a>>,
1259 #[derive(Subdiagnostic)]
1261 pub struct OverflowingIntHelp<'a> {
1262 pub suggestion_ty: &'a str,
1265 #[derive(LintDiagnostic)]
1266 #[diag(lint_only_cast_u8_to_char)]
1267 pub struct OnlyCastu8ToChar {
1268 #[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
1273 #[derive(LintDiagnostic)]
1274 #[diag(lint_overflowing_uint)]
1276 pub struct OverflowingUInt<'a> {
1283 #[derive(LintDiagnostic)]
1284 #[diag(lint_overflowing_literal)]
1286 pub struct OverflowingLiteral<'a> {
1291 #[derive(LintDiagnostic)]
1292 #[diag(lint_unused_comparisons)]
1293 pub struct UnusedComparisons;
1295 pub struct ImproperCTypes<'a> {
1299 pub help: Option<DiagnosticMessage>,
1300 pub note: DiagnosticMessage,
1301 pub span_note: Option<Span>,
1304 // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
1305 impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
1306 fn decorate_lint<'b>(
1308 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1309 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1310 diag.set_arg("ty", self.ty);
1311 diag.set_arg("desc", self.desc);
1312 diag.span_label(self.label, fluent::label);
1313 if let Some(help) = self.help {
1316 diag.note(self.note);
1317 if let Some(note) = self.span_note {
1318 diag.span_note(note, fluent::note);
1323 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1324 fluent::lint_improper_ctypes
1328 #[derive(LintDiagnostic)]
1329 #[diag(lint_variant_size_differences)]
1330 pub struct VariantSizeDifferencesDiag {
1334 #[derive(LintDiagnostic)]
1335 #[diag(lint_atomic_ordering_load)]
1337 pub struct AtomicOrderingLoad;
1339 #[derive(LintDiagnostic)]
1340 #[diag(lint_atomic_ordering_store)]
1342 pub struct AtomicOrderingStore;
1344 #[derive(LintDiagnostic)]
1345 #[diag(lint_atomic_ordering_fence)]
1347 pub struct AtomicOrderingFence;
1349 #[derive(LintDiagnostic)]
1350 #[diag(lint_atomic_ordering_invalid)]
1352 pub struct InvalidAtomicOrderingDiag {
1355 pub fail_order_arg_span: Span,
1359 #[derive(LintDiagnostic)]
1360 #[diag(lint_unused_op)]
1361 pub struct UnusedOp<'a> {
1365 #[suggestion(style = "verbose", code = "let _ = ", applicability = "machine-applicable")]
1366 pub suggestion: Span,
1369 #[derive(LintDiagnostic)]
1370 #[diag(lint_unused_result)]
1371 pub struct UnusedResult<'a> {
1375 // FIXME(davidtwco): this isn't properly translatable becauses of the
1377 #[derive(LintDiagnostic)]
1378 #[diag(lint_unused_closure)]
1380 pub struct UnusedClosure<'a> {
1386 // FIXME(davidtwco): this isn't properly translatable becauses of the
1388 #[derive(LintDiagnostic)]
1389 #[diag(lint_unused_generator)]
1391 pub struct UnusedGenerator<'a> {
1397 // FIXME(davidtwco): this isn't properly translatable becauses of the pre/post
1399 pub struct UnusedDef<'a, 'b> {
1402 pub cx: &'a LateContext<'b>,
1404 pub note: Option<Symbol>,
1407 // Needed because of def_path_str
1408 impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
1409 fn decorate_lint<'b>(
1411 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1412 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1413 diag.set_arg("pre", self.pre);
1414 diag.set_arg("post", self.post);
1415 diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id));
1416 // check for #[must_use = "..."]
1417 if let Some(note) = self.note {
1418 diag.note(note.as_str());
1423 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1424 fluent::lint_unused_def
1428 #[derive(LintDiagnostic)]
1429 #[diag(lint_path_statement_drop)]
1430 pub struct PathStatementDrop {
1432 pub sub: PathStatementDropSub,
1435 #[derive(Subdiagnostic)]
1436 pub enum PathStatementDropSub {
1437 #[suggestion(suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
1450 #[derive(LintDiagnostic)]
1451 #[diag(lint_path_statement_no_effect)]
1452 pub struct PathStatementNoEffect;
1454 #[derive(LintDiagnostic)]
1455 #[diag(lint_unused_delim)]
1456 pub struct UnusedDelim<'a> {
1457 pub delim: &'static str,
1460 pub suggestion: Option<UnusedDelimSuggestion>,
1463 #[derive(Subdiagnostic)]
1464 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1465 pub struct UnusedDelimSuggestion {
1466 #[suggestion_part(code = "{start_replace}")]
1467 pub start_span: Span,
1468 pub start_replace: &'static str,
1469 #[suggestion_part(code = "{end_replace}")]
1471 pub end_replace: &'static str,
1474 #[derive(LintDiagnostic)]
1475 #[diag(lint_unused_import_braces)]
1476 pub struct UnusedImportBracesDiag {
1480 #[derive(LintDiagnostic)]
1481 #[diag(lint_unused_allocation)]
1482 pub struct UnusedAllocationDiag;
1484 #[derive(LintDiagnostic)]
1485 #[diag(lint_unused_allocation_mut)]
1486 pub struct UnusedAllocationMutDiag;