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 // non_ascii_idents.rs
921 #[derive(LintDiagnostic)]
922 #[diag(lint_identifier_non_ascii_char)]
923 pub struct IdentifierNonAsciiChar;
925 #[derive(LintDiagnostic)]
926 #[diag(lint_identifier_uncommon_codepoints)]
927 pub struct IdentifierUncommonCodepoints;
929 #[derive(LintDiagnostic)]
930 #[diag(lint_confusable_identifier_pair)]
931 pub struct ConfusableIdentifierPair {
932 pub existing_sym: Symbol,
938 #[derive(LintDiagnostic)]
939 #[diag(lint_mixed_script_confusables)]
940 #[note(includes_note)]
942 pub struct MixedScriptConfusables {
944 pub includes: String,
948 pub struct NonFmtPanicUnused {
950 pub suggestion: Option<Span>,
953 // Used because of two suggestions based on one Option<Span>
954 impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused {
955 fn decorate_lint<'b>(
957 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
958 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
959 diag.set_arg("count", self.count);
960 diag.note(fluent::note);
961 if let Some(span) = self.suggestion {
962 diag.span_suggestion(
964 fluent::add_args_suggestion,
966 Applicability::HasPlaceholders,
968 diag.span_suggestion(
970 fluent::add_fmt_suggestion,
972 Applicability::MachineApplicable,
978 fn msg(&self) -> rustc_errors::DiagnosticMessage {
979 fluent::lint_non_fmt_panic_unused
983 #[derive(LintDiagnostic)]
984 #[diag(lint_non_fmt_panic_braces)]
986 pub struct NonFmtPanicBraces {
988 #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
989 pub suggestion: Option<Span>,
992 // nonstandard_style.rs
993 #[derive(LintDiagnostic)]
994 #[diag(lint_non_camel_case_type)]
995 pub struct NonCamelCaseType<'a> {
999 pub sub: NonCamelCaseTypeSub,
1002 #[derive(Subdiagnostic)]
1003 pub enum NonCamelCaseTypeSub {
1009 #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1017 #[derive(LintDiagnostic)]
1018 #[diag(lint_non_snake_case)]
1019 pub struct NonSnakeCaseDiag<'a> {
1024 pub sub: NonSnakeCaseDiagSub,
1027 pub enum NonSnakeCaseDiagSub {
1028 Label { span: Span },
1030 RenameOrConvertSuggestion { span: Span, suggestion: Ident },
1031 ConvertSuggestion { span: Span, suggestion: String },
1032 SuggestionAndNote { span: Span },
1035 impl AddToDiagnostic for NonSnakeCaseDiagSub {
1036 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
1039 &mut rustc_errors::Diagnostic,
1040 rustc_errors::SubdiagnosticMessage,
1041 ) -> rustc_errors::SubdiagnosticMessage,
1044 NonSnakeCaseDiagSub::Label { span } => {
1045 diag.span_label(span, fluent::label);
1047 NonSnakeCaseDiagSub::Help => {
1048 diag.help(fluent::help);
1050 NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
1051 diag.span_suggestion(
1053 fluent::convert_suggestion,
1055 Applicability::MaybeIncorrect,
1058 NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
1059 diag.span_suggestion(
1061 fluent::rename_or_convert_suggestion,
1063 Applicability::MaybeIncorrect,
1066 NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
1067 diag.note(fluent::cannot_convert_note);
1068 diag.span_suggestion(
1070 fluent::rename_suggestion,
1072 Applicability::MaybeIncorrect,
1079 #[derive(LintDiagnostic)]
1080 #[diag(lint_non_upper_case_global)]
1081 pub struct NonUpperCaseGlobal<'a> {
1085 pub sub: NonUpperCaseGlobalSub,
1088 #[derive(Subdiagnostic)]
1089 pub enum NonUpperCaseGlobalSub {
1095 #[suggestion(suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1103 // noop_method_call.rs
1104 #[derive(LintDiagnostic)]
1105 #[diag(lint_noop_method_call)]
1107 pub struct NoopMethodCallDiag<'a> {
1109 pub receiver_ty: Ty<'a>,
1115 #[derive(LintDiagnostic)]
1116 #[diag(lint_pass_by_value)]
1117 pub struct PassByValueDiag {
1119 #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
1120 pub suggestion: Span,
1123 // redundant_semicolon.rs
1124 #[derive(LintDiagnostic)]
1125 #[diag(lint_redundant_semicolons)]
1126 pub struct RedundantSemicolonsDiag {
1128 #[suggestion(code = "", applicability = "maybe-incorrect")]
1129 pub suggestion: Span,
1133 pub struct DropTraitConstraintsDiag<'a> {
1134 pub predicate: Predicate<'a>,
1135 pub tcx: TyCtxt<'a>,
1139 // Needed for def_path_str
1140 impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> {
1141 fn decorate_lint<'b>(
1143 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1144 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1145 diag.set_arg("predicate", self.predicate);
1146 diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
1149 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1150 fluent::lint_drop_trait_constraints
1154 pub struct DropGlue<'a> {
1155 pub tcx: TyCtxt<'a>,
1159 // Needed for def_path_str
1160 impl<'a> DecorateLint<'a, ()> for DropGlue<'_> {
1161 fn decorate_lint<'b>(
1163 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1164 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1165 diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id))
1168 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1169 fluent::lint_drop_glue
1174 #[derive(LintDiagnostic)]
1175 #[diag(lint_range_endpoint_out_of_range)]
1176 pub struct RangeEndpointOutOfRange<'a> {
1178 #[suggestion(code = "{start}..={literal}{suffix}", applicability = "machine-applicable")]
1179 pub suggestion: Span,
1182 pub suffix: &'a str,
1185 #[derive(LintDiagnostic)]
1186 #[diag(lint_overflowing_bin_hex)]
1187 pub struct OverflowingBinHex<'a> {
1191 pub actually: String,
1193 pub sign: OverflowingBinHexSign,
1195 pub sub: Option<OverflowingBinHexSub<'a>>,
1198 pub enum OverflowingBinHexSign {
1203 impl AddToDiagnostic for OverflowingBinHexSign {
1204 fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
1207 &mut rustc_errors::Diagnostic,
1208 rustc_errors::SubdiagnosticMessage,
1209 ) -> rustc_errors::SubdiagnosticMessage,
1212 OverflowingBinHexSign::Positive => {
1213 diag.note(fluent::positive_note);
1215 OverflowingBinHexSign::Negative => {
1216 diag.note(fluent::negative_note);
1217 diag.note(fluent::negative_becomes_note);
1223 #[derive(Subdiagnostic)]
1224 pub enum OverflowingBinHexSub<'a> {
1227 code = "{sans_suffix}{suggestion_ty}",
1228 applicability = "machine-applicable"
1233 suggestion_ty: &'a str,
1234 sans_suffix: &'a str,
1237 Help { suggestion_ty: &'a str },
1240 #[derive(LintDiagnostic)]
1241 #[diag(lint_overflowing_int)]
1243 pub struct OverflowingInt<'a> {
1249 pub help: Option<OverflowingIntHelp<'a>>,
1252 #[derive(Subdiagnostic)]
1254 pub struct OverflowingIntHelp<'a> {
1255 pub suggestion_ty: &'a str,
1258 #[derive(LintDiagnostic)]
1259 #[diag(lint_only_cast_u8_to_char)]
1260 pub struct OnlyCastu8ToChar {
1261 #[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
1266 #[derive(LintDiagnostic)]
1267 #[diag(lint_overflowing_uint)]
1269 pub struct OverflowingUInt<'a> {
1276 #[derive(LintDiagnostic)]
1277 #[diag(lint_overflowing_literal)]
1279 pub struct OverflowingLiteral<'a> {
1284 #[derive(LintDiagnostic)]
1285 #[diag(lint_unused_comparisons)]
1286 pub struct UnusedComparisons;
1288 pub struct ImproperCTypes<'a> {
1292 pub help: Option<DiagnosticMessage>,
1293 pub note: DiagnosticMessage,
1294 pub span_note: Option<Span>,
1297 // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span>
1298 impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> {
1299 fn decorate_lint<'b>(
1301 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1302 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1303 diag.set_arg("ty", self.ty);
1304 diag.set_arg("desc", self.desc);
1305 diag.span_label(self.label, fluent::label);
1306 if let Some(help) = self.help {
1309 diag.note(self.note);
1310 if let Some(note) = self.span_note {
1311 diag.span_note(note, fluent::note);
1316 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1317 fluent::lint_improper_ctypes
1321 #[derive(LintDiagnostic)]
1322 #[diag(lint_variant_size_differences)]
1323 pub struct VariantSizeDifferencesDiag {
1327 #[derive(LintDiagnostic)]
1328 #[diag(lint_atomic_ordering_load)]
1330 pub struct AtomicOrderingLoad;
1332 #[derive(LintDiagnostic)]
1333 #[diag(lint_atomic_ordering_store)]
1335 pub struct AtomicOrderingStore;
1337 #[derive(LintDiagnostic)]
1338 #[diag(lint_atomic_ordering_fence)]
1340 pub struct AtomicOrderingFence;
1342 #[derive(LintDiagnostic)]
1343 #[diag(lint_atomic_ordering_invalid)]
1345 pub struct InvalidAtomicOrderingDiag {
1348 pub fail_order_arg_span: Span,
1352 #[derive(LintDiagnostic)]
1353 #[diag(lint_unused_op)]
1354 pub struct UnusedOp<'a> {
1358 #[suggestion(style = "verbose", code = "let _ = ", applicability = "machine-applicable")]
1359 pub suggestion: Span,
1362 #[derive(LintDiagnostic)]
1363 #[diag(lint_unused_result)]
1364 pub struct UnusedResult<'a> {
1368 // FIXME(davidtwco): this isn't properly translatable becauses of the
1370 #[derive(LintDiagnostic)]
1371 #[diag(lint_unused_closure)]
1373 pub struct UnusedClosure<'a> {
1379 // FIXME(davidtwco): this isn't properly translatable becauses of the
1381 #[derive(LintDiagnostic)]
1382 #[diag(lint_unused_generator)]
1384 pub struct UnusedGenerator<'a> {
1390 // FIXME(davidtwco): this isn't properly translatable becauses of the pre/post
1392 pub struct UnusedDef<'a, 'b> {
1395 pub cx: &'a LateContext<'b>,
1397 pub note: Option<Symbol>,
1400 // Needed because of def_path_str
1401 impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> {
1402 fn decorate_lint<'b>(
1404 diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>,
1405 ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
1406 diag.set_arg("pre", self.pre);
1407 diag.set_arg("post", self.post);
1408 diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id));
1409 // check for #[must_use = "..."]
1410 if let Some(note) = self.note {
1411 diag.note(note.as_str());
1416 fn msg(&self) -> rustc_errors::DiagnosticMessage {
1417 fluent::lint_unused_def
1421 #[derive(LintDiagnostic)]
1422 #[diag(lint_path_statement_drop)]
1423 pub struct PathStatementDrop {
1425 pub sub: PathStatementDropSub,
1428 #[derive(Subdiagnostic)]
1429 pub enum PathStatementDropSub {
1430 #[suggestion(suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
1443 #[derive(LintDiagnostic)]
1444 #[diag(lint_path_statement_no_effect)]
1445 pub struct PathStatementNoEffect;
1447 #[derive(LintDiagnostic)]
1448 #[diag(lint_unused_delim)]
1449 pub struct UnusedDelim<'a> {
1450 pub delim: &'static str,
1453 pub suggestion: Option<UnusedDelimSuggestion>,
1456 #[derive(Subdiagnostic)]
1457 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1458 pub struct UnusedDelimSuggestion {
1459 #[suggestion_part(code = "{start_replace}")]
1460 pub start_span: Span,
1461 pub start_replace: &'static str,
1462 #[suggestion_part(code = "{end_replace}")]
1464 pub end_replace: &'static str,
1467 #[derive(LintDiagnostic)]
1468 #[diag(lint_unused_import_braces)]
1469 pub struct UnusedImportBracesDiag {
1473 #[derive(LintDiagnostic)]
1474 #[diag(lint_unused_allocation)]
1475 pub struct UnusedAllocationDiag;
1477 #[derive(LintDiagnostic)]
1478 #[diag(lint_unused_allocation_mut)]
1479 pub struct UnusedAllocationMutDiag;