1#![allow(rustc::untranslatable_diagnostic)]
4use std::num::NonZero;
5
6use rustc_errors::codes::*;
7use rustc_errors::{
8 Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
9 EmissionGuarantee, LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle,
10};
11use rustc_hir as hir;
12use rustc_hir::def_id::DefId;
13use rustc_hir::intravisit::VisitorExt;
14use rustc_macros::{LintDiagnostic, Subdiagnostic};
15use rustc_middle::ty::inhabitedness::InhabitedPredicate;
16use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
17use rustc_session::Session;
18use rustc_span::edition::Edition;
19use rustc_span::{Ident, Span, Symbol, sym};
20
21use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds};
22use crate::errors::{OverruledAttributeSub, RequestedLevel};
23use crate::lifetime_syntax::LifetimeSyntaxCategories;
24use crate::{LateContext, fluent_generated as fluent};
25
26#[derive(LintDiagnostic)]
28#[diag(lint_shadowed_into_iter)]
29pub(crate) struct ShadowedIntoIterDiag {
30 pub target: &'static str,
31 pub edition: &'static str,
32 #[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")]
33 pub suggestion: Span,
34 #[subdiagnostic]
35 pub sub: Option<ShadowedIntoIterDiagSub>,
36}
37
38#[derive(Subdiagnostic)]
39pub(crate) enum ShadowedIntoIterDiagSub {
40 #[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")]
41 RemoveIntoIter {
42 #[primary_span]
43 span: Span,
44 },
45 #[multipart_suggestion(
46 lint_use_explicit_into_iter_suggestion,
47 applicability = "maybe-incorrect"
48 )]
49 UseExplicitIntoIter {
50 #[suggestion_part(code = "IntoIterator::into_iter(")]
51 start_span: Span,
52 #[suggestion_part(code = ")")]
53 end_span: Span,
54 },
55}
56
57#[derive(LintDiagnostic)]
59#[diag(lint_implicit_unsafe_autorefs)]
60#[note]
61pub(crate) struct ImplicitUnsafeAutorefsDiag<'a> {
62 #[label(lint_raw_ptr)]
63 pub raw_ptr_span: Span,
64 pub raw_ptr_ty: Ty<'a>,
65 #[subdiagnostic]
66 pub origin: ImplicitUnsafeAutorefsOrigin<'a>,
67 #[subdiagnostic]
68 pub method: Option<ImplicitUnsafeAutorefsMethodNote>,
69 #[subdiagnostic]
70 pub suggestion: ImplicitUnsafeAutorefsSuggestion,
71}
72
73#[derive(Subdiagnostic)]
74pub(crate) enum ImplicitUnsafeAutorefsOrigin<'a> {
75 #[note(lint_autoref)]
76 Autoref {
77 #[primary_span]
78 autoref_span: Span,
79 autoref_ty: Ty<'a>,
80 },
81 #[note(lint_overloaded_deref)]
82 OverloadedDeref,
83}
84
85#[derive(Subdiagnostic)]
86#[note(lint_method_def)]
87pub(crate) struct ImplicitUnsafeAutorefsMethodNote {
88 #[primary_span]
89 pub def_span: Span,
90 pub method_name: Symbol,
91}
92
93#[derive(Subdiagnostic)]
94#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
95pub(crate) struct ImplicitUnsafeAutorefsSuggestion {
96 pub mutbl: &'static str,
97 pub deref: &'static str,
98 #[suggestion_part(code = "({mutbl}{deref}")]
99 pub start_span: Span,
100 #[suggestion_part(code = ")")]
101 pub end_span: Span,
102}
103
104#[derive(LintDiagnostic)]
106#[diag(lint_builtin_while_true)]
107pub(crate) struct BuiltinWhileTrue {
108 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
109 pub suggestion: Span,
110 pub replace: String,
111}
112
113#[derive(LintDiagnostic)]
114#[diag(lint_builtin_non_shorthand_field_patterns)]
115pub(crate) struct BuiltinNonShorthandFieldPatterns {
116 pub ident: Ident,
117 #[suggestion(code = "{prefix}{ident}", applicability = "machine-applicable")]
118 pub suggestion: Span,
119 pub prefix: &'static str,
120}
121
122#[derive(LintDiagnostic)]
123pub(crate) enum BuiltinUnsafe {
124 #[diag(lint_builtin_allow_internal_unsafe)]
125 AllowInternalUnsafe,
126 #[diag(lint_builtin_unsafe_block)]
127 UnsafeBlock,
128 #[diag(lint_builtin_unsafe_extern_block)]
129 UnsafeExternBlock,
130 #[diag(lint_builtin_unsafe_trait)]
131 UnsafeTrait,
132 #[diag(lint_builtin_unsafe_impl)]
133 UnsafeImpl,
134 #[diag(lint_builtin_no_mangle_fn)]
135 #[note(lint_builtin_overridden_symbol_name)]
136 NoMangleFn,
137 #[diag(lint_builtin_export_name_fn)]
138 #[note(lint_builtin_overridden_symbol_name)]
139 ExportNameFn,
140 #[diag(lint_builtin_link_section_fn)]
141 #[note(lint_builtin_overridden_symbol_section)]
142 LinkSectionFn,
143 #[diag(lint_builtin_no_mangle_static)]
144 #[note(lint_builtin_overridden_symbol_name)]
145 NoMangleStatic,
146 #[diag(lint_builtin_export_name_static)]
147 #[note(lint_builtin_overridden_symbol_name)]
148 ExportNameStatic,
149 #[diag(lint_builtin_link_section_static)]
150 #[note(lint_builtin_overridden_symbol_section)]
151 LinkSectionStatic,
152 #[diag(lint_builtin_no_mangle_method)]
153 #[note(lint_builtin_overridden_symbol_name)]
154 NoMangleMethod,
155 #[diag(lint_builtin_export_name_method)]
156 #[note(lint_builtin_overridden_symbol_name)]
157 ExportNameMethod,
158 #[diag(lint_builtin_decl_unsafe_fn)]
159 DeclUnsafeFn,
160 #[diag(lint_builtin_decl_unsafe_method)]
161 DeclUnsafeMethod,
162 #[diag(lint_builtin_impl_unsafe_method)]
163 ImplUnsafeMethod,
164 #[diag(lint_builtin_global_asm)]
165 #[note(lint_builtin_global_macro_unsafety)]
166 GlobalAsm,
167}
168
169#[derive(LintDiagnostic)]
170#[diag(lint_builtin_missing_doc)]
171pub(crate) struct BuiltinMissingDoc<'a> {
172 pub article: &'a str,
173 pub desc: &'a str,
174}
175
176#[derive(LintDiagnostic)]
177#[diag(lint_builtin_missing_copy_impl)]
178pub(crate) struct BuiltinMissingCopyImpl;
179
180pub(crate) struct BuiltinMissingDebugImpl<'a> {
181 pub tcx: TyCtxt<'a>,
182 pub def_id: DefId,
183}
184
185impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
187 fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
188 diag.primary_message(fluent::lint_builtin_missing_debug_impl);
189 diag.arg("debug", self.tcx.def_path_str(self.def_id));
190 }
191}
192
193#[derive(LintDiagnostic)]
194#[diag(lint_builtin_anonymous_params)]
195pub(crate) struct BuiltinAnonymousParams<'a> {
196 #[suggestion(code = "_: {ty_snip}")]
197 pub suggestion: (Span, Applicability),
198 pub ty_snip: &'a str,
199}
200
201#[derive(LintDiagnostic)]
202#[diag(lint_builtin_unused_doc_comment)]
203pub(crate) struct BuiltinUnusedDocComment<'a> {
204 pub kind: &'a str,
205 #[label]
206 pub label: Span,
207 #[subdiagnostic]
208 pub sub: BuiltinUnusedDocCommentSub,
209}
210
211#[derive(Subdiagnostic)]
212pub(crate) enum BuiltinUnusedDocCommentSub {
213 #[help(lint_plain_help)]
214 PlainHelp,
215 #[help(lint_block_help)]
216 BlockHelp,
217}
218
219#[derive(LintDiagnostic)]
220#[diag(lint_builtin_no_mangle_generic)]
221pub(crate) struct BuiltinNoMangleGeneric {
222 #[suggestion(style = "short", code = "", applicability = "maybe-incorrect")]
225 pub suggestion: Span,
226}
227
228#[derive(LintDiagnostic)]
229#[diag(lint_builtin_const_no_mangle)]
230pub(crate) struct BuiltinConstNoMangle {
231 #[suggestion(code = "pub static ", applicability = "machine-applicable")]
232 pub suggestion: Option<Span>,
233}
234
235#[derive(LintDiagnostic)]
236#[diag(lint_builtin_mutable_transmutes)]
237pub(crate) struct BuiltinMutablesTransmutes;
238
239#[derive(LintDiagnostic)]
240#[diag(lint_builtin_unstable_features)]
241pub(crate) struct BuiltinUnstableFeatures;
242
243pub(crate) struct BuiltinUngatedAsyncFnTrackCaller<'a> {
245 pub label: Span,
246 pub session: &'a Session,
247}
248
249impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
250 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
251 diag.primary_message(fluent::lint_ungated_async_fn_track_caller);
252 diag.span_label(self.label, fluent::lint_label);
253 rustc_session::parse::add_feature_diagnostics(
254 diag,
255 self.session,
256 sym::async_fn_track_caller,
257 );
258 }
259}
260
261#[derive(LintDiagnostic)]
262#[diag(lint_builtin_unreachable_pub)]
263pub(crate) struct BuiltinUnreachablePub<'a> {
264 pub what: &'a str,
265 pub new_vis: &'a str,
266 #[suggestion(code = "{new_vis}")]
267 pub suggestion: (Span, Applicability),
268 #[help]
269 pub help: bool,
270}
271
272#[derive(LintDiagnostic)]
273#[diag(lint_macro_expr_fragment_specifier_2024_migration)]
274pub(crate) struct MacroExprFragment2024 {
275 #[suggestion(code = "expr_2021", applicability = "machine-applicable")]
276 pub suggestion: Span,
277}
278
279pub(crate) struct BuiltinTypeAliasBounds<'hir> {
280 pub in_where_clause: bool,
281 pub label: Span,
282 pub enable_feat_help: bool,
283 pub suggestions: Vec<(Span, String)>,
284 pub preds: &'hir [hir::WherePredicate<'hir>],
285 pub ty: Option<&'hir hir::Ty<'hir>>,
286}
287
288impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
289 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
290 diag.primary_message(if self.in_where_clause {
291 fluent::lint_builtin_type_alias_bounds_where_clause
292 } else {
293 fluent::lint_builtin_type_alias_bounds_param_bounds
294 });
295 diag.span_label(self.label, fluent::lint_builtin_type_alias_bounds_label);
296 diag.note(fluent::lint_builtin_type_alias_bounds_limitation_note);
297 if self.enable_feat_help {
298 diag.help(fluent::lint_builtin_type_alias_bounds_enable_feat_help);
299 }
300
301 let mut collector = ShorthandAssocTyCollector { qselves: Vec::new() };
304 if let Some(ty) = self.ty {
305 collector.visit_ty_unambig(ty);
306 }
307
308 let affect_object_lifetime_defaults = self
309 .preds
310 .iter()
311 .filter(|pred| pred.kind.in_where_clause() == self.in_where_clause)
312 .any(|pred| TypeAliasBounds::affects_object_lifetime_defaults(pred));
313
314 let applicability = if !collector.qselves.is_empty() || affect_object_lifetime_defaults {
317 Applicability::MaybeIncorrect
318 } else {
319 Applicability::MachineApplicable
320 };
321
322 diag.arg("count", self.suggestions.len());
323 diag.multipart_suggestion(fluent::lint_suggestion, self.suggestions, applicability);
324
325 for qself in collector.qselves {
336 diag.multipart_suggestion(
337 fluent::lint_builtin_type_alias_bounds_qualify_assoc_tys_sugg,
338 vec![
339 (qself.shrink_to_lo(), "<".into()),
340 (qself.shrink_to_hi(), " as /* Trait */>".into()),
341 ],
342 Applicability::HasPlaceholders,
343 );
344 }
345 }
346}
347
348#[derive(LintDiagnostic)]
349#[diag(lint_builtin_trivial_bounds)]
350pub(crate) struct BuiltinTrivialBounds<'a> {
351 pub predicate_kind_name: &'a str,
352 pub predicate: Clause<'a>,
353}
354
355#[derive(LintDiagnostic)]
356#[diag(lint_builtin_double_negations)]
357#[note(lint_note)]
358#[note(lint_note_decrement)]
359pub(crate) struct BuiltinDoubleNegations {
360 #[subdiagnostic]
361 pub add_parens: BuiltinDoubleNegationsAddParens,
362}
363
364#[derive(Subdiagnostic)]
365#[multipart_suggestion(lint_add_parens_suggestion, applicability = "maybe-incorrect")]
366pub(crate) struct BuiltinDoubleNegationsAddParens {
367 #[suggestion_part(code = "(")]
368 pub start_span: Span,
369 #[suggestion_part(code = ")")]
370 pub end_span: Span,
371}
372
373#[derive(LintDiagnostic)]
374pub(crate) enum BuiltinEllipsisInclusiveRangePatternsLint {
375 #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
376 Parenthesise {
377 #[suggestion(code = "{replace}", applicability = "machine-applicable")]
378 suggestion: Span,
379 replace: String,
380 },
381 #[diag(lint_builtin_ellipsis_inclusive_range_patterns)]
382 NonParenthesise {
383 #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")]
384 suggestion: Span,
385 },
386}
387
388#[derive(LintDiagnostic)]
389#[diag(lint_builtin_keyword_idents)]
390pub(crate) struct BuiltinKeywordIdents {
391 pub kw: Ident,
392 pub next: Edition,
393 #[suggestion(code = "{prefix}r#{kw}", applicability = "machine-applicable")]
394 pub suggestion: Span,
395 pub prefix: &'static str,
396}
397
398#[derive(LintDiagnostic)]
399#[diag(lint_builtin_explicit_outlives)]
400pub(crate) struct BuiltinExplicitOutlives {
401 pub count: usize,
402 #[subdiagnostic]
403 pub suggestion: BuiltinExplicitOutlivesSuggestion,
404}
405
406#[derive(Subdiagnostic)]
407#[multipart_suggestion(lint_suggestion)]
408pub(crate) struct BuiltinExplicitOutlivesSuggestion {
409 #[suggestion_part(code = "")]
410 pub spans: Vec<Span>,
411 #[applicability]
412 pub applicability: Applicability,
413}
414
415#[derive(LintDiagnostic)]
416#[diag(lint_builtin_incomplete_features)]
417pub(crate) struct BuiltinIncompleteFeatures {
418 pub name: Symbol,
419 #[subdiagnostic]
420 pub note: Option<BuiltinFeatureIssueNote>,
421 #[subdiagnostic]
422 pub help: Option<BuiltinIncompleteFeaturesHelp>,
423}
424
425#[derive(LintDiagnostic)]
426#[diag(lint_builtin_internal_features)]
427#[note]
428pub(crate) struct BuiltinInternalFeatures {
429 pub name: Symbol,
430}
431
432#[derive(Subdiagnostic)]
433#[help(lint_help)]
434pub(crate) struct BuiltinIncompleteFeaturesHelp;
435
436#[derive(Subdiagnostic)]
437#[note(lint_note)]
438pub(crate) struct BuiltinFeatureIssueNote {
439 pub n: NonZero<u32>,
440}
441
442pub(crate) struct BuiltinUnpermittedTypeInit<'a> {
443 pub msg: DiagMessage,
444 pub ty: Ty<'a>,
445 pub label: Span,
446 pub sub: BuiltinUnpermittedTypeInitSub,
447 pub tcx: TyCtxt<'a>,
448}
449
450impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
451 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
452 diag.primary_message(self.msg);
453 diag.arg("ty", self.ty);
454 diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
455 if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
456 diag.span_label(
458 self.label,
459 fluent::lint_builtin_unpermitted_type_init_label_suggestion,
460 );
461 }
462 self.sub.add_to_diag(diag);
463 }
464}
465
466pub(crate) struct BuiltinUnpermittedTypeInitSub {
468 pub err: InitError,
469}
470
471impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
472 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
473 let mut err = self.err;
474 loop {
475 if let Some(span) = err.span {
476 diag.span_note(span, err.message);
477 } else {
478 diag.note(err.message);
479 }
480 if let Some(e) = err.nested {
481 err = *e;
482 } else {
483 break;
484 }
485 }
486 }
487}
488
489#[derive(LintDiagnostic)]
490pub(crate) enum BuiltinClashingExtern<'a> {
491 #[diag(lint_builtin_clashing_extern_same_name)]
492 SameName {
493 this: Symbol,
494 orig: Symbol,
495 #[label(lint_previous_decl_label)]
496 previous_decl_label: Span,
497 #[label(lint_mismatch_label)]
498 mismatch_label: Span,
499 #[subdiagnostic]
500 sub: BuiltinClashingExternSub<'a>,
501 },
502 #[diag(lint_builtin_clashing_extern_diff_name)]
503 DiffName {
504 this: Symbol,
505 orig: Symbol,
506 #[label(lint_previous_decl_label)]
507 previous_decl_label: Span,
508 #[label(lint_mismatch_label)]
509 mismatch_label: Span,
510 #[subdiagnostic]
511 sub: BuiltinClashingExternSub<'a>,
512 },
513}
514
515pub(crate) struct BuiltinClashingExternSub<'a> {
517 pub tcx: TyCtxt<'a>,
518 pub expected: Ty<'a>,
519 pub found: Ty<'a>,
520}
521
522impl Subdiagnostic for BuiltinClashingExternSub<'_> {
523 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
524 let mut expected_str = DiagStyledString::new();
525 expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false);
526 let mut found_str = DiagStyledString::new();
527 found_str.push(self.found.fn_sig(self.tcx).to_string(), true);
528 diag.note_expected_found("", expected_str, "", found_str);
529 }
530}
531
532#[derive(LintDiagnostic)]
533#[diag(lint_builtin_deref_nullptr)]
534pub(crate) struct BuiltinDerefNullptr {
535 #[label]
536 pub label: Span,
537}
538
539#[derive(LintDiagnostic)]
542pub(crate) enum BuiltinSpecialModuleNameUsed {
543 #[diag(lint_builtin_special_module_name_used_lib)]
544 #[note]
545 #[help]
546 Lib,
547 #[diag(lint_builtin_special_module_name_used_main)]
548 #[note]
549 Main,
550}
551
552#[derive(LintDiagnostic)]
554#[diag(lint_supertrait_as_deref_target)]
555pub(crate) struct SupertraitAsDerefTarget<'a> {
556 pub self_ty: Ty<'a>,
557 pub supertrait_principal: PolyExistentialTraitRef<'a>,
558 pub target_principal: PolyExistentialTraitRef<'a>,
559 #[label]
560 pub label: Span,
561 #[subdiagnostic]
562 pub label2: Option<SupertraitAsDerefTargetLabel>,
563}
564
565#[derive(Subdiagnostic)]
566#[label(lint_label2)]
567pub(crate) struct SupertraitAsDerefTargetLabel {
568 #[primary_span]
569 pub label: Span,
570}
571
572#[derive(LintDiagnostic)]
574#[diag(lint_enum_intrinsics_mem_discriminant)]
575pub(crate) struct EnumIntrinsicsMemDiscriminate<'a> {
576 pub ty_param: Ty<'a>,
577 #[note]
578 pub note: Span,
579}
580
581#[derive(LintDiagnostic)]
582#[diag(lint_enum_intrinsics_mem_variant)]
583#[note]
584pub(crate) struct EnumIntrinsicsMemVariant<'a> {
585 pub ty_param: Ty<'a>,
586}
587
588#[derive(LintDiagnostic)]
590#[diag(lint_expectation)]
591pub(crate) struct Expectation {
592 #[subdiagnostic]
593 pub rationale: Option<ExpectationNote>,
594 #[note]
595 pub note: bool,
596}
597
598#[derive(Subdiagnostic)]
599#[note(lint_rationale)]
600pub(crate) struct ExpectationNote {
601 pub rationale: Symbol,
602}
603
604#[derive(LintDiagnostic)]
606pub(crate) enum UselessPtrNullChecksDiag<'a> {
607 #[diag(lint_useless_ptr_null_checks_fn_ptr)]
608 #[help]
609 FnPtr {
610 orig_ty: Ty<'a>,
611 #[label]
612 label: Span,
613 },
614 #[diag(lint_useless_ptr_null_checks_ref)]
615 Ref {
616 orig_ty: Ty<'a>,
617 #[label]
618 label: Span,
619 },
620 #[diag(lint_useless_ptr_null_checks_fn_ret)]
621 FnRet { fn_name: Ident },
622}
623
624#[derive(LintDiagnostic)]
625pub(crate) enum InvalidNullArgumentsDiag {
626 #[diag(lint_invalid_null_arguments)]
627 #[help(lint_doc)]
628 NullPtrInline {
629 #[label(lint_origin)]
630 null_span: Span,
631 },
632 #[diag(lint_invalid_null_arguments)]
633 #[help(lint_doc)]
634 NullPtrThroughBinding {
635 #[note(lint_origin)]
636 null_span: Span,
637 },
638}
639
640#[derive(LintDiagnostic)]
642#[diag(lint_for_loops_over_fallibles)]
643pub(crate) struct ForLoopsOverFalliblesDiag<'a> {
644 pub article: &'static str,
645 pub ref_prefix: &'static str,
646 pub ty: &'static str,
647 #[subdiagnostic]
648 pub sub: ForLoopsOverFalliblesLoopSub<'a>,
649 #[subdiagnostic]
650 pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>,
651 #[subdiagnostic]
652 pub suggestion: ForLoopsOverFalliblesSuggestion<'a>,
653}
654
655#[derive(Subdiagnostic)]
656pub(crate) enum ForLoopsOverFalliblesLoopSub<'a> {
657 #[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")]
658 RemoveNext {
659 #[primary_span]
660 suggestion: Span,
661 recv_snip: String,
662 },
663 #[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")]
664 UseWhileLet {
665 #[suggestion_part(code = "while let {var}(")]
666 start_span: Span,
667 #[suggestion_part(code = ") = ")]
668 end_span: Span,
669 var: &'a str,
670 },
671}
672
673#[derive(Subdiagnostic)]
674#[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")]
675pub(crate) struct ForLoopsOverFalliblesQuestionMark {
676 #[primary_span]
677 pub suggestion: Span,
678}
679
680#[derive(Subdiagnostic)]
681#[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")]
682pub(crate) struct ForLoopsOverFalliblesSuggestion<'a> {
683 pub var: &'a str,
684 #[suggestion_part(code = "if let {var}(")]
685 pub start_span: Span,
686 #[suggestion_part(code = ") = ")]
687 pub end_span: Span,
688}
689
690#[derive(Subdiagnostic)]
691pub(crate) enum UseLetUnderscoreIgnoreSuggestion {
692 #[note(lint_use_let_underscore_ignore_suggestion)]
693 Note,
694 #[multipart_suggestion(
695 lint_use_let_underscore_ignore_suggestion,
696 style = "verbose",
697 applicability = "maybe-incorrect"
698 )]
699 Suggestion {
700 #[suggestion_part(code = "let _ = ")]
701 start_span: Span,
702 #[suggestion_part(code = "")]
703 end_span: Span,
704 },
705}
706
707#[derive(LintDiagnostic)]
709#[diag(lint_dropping_references)]
710pub(crate) struct DropRefDiag<'a> {
711 pub arg_ty: Ty<'a>,
712 #[label]
713 pub label: Span,
714 #[subdiagnostic]
715 pub sugg: UseLetUnderscoreIgnoreSuggestion,
716}
717
718#[derive(LintDiagnostic)]
719#[diag(lint_dropping_copy_types)]
720pub(crate) struct DropCopyDiag<'a> {
721 pub arg_ty: Ty<'a>,
722 #[label]
723 pub label: Span,
724 #[subdiagnostic]
725 pub sugg: UseLetUnderscoreIgnoreSuggestion,
726}
727
728#[derive(LintDiagnostic)]
729#[diag(lint_forgetting_references)]
730pub(crate) struct ForgetRefDiag<'a> {
731 pub arg_ty: Ty<'a>,
732 #[label]
733 pub label: Span,
734 #[subdiagnostic]
735 pub sugg: UseLetUnderscoreIgnoreSuggestion,
736}
737
738#[derive(LintDiagnostic)]
739#[diag(lint_forgetting_copy_types)]
740pub(crate) struct ForgetCopyDiag<'a> {
741 pub arg_ty: Ty<'a>,
742 #[label]
743 pub label: Span,
744 #[subdiagnostic]
745 pub sugg: UseLetUnderscoreIgnoreSuggestion,
746}
747
748#[derive(LintDiagnostic)]
749#[diag(lint_undropped_manually_drops)]
750pub(crate) struct UndroppedManuallyDropsDiag<'a> {
751 pub arg_ty: Ty<'a>,
752 #[label]
753 pub label: Span,
754 #[subdiagnostic]
755 pub suggestion: UndroppedManuallyDropsSuggestion,
756}
757
758#[derive(Subdiagnostic)]
759#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
760pub(crate) struct UndroppedManuallyDropsSuggestion {
761 #[suggestion_part(code = "std::mem::ManuallyDrop::into_inner(")]
762 pub start_span: Span,
763 #[suggestion_part(code = ")")]
764 pub end_span: Span,
765}
766
767#[derive(LintDiagnostic)]
769pub(crate) enum InvalidFromUtf8Diag {
770 #[diag(lint_invalid_from_utf8_unchecked)]
771 Unchecked {
772 method: String,
773 valid_up_to: usize,
774 #[label]
775 label: Span,
776 },
777 #[diag(lint_invalid_from_utf8_checked)]
778 Checked {
779 method: String,
780 valid_up_to: usize,
781 #[label]
782 label: Span,
783 },
784}
785
786#[derive(LintDiagnostic)]
788#[diag(lint_const_item_interior_mutations)]
789#[note(lint_temporary)]
790#[note(lint_never_original)]
791#[help]
792pub(crate) struct ConstItemInteriorMutationsDiag<'tcx> {
793 pub method_name: Ident,
794 pub const_name: Ident,
795 pub const_ty: Ty<'tcx>,
796 #[label]
797 pub receiver_span: Span,
798 #[subdiagnostic]
799 pub sugg_static: Option<ConstItemInteriorMutationsSuggestionStatic>,
800}
801
802#[derive(Subdiagnostic)]
803pub(crate) enum ConstItemInteriorMutationsSuggestionStatic {
804 #[suggestion(
805 lint_suggestion_static,
806 code = "{before}static ",
807 style = "verbose",
808 applicability = "maybe-incorrect"
809 )]
810 Spanful {
811 #[primary_span]
812 const_: Span,
813 before: &'static str,
814 },
815 #[help(lint_suggestion_static)]
816 Spanless,
817}
818
819#[derive(LintDiagnostic)]
821pub(crate) enum InvalidReferenceCastingDiag<'tcx> {
822 #[diag(lint_invalid_reference_casting_borrow_as_mut)]
823 #[note(lint_invalid_reference_casting_note_book)]
824 BorrowAsMut {
825 #[label]
826 orig_cast: Option<Span>,
827 #[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
828 ty_has_interior_mutability: bool,
829 },
830 #[diag(lint_invalid_reference_casting_assign_to_ref)]
831 #[note(lint_invalid_reference_casting_note_book)]
832 AssignToRef {
833 #[label]
834 orig_cast: Option<Span>,
835 #[note(lint_invalid_reference_casting_note_ty_has_interior_mutability)]
836 ty_has_interior_mutability: bool,
837 },
838 #[diag(lint_invalid_reference_casting_bigger_layout)]
839 #[note(lint_layout)]
840 BiggerLayout {
841 #[label]
842 orig_cast: Option<Span>,
843 #[label(lint_alloc)]
844 alloc: Span,
845 from_ty: Ty<'tcx>,
846 from_size: u64,
847 to_ty: Ty<'tcx>,
848 to_size: u64,
849 },
850}
851
852#[derive(LintDiagnostic)]
854#[diag(lint_map_unit_fn)]
855#[note]
856pub(crate) struct MappingToUnit {
857 #[label(lint_function_label)]
858 pub function_label: Span,
859 #[label(lint_argument_label)]
860 pub argument_label: Span,
861 #[label(lint_map_label)]
862 pub map_label: Span,
863 #[suggestion(style = "verbose", code = "for_each", applicability = "maybe-incorrect")]
864 pub suggestion: Span,
865}
866
867#[derive(LintDiagnostic)]
869#[diag(lint_default_hash_types)]
870#[note]
871pub(crate) struct DefaultHashTypesDiag<'a> {
872 pub preferred: &'a str,
873 pub used: Symbol,
874}
875
876#[derive(LintDiagnostic)]
877#[diag(lint_query_instability)]
878#[note]
879pub(crate) struct QueryInstability {
880 pub query: Symbol,
881}
882
883#[derive(LintDiagnostic)]
884#[diag(lint_query_untracked)]
885#[note]
886pub(crate) struct QueryUntracked {
887 pub method: Symbol,
888}
889
890#[derive(LintDiagnostic)]
891#[diag(lint_span_use_eq_ctxt)]
892pub(crate) struct SpanUseEqCtxtDiag;
893
894#[derive(LintDiagnostic)]
895#[diag(lint_symbol_intern_string_literal)]
896#[help]
897pub(crate) struct SymbolInternStringLiteralDiag;
898
899#[derive(LintDiagnostic)]
900#[diag(lint_tykind_kind)]
901pub(crate) struct TykindKind {
902 #[suggestion(code = "ty", applicability = "maybe-incorrect")]
903 pub suggestion: Span,
904}
905
906#[derive(LintDiagnostic)]
907#[diag(lint_tykind)]
908#[help]
909pub(crate) struct TykindDiag;
910
911#[derive(LintDiagnostic)]
912#[diag(lint_ty_qualified)]
913pub(crate) struct TyQualified {
914 pub ty: String,
915 #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
916 pub suggestion: Span,
917}
918
919#[derive(LintDiagnostic)]
920#[diag(lint_type_ir_inherent_usage)]
921#[note]
922pub(crate) struct TypeIrInherentUsage;
923
924#[derive(LintDiagnostic)]
925#[diag(lint_type_ir_trait_usage)]
926#[note]
927pub(crate) struct TypeIrTraitUsage;
928
929#[derive(LintDiagnostic)]
930#[diag(lint_type_ir_direct_use)]
931#[note]
932pub(crate) struct TypeIrDirectUse;
933
934#[derive(LintDiagnostic)]
935#[diag(lint_non_glob_import_type_ir_inherent)]
936pub(crate) struct NonGlobImportTypeIrInherent {
937 #[suggestion(code = "{snippet}", applicability = "maybe-incorrect")]
938 pub suggestion: Option<Span>,
939 pub snippet: &'static str,
940}
941
942#[derive(LintDiagnostic)]
943#[diag(lint_lintpass_by_hand)]
944#[help]
945pub(crate) struct LintPassByHand;
946
947#[derive(LintDiagnostic)]
948#[diag(lint_diag_out_of_impl)]
949pub(crate) struct DiagOutOfImpl;
950
951#[derive(LintDiagnostic)]
952#[diag(lint_untranslatable_diag)]
953pub(crate) struct UntranslatableDiag;
954
955#[derive(LintDiagnostic)]
956#[diag(lint_bad_opt_access)]
957pub(crate) struct BadOptAccessDiag<'a> {
958 pub msg: &'a str,
959}
960
961#[derive(LintDiagnostic)]
962#[diag(lint_implicit_sysroot_crate_import)]
963#[help]
964pub(crate) struct ImplicitSysrootCrateImportDiag<'a> {
965 pub name: &'a str,
966}
967
968#[derive(LintDiagnostic)]
970pub(crate) enum NonBindingLet {
971 #[diag(lint_non_binding_let_on_sync_lock)]
972 SyncLock {
973 #[label]
974 pat: Span,
975 #[subdiagnostic]
976 sub: NonBindingLetSub,
977 },
978 #[diag(lint_non_binding_let_on_drop_type)]
979 DropType {
980 #[subdiagnostic]
981 sub: NonBindingLetSub,
982 },
983}
984
985pub(crate) struct NonBindingLetSub {
986 pub suggestion: Span,
987 pub drop_fn_start_end: Option<(Span, Span)>,
988 pub is_assign_desugar: bool,
989}
990
991impl Subdiagnostic for NonBindingLetSub {
992 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
993 let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
994
995 if can_suggest_binding {
996 let prefix = if self.is_assign_desugar { "let " } else { "" };
997 diag.span_suggestion_verbose(
998 self.suggestion,
999 fluent::lint_non_binding_let_suggestion,
1000 format!("{prefix}_unused"),
1001 Applicability::MachineApplicable,
1002 );
1003 } else {
1004 diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion);
1005 }
1006 if let Some(drop_fn_start_end) = self.drop_fn_start_end {
1007 diag.multipart_suggestion(
1008 fluent::lint_non_binding_let_multi_suggestion,
1009 vec![
1010 (drop_fn_start_end.0, "drop(".to_string()),
1011 (drop_fn_start_end.1, ")".to_string()),
1012 ],
1013 Applicability::MachineApplicable,
1014 );
1015 } else {
1016 diag.help(fluent::lint_non_binding_let_multi_drop_fn);
1017 }
1018 }
1019}
1020
1021#[derive(LintDiagnostic)]
1023#[diag(lint_overruled_attribute)]
1024pub(crate) struct OverruledAttributeLint<'a> {
1025 #[label]
1026 pub overruled: Span,
1027 pub lint_level: &'a str,
1028 pub lint_source: Symbol,
1029 #[subdiagnostic]
1030 pub sub: OverruledAttributeSub,
1031}
1032
1033#[derive(LintDiagnostic)]
1034#[diag(lint_deprecated_lint_name)]
1035pub(crate) struct DeprecatedLintName<'a> {
1036 pub name: String,
1037 #[suggestion(code = "{replace}", applicability = "machine-applicable")]
1038 pub suggestion: Span,
1039 pub replace: &'a str,
1040}
1041
1042#[derive(LintDiagnostic)]
1043#[diag(lint_deprecated_lint_name)]
1044#[help]
1045pub(crate) struct DeprecatedLintNameFromCommandLine<'a> {
1046 pub name: String,
1047 pub replace: &'a str,
1048 #[subdiagnostic]
1049 pub requested_level: RequestedLevel<'a>,
1050}
1051
1052#[derive(LintDiagnostic)]
1053#[diag(lint_renamed_lint)]
1054pub(crate) struct RenamedLint<'a> {
1055 pub name: &'a str,
1056 pub replace: &'a str,
1057 #[subdiagnostic]
1058 pub suggestion: RenamedLintSuggestion<'a>,
1059}
1060
1061#[derive(Subdiagnostic)]
1062pub(crate) enum RenamedLintSuggestion<'a> {
1063 #[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
1064 WithSpan {
1065 #[primary_span]
1066 suggestion: Span,
1067 replace: &'a str,
1068 },
1069 #[help(lint_help)]
1070 WithoutSpan { replace: &'a str },
1071}
1072
1073#[derive(LintDiagnostic)]
1074#[diag(lint_renamed_lint)]
1075pub(crate) struct RenamedLintFromCommandLine<'a> {
1076 pub name: &'a str,
1077 pub replace: &'a str,
1078 #[subdiagnostic]
1079 pub suggestion: RenamedLintSuggestion<'a>,
1080 #[subdiagnostic]
1081 pub requested_level: RequestedLevel<'a>,
1082}
1083
1084#[derive(LintDiagnostic)]
1085#[diag(lint_removed_lint)]
1086pub(crate) struct RemovedLint<'a> {
1087 pub name: &'a str,
1088 pub reason: &'a str,
1089}
1090
1091#[derive(LintDiagnostic)]
1092#[diag(lint_removed_lint)]
1093pub(crate) struct RemovedLintFromCommandLine<'a> {
1094 pub name: &'a str,
1095 pub reason: &'a str,
1096 #[subdiagnostic]
1097 pub requested_level: RequestedLevel<'a>,
1098}
1099
1100#[derive(LintDiagnostic)]
1101#[diag(lint_unknown_lint)]
1102pub(crate) struct UnknownLint {
1103 pub name: String,
1104 #[subdiagnostic]
1105 pub suggestion: Option<UnknownLintSuggestion>,
1106}
1107
1108#[derive(Subdiagnostic)]
1109pub(crate) enum UnknownLintSuggestion {
1110 #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1111 WithSpan {
1112 #[primary_span]
1113 suggestion: Span,
1114 replace: Symbol,
1115 from_rustc: bool,
1116 },
1117 #[help(lint_help)]
1118 WithoutSpan { replace: Symbol, from_rustc: bool },
1119}
1120
1121#[derive(LintDiagnostic)]
1122#[diag(lint_unknown_lint, code = E0602)]
1123pub(crate) struct UnknownLintFromCommandLine<'a> {
1124 pub name: String,
1125 #[subdiagnostic]
1126 pub suggestion: Option<UnknownLintSuggestion>,
1127 #[subdiagnostic]
1128 pub requested_level: RequestedLevel<'a>,
1129}
1130
1131#[derive(LintDiagnostic)]
1132#[diag(lint_ignored_unless_crate_specified)]
1133pub(crate) struct IgnoredUnlessCrateSpecified<'a> {
1134 pub level: &'a str,
1135 pub name: Symbol,
1136}
1137
1138#[derive(LintDiagnostic)]
1140#[diag(lint_dangling_pointers_from_temporaries)]
1141#[help(lint_help_bind)]
1142#[note(lint_note_safe)]
1143#[note(lint_note_return)]
1144#[note(lint_note_more_info)]
1145pub(crate) struct DanglingPointersFromTemporaries<'tcx> {
1147 pub callee: Ident,
1148 pub ty: Ty<'tcx>,
1149 #[label(lint_label_ptr)]
1150 pub ptr_span: Span,
1151 #[label(lint_label_temporary)]
1152 pub temporary_span: Span,
1153}
1154
1155#[derive(LintDiagnostic)]
1156#[diag(lint_dangling_pointers_from_locals)]
1157#[note(lint_note_safe)]
1158#[note(lint_note_more_info)]
1159pub(crate) struct DanglingPointersFromLocals<'tcx> {
1160 pub ret_ty: Ty<'tcx>,
1161 #[label(lint_ret_ty)]
1162 pub ret_ty_span: Span,
1163 pub fn_kind: &'static str,
1164 #[label(lint_local_var)]
1165 pub local_var: Span,
1166 pub local_var_name: Ident,
1167 pub local_var_ty: Ty<'tcx>,
1168 #[label(lint_created_at)]
1169 pub created_at: Option<Span>,
1170}
1171
1172#[derive(LintDiagnostic)]
1174#[diag(lint_multiple_supertrait_upcastable)]
1175pub(crate) struct MultipleSupertraitUpcastable {
1176 pub ident: Ident,
1177}
1178
1179#[derive(LintDiagnostic)]
1181#[diag(lint_identifier_non_ascii_char)]
1182pub(crate) struct IdentifierNonAsciiChar;
1183
1184#[derive(LintDiagnostic)]
1185#[diag(lint_identifier_uncommon_codepoints)]
1186#[note]
1187pub(crate) struct IdentifierUncommonCodepoints {
1188 pub codepoints: Vec<char>,
1189 pub codepoints_len: usize,
1190 pub identifier_type: &'static str,
1191}
1192
1193#[derive(LintDiagnostic)]
1194#[diag(lint_confusable_identifier_pair)]
1195pub(crate) struct ConfusableIdentifierPair {
1196 pub existing_sym: Symbol,
1197 pub sym: Symbol,
1198 #[label(lint_other_use)]
1199 pub label: Span,
1200 #[label(lint_current_use)]
1201 pub main_label: Span,
1202}
1203
1204#[derive(LintDiagnostic)]
1205#[diag(lint_mixed_script_confusables)]
1206#[note(lint_includes_note)]
1207#[note]
1208pub(crate) struct MixedScriptConfusables {
1209 pub set: String,
1210 pub includes: String,
1211}
1212
1213pub(crate) struct NonFmtPanicUnused {
1215 pub count: usize,
1216 pub suggestion: Option<Span>,
1217}
1218
1219impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
1221 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1222 diag.primary_message(fluent::lint_non_fmt_panic_unused);
1223 diag.arg("count", self.count);
1224 diag.note(fluent::lint_note);
1225 if let Some(span) = self.suggestion {
1226 diag.span_suggestion(
1227 span.shrink_to_hi(),
1228 fluent::lint_add_args_suggestion,
1229 ", ...",
1230 Applicability::HasPlaceholders,
1231 );
1232 diag.span_suggestion(
1233 span.shrink_to_lo(),
1234 fluent::lint_add_fmt_suggestion,
1235 "\"{}\", ",
1236 Applicability::MachineApplicable,
1237 );
1238 }
1239 }
1240}
1241
1242#[derive(LintDiagnostic)]
1243#[diag(lint_non_fmt_panic_braces)]
1244#[note]
1245pub(crate) struct NonFmtPanicBraces {
1246 pub count: usize,
1247 #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")]
1248 pub suggestion: Option<Span>,
1249}
1250
1251#[derive(LintDiagnostic)]
1253#[diag(lint_non_camel_case_type)]
1254pub(crate) struct NonCamelCaseType<'a> {
1255 pub sort: &'a str,
1256 pub name: &'a str,
1257 #[subdiagnostic]
1258 pub sub: NonCamelCaseTypeSub,
1259}
1260
1261#[derive(Subdiagnostic)]
1262pub(crate) enum NonCamelCaseTypeSub {
1263 #[label(lint_label)]
1264 Label {
1265 #[primary_span]
1266 span: Span,
1267 },
1268 #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")]
1269 Suggestion {
1270 #[primary_span]
1271 span: Span,
1272 replace: String,
1273 },
1274}
1275
1276#[derive(LintDiagnostic)]
1277#[diag(lint_non_snake_case)]
1278pub(crate) struct NonSnakeCaseDiag<'a> {
1279 pub sort: &'a str,
1280 pub name: &'a str,
1281 pub sc: String,
1282 #[subdiagnostic]
1283 pub sub: NonSnakeCaseDiagSub,
1284}
1285
1286pub(crate) enum NonSnakeCaseDiagSub {
1287 Label { span: Span },
1288 Help,
1289 RenameOrConvertSuggestion { span: Span, suggestion: Ident },
1290 ConvertSuggestion { span: Span, suggestion: String },
1291 SuggestionAndNote { span: Span },
1292}
1293
1294impl Subdiagnostic for NonSnakeCaseDiagSub {
1295 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1296 match self {
1297 NonSnakeCaseDiagSub::Label { span } => {
1298 diag.span_label(span, fluent::lint_label);
1299 }
1300 NonSnakeCaseDiagSub::Help => {
1301 diag.help(fluent::lint_help);
1302 }
1303 NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => {
1304 diag.span_suggestion(
1305 span,
1306 fluent::lint_convert_suggestion,
1307 suggestion,
1308 Applicability::MaybeIncorrect,
1309 );
1310 }
1311 NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => {
1312 diag.span_suggestion(
1313 span,
1314 fluent::lint_rename_or_convert_suggestion,
1315 suggestion,
1316 Applicability::MaybeIncorrect,
1317 );
1318 }
1319 NonSnakeCaseDiagSub::SuggestionAndNote { span } => {
1320 diag.note(fluent::lint_cannot_convert_note);
1321 diag.span_suggestion(
1322 span,
1323 fluent::lint_rename_suggestion,
1324 "",
1325 Applicability::MaybeIncorrect,
1326 );
1327 }
1328 }
1329 }
1330}
1331
1332#[derive(LintDiagnostic)]
1333#[diag(lint_non_upper_case_global)]
1334pub(crate) struct NonUpperCaseGlobal<'a> {
1335 pub sort: &'a str,
1336 pub name: &'a str,
1337 #[subdiagnostic]
1338 pub sub: NonUpperCaseGlobalSub,
1339 #[subdiagnostic]
1340 pub usages: Vec<NonUpperCaseGlobalSubTool>,
1341}
1342
1343#[derive(Subdiagnostic)]
1344pub(crate) enum NonUpperCaseGlobalSub {
1345 #[label(lint_label)]
1346 Label {
1347 #[primary_span]
1348 span: Span,
1349 },
1350 #[suggestion(lint_suggestion, code = "{replace}")]
1351 Suggestion {
1352 #[primary_span]
1353 span: Span,
1354 #[applicability]
1355 applicability: Applicability,
1356 replace: String,
1357 },
1358}
1359
1360#[derive(Subdiagnostic)]
1361#[suggestion(
1362 lint_suggestion,
1363 code = "{replace}",
1364 applicability = "machine-applicable",
1365 style = "tool-only"
1366)]
1367pub(crate) struct NonUpperCaseGlobalSubTool {
1368 #[primary_span]
1369 pub(crate) span: Span,
1370 pub(crate) replace: String,
1371}
1372
1373#[derive(LintDiagnostic)]
1375#[diag(lint_noop_method_call)]
1376#[note]
1377pub(crate) struct NoopMethodCallDiag<'a> {
1378 pub method: Ident,
1379 pub orig_ty: Ty<'a>,
1380 pub trait_: Symbol,
1381 #[suggestion(code = "", applicability = "machine-applicable")]
1382 pub label: Span,
1383 #[suggestion(
1384 lint_derive_suggestion,
1385 code = "#[derive(Clone)]\n",
1386 applicability = "maybe-incorrect"
1387 )]
1388 pub suggest_derive: Option<Span>,
1389}
1390
1391#[derive(LintDiagnostic)]
1392#[diag(lint_suspicious_double_ref_deref)]
1393pub(crate) struct SuspiciousDoubleRefDerefDiag<'a> {
1394 pub ty: Ty<'a>,
1395}
1396
1397#[derive(LintDiagnostic)]
1398#[diag(lint_suspicious_double_ref_clone)]
1399pub(crate) struct SuspiciousDoubleRefCloneDiag<'a> {
1400 pub ty: Ty<'a>,
1401}
1402
1403pub(crate) enum NonLocalDefinitionsDiag {
1405 Impl {
1406 depth: u32,
1407 body_kind_descr: &'static str,
1408 body_name: String,
1409 cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1410 const_anon: Option<Option<Span>>,
1411 doctest: bool,
1412 macro_to_change: Option<(String, &'static str)>,
1413 },
1414 MacroRules {
1415 depth: u32,
1416 body_kind_descr: &'static str,
1417 body_name: String,
1418 doctest: bool,
1419 cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1420 },
1421}
1422
1423impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
1424 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1425 match self {
1426 NonLocalDefinitionsDiag::Impl {
1427 depth,
1428 body_kind_descr,
1429 body_name,
1430 cargo_update,
1431 const_anon,
1432 doctest,
1433 macro_to_change,
1434 } => {
1435 diag.primary_message(fluent::lint_non_local_definitions_impl);
1436 diag.arg("depth", depth);
1437 diag.arg("body_kind_descr", body_kind_descr);
1438 diag.arg("body_name", body_name);
1439
1440 if let Some((macro_to_change, macro_kind)) = macro_to_change {
1441 diag.arg("macro_to_change", macro_to_change);
1442 diag.arg("macro_kind", macro_kind);
1443 diag.note(fluent::lint_macro_to_change);
1444 }
1445 if let Some(cargo_update) = cargo_update {
1446 diag.subdiagnostic(cargo_update);
1447 }
1448
1449 diag.note(fluent::lint_non_local);
1450
1451 if doctest {
1452 diag.help(fluent::lint_doctest);
1453 }
1454
1455 if let Some(const_anon) = const_anon {
1456 diag.note(fluent::lint_exception);
1457 if let Some(const_anon) = const_anon {
1458 diag.span_suggestion(
1459 const_anon,
1460 fluent::lint_const_anon,
1461 "_",
1462 Applicability::MachineApplicable,
1463 );
1464 }
1465 }
1466 }
1467 NonLocalDefinitionsDiag::MacroRules {
1468 depth,
1469 body_kind_descr,
1470 body_name,
1471 doctest,
1472 cargo_update,
1473 } => {
1474 diag.primary_message(fluent::lint_non_local_definitions_macro_rules);
1475 diag.arg("depth", depth);
1476 diag.arg("body_kind_descr", body_kind_descr);
1477 diag.arg("body_name", body_name);
1478
1479 if doctest {
1480 diag.help(fluent::lint_help_doctest);
1481 } else {
1482 diag.help(fluent::lint_help);
1483 }
1484
1485 diag.note(fluent::lint_non_local);
1486
1487 if let Some(cargo_update) = cargo_update {
1488 diag.subdiagnostic(cargo_update);
1489 }
1490 }
1491 }
1492 }
1493}
1494
1495#[derive(Subdiagnostic)]
1496#[note(lint_non_local_definitions_cargo_update)]
1497pub(crate) struct NonLocalDefinitionsCargoUpdateNote {
1498 pub macro_kind: &'static str,
1499 pub macro_name: Symbol,
1500 pub crate_name: Symbol,
1501}
1502
1503#[derive(LintDiagnostic)]
1505#[diag(lint_ambiguous_negative_literals)]
1506#[note(lint_example)]
1507pub(crate) struct AmbiguousNegativeLiteralsDiag {
1508 #[subdiagnostic]
1509 pub negative_literal: AmbiguousNegativeLiteralsNegativeLiteralSuggestion,
1510 #[subdiagnostic]
1511 pub current_behavior: AmbiguousNegativeLiteralsCurrentBehaviorSuggestion,
1512}
1513
1514#[derive(Subdiagnostic)]
1515#[multipart_suggestion(lint_negative_literal, applicability = "maybe-incorrect")]
1516pub(crate) struct AmbiguousNegativeLiteralsNegativeLiteralSuggestion {
1517 #[suggestion_part(code = "(")]
1518 pub start_span: Span,
1519 #[suggestion_part(code = ")")]
1520 pub end_span: Span,
1521}
1522
1523#[derive(Subdiagnostic)]
1524#[multipart_suggestion(lint_current_behavior, applicability = "maybe-incorrect")]
1525pub(crate) struct AmbiguousNegativeLiteralsCurrentBehaviorSuggestion {
1526 #[suggestion_part(code = "(")]
1527 pub start_span: Span,
1528 #[suggestion_part(code = ")")]
1529 pub end_span: Span,
1530}
1531
1532#[derive(LintDiagnostic)]
1534#[diag(lint_pass_by_value)]
1535pub(crate) struct PassByValueDiag {
1536 pub ty: String,
1537 #[suggestion(code = "{ty}", applicability = "maybe-incorrect")]
1538 pub suggestion: Span,
1539}
1540
1541#[derive(LintDiagnostic)]
1543#[diag(lint_redundant_semicolons)]
1544pub(crate) struct RedundantSemicolonsDiag {
1545 pub multiple: bool,
1546 #[subdiagnostic]
1547 pub suggestion: Option<RedundantSemicolonsSuggestion>,
1548}
1549
1550#[derive(Subdiagnostic)]
1551#[suggestion(lint_redundant_semicolons_suggestion, code = "", applicability = "maybe-incorrect")]
1552pub(crate) struct RedundantSemicolonsSuggestion {
1553 pub multiple_semicolons: bool,
1554 #[primary_span]
1555 pub span: Span,
1556}
1557
1558pub(crate) struct DropTraitConstraintsDiag<'a> {
1560 pub predicate: Clause<'a>,
1561 pub tcx: TyCtxt<'a>,
1562 pub def_id: DefId,
1563}
1564
1565impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
1567 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1568 diag.primary_message(fluent::lint_drop_trait_constraints);
1569 diag.arg("predicate", self.predicate);
1570 diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
1571 }
1572}
1573
1574pub(crate) struct DropGlue<'a> {
1575 pub tcx: TyCtxt<'a>,
1576 pub def_id: DefId,
1577}
1578
1579impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
1581 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1582 diag.primary_message(fluent::lint_drop_glue);
1583 diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
1584 }
1585}
1586
1587#[derive(LintDiagnostic)]
1589#[diag(lint_int_to_ptr_transmutes)]
1590#[note]
1591#[note(lint_note_exposed_provenance)]
1592#[help(lint_suggestion_without_provenance_mut)]
1593#[help(lint_help_transmute)]
1594#[help(lint_help_exposed_provenance)]
1595pub(crate) struct IntegerToPtrTransmutes<'tcx> {
1596 #[subdiagnostic]
1597 pub suggestion: Option<IntegerToPtrTransmutesSuggestion<'tcx>>,
1598}
1599
1600#[derive(Subdiagnostic)]
1601pub(crate) enum IntegerToPtrTransmutesSuggestion<'tcx> {
1602 #[multipart_suggestion(
1603 lint_suggestion_with_exposed_provenance,
1604 applicability = "machine-applicable",
1605 style = "verbose"
1606 )]
1607 ToPtr {
1608 dst: Ty<'tcx>,
1609 suffix: &'static str,
1610 #[suggestion_part(code = "std::ptr::with_exposed_provenance{suffix}::<{dst}>(")]
1611 start_call: Span,
1612 },
1613 #[multipart_suggestion(
1614 lint_suggestion_with_exposed_provenance,
1615 applicability = "machine-applicable",
1616 style = "verbose"
1617 )]
1618 ToRef {
1619 dst: Ty<'tcx>,
1620 suffix: &'static str,
1621 ref_mutbl: &'static str,
1622 #[suggestion_part(
1623 code = "&{ref_mutbl}*std::ptr::with_exposed_provenance{suffix}::<{dst}>("
1624 )]
1625 start_call: Span,
1626 },
1627}
1628
1629#[derive(LintDiagnostic)]
1631#[diag(lint_range_endpoint_out_of_range)]
1632pub(crate) struct RangeEndpointOutOfRange<'a> {
1633 pub ty: &'a str,
1634 #[subdiagnostic]
1635 pub sub: UseInclusiveRange<'a>,
1636}
1637
1638#[derive(Subdiagnostic)]
1639pub(crate) enum UseInclusiveRange<'a> {
1640 #[suggestion(
1641 lint_range_use_inclusive_range,
1642 code = "{start}..={literal}{suffix}",
1643 applicability = "machine-applicable"
1644 )]
1645 WithoutParen {
1646 #[primary_span]
1647 sugg: Span,
1648 start: String,
1649 literal: u128,
1650 suffix: &'a str,
1651 },
1652 #[multipart_suggestion(lint_range_use_inclusive_range, applicability = "machine-applicable")]
1653 WithParen {
1654 #[suggestion_part(code = "=")]
1655 eq_sugg: Span,
1656 #[suggestion_part(code = "{literal}{suffix}")]
1657 lit_sugg: Span,
1658 literal: u128,
1659 suffix: &'a str,
1660 },
1661}
1662
1663#[derive(LintDiagnostic)]
1664#[diag(lint_overflowing_bin_hex)]
1665pub(crate) struct OverflowingBinHex<'a> {
1666 pub ty: &'a str,
1667 pub lit: String,
1668 pub dec: u128,
1669 pub actually: String,
1670 #[subdiagnostic]
1671 pub sign: OverflowingBinHexSign,
1672 #[subdiagnostic]
1673 pub sub: Option<OverflowingBinHexSub<'a>>,
1674 #[subdiagnostic]
1675 pub sign_bit_sub: Option<OverflowingBinHexSignBitSub<'a>>,
1676}
1677
1678pub(crate) enum OverflowingBinHexSign {
1679 Positive,
1680 Negative,
1681}
1682
1683impl Subdiagnostic for OverflowingBinHexSign {
1684 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1685 match self {
1686 OverflowingBinHexSign::Positive => {
1687 diag.note(fluent::lint_positive_note);
1688 }
1689 OverflowingBinHexSign::Negative => {
1690 diag.note(fluent::lint_negative_note);
1691 diag.note(fluent::lint_negative_becomes_note);
1692 }
1693 }
1694 }
1695}
1696
1697#[derive(Subdiagnostic)]
1698pub(crate) enum OverflowingBinHexSub<'a> {
1699 #[suggestion(
1700 lint_suggestion,
1701 code = "{sans_suffix}{suggestion_ty}",
1702 applicability = "machine-applicable"
1703 )]
1704 Suggestion {
1705 #[primary_span]
1706 span: Span,
1707 suggestion_ty: &'a str,
1708 sans_suffix: &'a str,
1709 },
1710 #[help(lint_help)]
1711 Help { suggestion_ty: &'a str },
1712}
1713
1714#[derive(Subdiagnostic)]
1715#[suggestion(
1716 lint_sign_bit_suggestion,
1717 code = "{lit_no_suffix}{uint_ty} as {int_ty}",
1718 applicability = "maybe-incorrect"
1719)]
1720pub(crate) struct OverflowingBinHexSignBitSub<'a> {
1721 #[primary_span]
1722 pub span: Span,
1723 pub lit_no_suffix: &'a str,
1724 pub negative_val: String,
1725 pub uint_ty: &'a str,
1726 pub int_ty: &'a str,
1727}
1728
1729#[derive(LintDiagnostic)]
1730#[diag(lint_overflowing_int)]
1731#[note]
1732pub(crate) struct OverflowingInt<'a> {
1733 pub ty: &'a str,
1734 pub lit: String,
1735 pub min: i128,
1736 pub max: u128,
1737 #[subdiagnostic]
1738 pub help: Option<OverflowingIntHelp<'a>>,
1739}
1740
1741#[derive(Subdiagnostic)]
1742#[help(lint_help)]
1743pub(crate) struct OverflowingIntHelp<'a> {
1744 pub suggestion_ty: &'a str,
1745}
1746
1747#[derive(LintDiagnostic)]
1748#[diag(lint_only_cast_u8_to_char)]
1749pub(crate) struct OnlyCastu8ToChar {
1750 #[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")]
1751 pub span: Span,
1752 pub literal: u128,
1753}
1754
1755#[derive(LintDiagnostic)]
1756#[diag(lint_overflowing_uint)]
1757#[note]
1758pub(crate) struct OverflowingUInt<'a> {
1759 pub ty: &'a str,
1760 pub lit: String,
1761 pub min: u128,
1762 pub max: u128,
1763}
1764
1765#[derive(LintDiagnostic)]
1766#[diag(lint_overflowing_literal)]
1767#[note]
1768pub(crate) struct OverflowingLiteral<'a> {
1769 pub ty: &'a str,
1770 pub lit: String,
1771}
1772
1773#[derive(LintDiagnostic)]
1774#[diag(lint_surrogate_char_cast)]
1775#[note]
1776pub(crate) struct SurrogateCharCast {
1777 pub literal: u128,
1778}
1779
1780#[derive(LintDiagnostic)]
1781#[diag(lint_too_large_char_cast)]
1782#[note]
1783pub(crate) struct TooLargeCharCast {
1784 pub literal: u128,
1785}
1786
1787#[derive(LintDiagnostic)]
1788#[diag(lint_uses_power_alignment)]
1789pub(crate) struct UsesPowerAlignment;
1790
1791#[derive(LintDiagnostic)]
1792#[diag(lint_unused_comparisons)]
1793pub(crate) struct UnusedComparisons;
1794
1795#[derive(LintDiagnostic)]
1796pub(crate) enum InvalidNanComparisons {
1797 #[diag(lint_invalid_nan_comparisons_eq_ne)]
1798 EqNe {
1799 #[subdiagnostic]
1800 suggestion: InvalidNanComparisonsSuggestion,
1801 },
1802 #[diag(lint_invalid_nan_comparisons_lt_le_gt_ge)]
1803 LtLeGtGe,
1804}
1805
1806#[derive(Subdiagnostic)]
1807pub(crate) enum InvalidNanComparisonsSuggestion {
1808 #[multipart_suggestion(
1809 lint_suggestion,
1810 style = "verbose",
1811 applicability = "machine-applicable"
1812 )]
1813 Spanful {
1814 #[suggestion_part(code = "!")]
1815 neg: Option<Span>,
1816 #[suggestion_part(code = ".is_nan()")]
1817 float: Span,
1818 #[suggestion_part(code = "")]
1819 nan_plus_binop: Span,
1820 },
1821 #[help(lint_suggestion)]
1822 Spanless,
1823}
1824
1825#[derive(LintDiagnostic)]
1826pub(crate) enum AmbiguousWidePointerComparisons<'a> {
1827 #[diag(lint_ambiguous_wide_pointer_comparisons)]
1828 SpanfulEq {
1829 #[subdiagnostic]
1830 addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion<'a>,
1831 #[subdiagnostic]
1832 addr_metadata_suggestion: Option<AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a>>,
1833 },
1834 #[diag(lint_ambiguous_wide_pointer_comparisons)]
1835 SpanfulCmp {
1836 #[subdiagnostic]
1837 cast_suggestion: AmbiguousWidePointerComparisonsCastSuggestion<'a>,
1838 #[subdiagnostic]
1839 expect_suggestion: AmbiguousWidePointerComparisonsExpectSuggestion<'a>,
1840 },
1841 #[diag(lint_ambiguous_wide_pointer_comparisons)]
1842 #[help(lint_addr_metadata_suggestion)]
1843 #[help(lint_addr_suggestion)]
1844 Spanless,
1845}
1846
1847#[derive(Subdiagnostic)]
1848#[multipart_suggestion(
1849 lint_addr_metadata_suggestion,
1850 style = "verbose",
1851 applicability = "maybe-incorrect"
1853)]
1854pub(crate) struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
1855 pub ne: &'a str,
1856 pub deref_left: &'a str,
1857 pub deref_right: &'a str,
1858 pub l_modifiers: &'a str,
1859 pub r_modifiers: &'a str,
1860 #[suggestion_part(code = "{ne}std::ptr::eq({deref_left}")]
1861 pub left: Span,
1862 #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
1863 pub middle: Span,
1864 #[suggestion_part(code = "{r_modifiers})")]
1865 pub right: Span,
1866}
1867
1868#[derive(Subdiagnostic)]
1869#[multipart_suggestion(
1870 lint_addr_suggestion,
1871 style = "verbose",
1872 applicability = "maybe-incorrect"
1874)]
1875pub(crate) struct AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
1876 pub(crate) ne: &'a str,
1877 pub(crate) deref_left: &'a str,
1878 pub(crate) deref_right: &'a str,
1879 pub(crate) l_modifiers: &'a str,
1880 pub(crate) r_modifiers: &'a str,
1881 #[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
1882 pub(crate) left: Span,
1883 #[suggestion_part(code = "{l_modifiers}, {deref_right}")]
1884 pub(crate) middle: Span,
1885 #[suggestion_part(code = "{r_modifiers})")]
1886 pub(crate) right: Span,
1887}
1888
1889#[derive(Subdiagnostic)]
1890#[multipart_suggestion(
1891 lint_cast_suggestion,
1892 style = "verbose",
1893 applicability = "maybe-incorrect"
1895)]
1896pub(crate) struct AmbiguousWidePointerComparisonsCastSuggestion<'a> {
1897 pub(crate) deref_left: &'a str,
1898 pub(crate) deref_right: &'a str,
1899 pub(crate) paren_left: &'a str,
1900 pub(crate) paren_right: &'a str,
1901 pub(crate) l_modifiers: &'a str,
1902 pub(crate) r_modifiers: &'a str,
1903 #[suggestion_part(code = "({deref_left}")]
1904 pub(crate) left_before: Option<Span>,
1905 #[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
1906 pub(crate) left_after: Span,
1907 #[suggestion_part(code = "({deref_right}")]
1908 pub(crate) right_before: Option<Span>,
1909 #[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
1910 pub(crate) right_after: Span,
1911}
1912
1913#[derive(Subdiagnostic)]
1914#[multipart_suggestion(
1915 lint_expect_suggestion,
1916 style = "verbose",
1917 applicability = "maybe-incorrect"
1919)]
1920pub(crate) struct AmbiguousWidePointerComparisonsExpectSuggestion<'a> {
1921 pub(crate) paren_left: &'a str,
1922 pub(crate) paren_right: &'a str,
1923 #[suggestion_part(
1925 code = r#"{{ #[expect(ambiguous_wide_pointer_comparisons, reason = "...")] {paren_left}"#
1926 )]
1927 pub(crate) before: Span,
1928 #[suggestion_part(code = "{paren_right} }}")]
1929 pub(crate) after: Span,
1930}
1931
1932#[derive(LintDiagnostic)]
1933pub(crate) enum UnpredictableFunctionPointerComparisons<'a, 'tcx> {
1934 #[diag(lint_unpredictable_fn_pointer_comparisons)]
1935 #[note(lint_note_duplicated_fn)]
1936 #[note(lint_note_deduplicated_fn)]
1937 #[note(lint_note_visit_fn_addr_eq)]
1938 Suggestion {
1939 #[subdiagnostic]
1940 sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx>,
1941 },
1942 #[diag(lint_unpredictable_fn_pointer_comparisons)]
1943 #[note(lint_note_duplicated_fn)]
1944 #[note(lint_note_deduplicated_fn)]
1945 #[note(lint_note_visit_fn_addr_eq)]
1946 Warn,
1947}
1948
1949#[derive(Subdiagnostic)]
1950pub(crate) enum UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
1951 #[multipart_suggestion(
1952 lint_fn_addr_eq_suggestion,
1953 style = "verbose",
1954 applicability = "maybe-incorrect"
1955 )]
1956 FnAddrEq {
1957 ne: &'a str,
1958 deref_left: &'a str,
1959 deref_right: &'a str,
1960 #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1961 left: Span,
1962 #[suggestion_part(code = ", {deref_right}")]
1963 middle: Span,
1964 #[suggestion_part(code = ")")]
1965 right: Span,
1966 },
1967 #[multipart_suggestion(
1968 lint_fn_addr_eq_suggestion,
1969 style = "verbose",
1970 applicability = "maybe-incorrect"
1971 )]
1972 FnAddrEqWithCast {
1973 ne: &'a str,
1974 deref_left: &'a str,
1975 deref_right: &'a str,
1976 fn_sig: rustc_middle::ty::PolyFnSig<'tcx>,
1977 #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
1978 left: Span,
1979 #[suggestion_part(code = ", {deref_right}")]
1980 middle: Span,
1981 #[suggestion_part(code = " as {fn_sig})")]
1982 right: Span,
1983 },
1984}
1985
1986pub(crate) struct ImproperCTypes<'a> {
1987 pub ty: Ty<'a>,
1988 pub desc: &'a str,
1989 pub label: Span,
1990 pub help: Option<DiagMessage>,
1991 pub note: DiagMessage,
1992 pub span_note: Option<Span>,
1993}
1994
1995impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
1997 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1998 diag.primary_message(fluent::lint_improper_ctypes);
1999 diag.arg("ty", self.ty);
2000 diag.arg("desc", self.desc);
2001 diag.span_label(self.label, fluent::lint_label);
2002 if let Some(help) = self.help {
2003 diag.help(help);
2004 }
2005 diag.note(self.note);
2006 if let Some(note) = self.span_note {
2007 diag.span_note(note, fluent::lint_note);
2008 }
2009 }
2010}
2011
2012#[derive(LintDiagnostic)]
2013#[diag(lint_variant_size_differences)]
2014pub(crate) struct VariantSizeDifferencesDiag {
2015 pub largest: u64,
2016}
2017
2018#[derive(LintDiagnostic)]
2019#[diag(lint_atomic_ordering_load)]
2020#[help]
2021pub(crate) struct AtomicOrderingLoad;
2022
2023#[derive(LintDiagnostic)]
2024#[diag(lint_atomic_ordering_store)]
2025#[help]
2026pub(crate) struct AtomicOrderingStore;
2027
2028#[derive(LintDiagnostic)]
2029#[diag(lint_atomic_ordering_fence)]
2030#[help]
2031pub(crate) struct AtomicOrderingFence;
2032
2033#[derive(LintDiagnostic)]
2034#[diag(lint_atomic_ordering_invalid)]
2035#[help]
2036pub(crate) struct InvalidAtomicOrderingDiag {
2037 pub method: Symbol,
2038 #[label]
2039 pub fail_order_arg_span: Span,
2040}
2041
2042#[derive(LintDiagnostic)]
2044#[diag(lint_unused_op)]
2045pub(crate) struct UnusedOp<'a> {
2046 pub op: &'a str,
2047 #[label]
2048 pub label: Span,
2049 #[subdiagnostic]
2050 pub suggestion: UnusedOpSuggestion,
2051}
2052
2053#[derive(Subdiagnostic)]
2054pub(crate) enum UnusedOpSuggestion {
2055 #[suggestion(
2056 lint_suggestion,
2057 style = "verbose",
2058 code = "let _ = ",
2059 applicability = "maybe-incorrect"
2060 )]
2061 NormalExpr {
2062 #[primary_span]
2063 span: Span,
2064 },
2065 #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2066 BlockTailExpr {
2067 #[suggestion_part(code = "let _ = ")]
2068 before_span: Span,
2069 #[suggestion_part(code = ";")]
2070 after_span: Span,
2071 },
2072}
2073
2074#[derive(LintDiagnostic)]
2075#[diag(lint_unused_result)]
2076pub(crate) struct UnusedResult<'a> {
2077 pub ty: Ty<'a>,
2078}
2079
2080#[derive(LintDiagnostic)]
2083#[diag(lint_unused_closure)]
2084#[note]
2085pub(crate) struct UnusedClosure<'a> {
2086 pub count: usize,
2087 pub pre: &'a str,
2088 pub post: &'a str,
2089}
2090
2091#[derive(LintDiagnostic)]
2094#[diag(lint_unused_coroutine)]
2095#[note]
2096pub(crate) struct UnusedCoroutine<'a> {
2097 pub count: usize,
2098 pub pre: &'a str,
2099 pub post: &'a str,
2100}
2101
2102pub(crate) struct UnusedDef<'a, 'b> {
2105 pub pre: &'a str,
2106 pub post: &'a str,
2107 pub cx: &'a LateContext<'b>,
2108 pub def_id: DefId,
2109 pub note: Option<Symbol>,
2110 pub suggestion: Option<UnusedDefSuggestion>,
2111}
2112
2113#[derive(Subdiagnostic)]
2114
2115pub(crate) enum UnusedDefSuggestion {
2116 #[suggestion(
2117 lint_suggestion,
2118 style = "verbose",
2119 code = "let _ = ",
2120 applicability = "maybe-incorrect"
2121 )]
2122 NormalExpr {
2123 #[primary_span]
2124 span: Span,
2125 },
2126 #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2127 BlockTailExpr {
2128 #[suggestion_part(code = "let _ = ")]
2129 before_span: Span,
2130 #[suggestion_part(code = ";")]
2131 after_span: Span,
2132 },
2133}
2134
2135impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
2137 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2138 diag.primary_message(fluent::lint_unused_def);
2139 diag.arg("pre", self.pre);
2140 diag.arg("post", self.post);
2141 diag.arg("def", self.cx.tcx.def_path_str(self.def_id));
2142 if let Some(note) = self.note {
2144 diag.note(note.to_string());
2145 }
2146 if let Some(sugg) = self.suggestion {
2147 diag.subdiagnostic(sugg);
2148 }
2149 }
2150}
2151
2152#[derive(LintDiagnostic)]
2153#[diag(lint_path_statement_drop)]
2154pub(crate) struct PathStatementDrop {
2155 #[subdiagnostic]
2156 pub sub: PathStatementDropSub,
2157}
2158
2159#[derive(Subdiagnostic)]
2160pub(crate) enum PathStatementDropSub {
2161 #[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")]
2162 Suggestion {
2163 #[primary_span]
2164 span: Span,
2165 snippet: String,
2166 },
2167 #[help(lint_help)]
2168 Help {
2169 #[primary_span]
2170 span: Span,
2171 },
2172}
2173
2174#[derive(LintDiagnostic)]
2175#[diag(lint_path_statement_no_effect)]
2176pub(crate) struct PathStatementNoEffect;
2177
2178#[derive(LintDiagnostic)]
2179#[diag(lint_unused_delim)]
2180pub(crate) struct UnusedDelim<'a> {
2181 pub delim: &'static str,
2182 pub item: &'a str,
2183 #[subdiagnostic]
2184 pub suggestion: Option<UnusedDelimSuggestion>,
2185}
2186
2187#[derive(Subdiagnostic)]
2188#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2189pub(crate) struct UnusedDelimSuggestion {
2190 #[suggestion_part(code = "{start_replace}")]
2191 pub start_span: Span,
2192 pub start_replace: &'static str,
2193 #[suggestion_part(code = "{end_replace}")]
2194 pub end_span: Span,
2195 pub end_replace: &'static str,
2196}
2197
2198#[derive(LintDiagnostic)]
2199#[diag(lint_unused_import_braces)]
2200pub(crate) struct UnusedImportBracesDiag {
2201 pub node: Symbol,
2202}
2203
2204#[derive(LintDiagnostic)]
2205#[diag(lint_unused_allocation)]
2206pub(crate) struct UnusedAllocationDiag;
2207
2208#[derive(LintDiagnostic)]
2209#[diag(lint_unused_allocation_mut)]
2210pub(crate) struct UnusedAllocationMutDiag;
2211
2212pub(crate) struct AsyncFnInTraitDiag {
2213 pub sugg: Option<Vec<(Span, String)>>,
2214}
2215
2216impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
2217 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2218 diag.primary_message(fluent::lint_async_fn_in_trait);
2219 diag.note(fluent::lint_note);
2220 if let Some(sugg) = self.sugg {
2221 diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
2222 }
2223 }
2224}
2225
2226#[derive(LintDiagnostic)]
2227#[diag(lint_unit_bindings)]
2228pub(crate) struct UnitBindingsDiag {
2229 #[label]
2230 pub label: Span,
2231}
2232
2233#[derive(LintDiagnostic)]
2234pub(crate) enum InvalidAsmLabel {
2235 #[diag(lint_invalid_asm_label_named)]
2236 #[help]
2237 #[note]
2238 Named {
2239 #[note(lint_invalid_asm_label_no_span)]
2240 missing_precise_span: bool,
2241 },
2242 #[diag(lint_invalid_asm_label_format_arg)]
2243 #[help]
2244 #[note(lint_note1)]
2245 #[note(lint_note2)]
2246 FormatArg {
2247 #[note(lint_invalid_asm_label_no_span)]
2248 missing_precise_span: bool,
2249 },
2250 #[diag(lint_invalid_asm_label_binary)]
2251 #[help]
2252 #[note(lint_note1)]
2253 #[note(lint_note2)]
2254 Binary {
2255 #[note(lint_invalid_asm_label_no_span)]
2256 missing_precise_span: bool,
2257 #[label]
2259 span: Span,
2260 },
2261}
2262
2263#[derive(Subdiagnostic)]
2264pub(crate) enum UnexpectedCfgCargoHelp {
2265 #[help(lint_unexpected_cfg_add_cargo_feature)]
2266 #[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
2267 LintCfg { cargo_toml_lint_cfg: String },
2268 #[help(lint_unexpected_cfg_add_cargo_feature)]
2269 #[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
2270 #[help(lint_unexpected_cfg_add_build_rs_println)]
2271 LintCfgAndBuildRs { cargo_toml_lint_cfg: String, build_rs_println: String },
2272}
2273
2274impl UnexpectedCfgCargoHelp {
2275 fn cargo_toml_lint_cfg(unescaped: &str) -> String {
2276 format!(
2277 "\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}"
2278 )
2279 }
2280
2281 pub(crate) fn lint_cfg(unescaped: &str) -> Self {
2282 UnexpectedCfgCargoHelp::LintCfg {
2283 cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
2284 }
2285 }
2286
2287 pub(crate) fn lint_cfg_and_build_rs(unescaped: &str, escaped: &str) -> Self {
2288 UnexpectedCfgCargoHelp::LintCfgAndBuildRs {
2289 cargo_toml_lint_cfg: Self::cargo_toml_lint_cfg(unescaped),
2290 build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");"),
2291 }
2292 }
2293}
2294
2295#[derive(Subdiagnostic)]
2296#[help(lint_unexpected_cfg_add_cmdline_arg)]
2297pub(crate) struct UnexpectedCfgRustcHelp {
2298 pub cmdline_arg: String,
2299}
2300
2301impl UnexpectedCfgRustcHelp {
2302 pub(crate) fn new(unescaped: &str) -> Self {
2303 Self { cmdline_arg: format!("--check-cfg={unescaped}") }
2304 }
2305}
2306
2307#[derive(Subdiagnostic)]
2308#[note(lint_unexpected_cfg_from_external_macro_origin)]
2309#[help(lint_unexpected_cfg_from_external_macro_refer)]
2310pub(crate) struct UnexpectedCfgRustcMacroHelp {
2311 pub macro_kind: &'static str,
2312 pub macro_name: Symbol,
2313}
2314
2315#[derive(Subdiagnostic)]
2316#[note(lint_unexpected_cfg_from_external_macro_origin)]
2317#[help(lint_unexpected_cfg_from_external_macro_refer)]
2318#[help(lint_unexpected_cfg_cargo_update)]
2319pub(crate) struct UnexpectedCfgCargoMacroHelp {
2320 pub macro_kind: &'static str,
2321 pub macro_name: Symbol,
2322 pub crate_name: Symbol,
2323}
2324
2325#[derive(LintDiagnostic)]
2326#[diag(lint_unexpected_cfg_name)]
2327pub(crate) struct UnexpectedCfgName {
2328 #[subdiagnostic]
2329 pub code_sugg: unexpected_cfg_name::CodeSuggestion,
2330 #[subdiagnostic]
2331 pub invocation_help: unexpected_cfg_name::InvocationHelp,
2332
2333 pub name: Symbol,
2334}
2335
2336pub(crate) mod unexpected_cfg_name {
2337 use rustc_errors::DiagSymbolList;
2338 use rustc_macros::Subdiagnostic;
2339 use rustc_span::{Ident, Span, Symbol};
2340
2341 #[derive(Subdiagnostic)]
2342 pub(crate) enum CodeSuggestion {
2343 #[help(lint_unexpected_cfg_define_features)]
2344 DefineFeatures,
2345 #[multipart_suggestion(
2346 lint_unexpected_cfg_name_version_syntax,
2347 applicability = "machine-applicable"
2348 )]
2349 VersionSyntax {
2350 #[suggestion_part(code = "(")]
2351 between_name_and_value: Span,
2352 #[suggestion_part(code = ")")]
2353 after_value: Span,
2354 },
2355 #[suggestion(
2356 lint_unexpected_cfg_name_similar_name_value,
2357 applicability = "maybe-incorrect",
2358 code = "{code}"
2359 )]
2360 SimilarNameAndValue {
2361 #[primary_span]
2362 span: Span,
2363 code: String,
2364 },
2365 #[suggestion(
2366 lint_unexpected_cfg_name_similar_name_no_value,
2367 applicability = "maybe-incorrect",
2368 code = "{code}"
2369 )]
2370 SimilarNameNoValue {
2371 #[primary_span]
2372 span: Span,
2373 code: String,
2374 },
2375 #[suggestion(
2376 lint_unexpected_cfg_name_similar_name_different_values,
2377 applicability = "maybe-incorrect",
2378 code = "{code}"
2379 )]
2380 SimilarNameDifferentValues {
2381 #[primary_span]
2382 span: Span,
2383 code: String,
2384 #[subdiagnostic]
2385 expected: Option<ExpectedValues>,
2386 },
2387 #[suggestion(
2388 lint_unexpected_cfg_name_similar_name,
2389 applicability = "maybe-incorrect",
2390 code = "{code}"
2391 )]
2392 SimilarName {
2393 #[primary_span]
2394 span: Span,
2395 code: String,
2396 #[subdiagnostic]
2397 expected: Option<ExpectedValues>,
2398 },
2399 SimilarValues {
2400 #[subdiagnostic]
2401 with_similar_values: Vec<FoundWithSimilarValue>,
2402 #[subdiagnostic]
2403 expected_names: Option<ExpectedNames>,
2404 },
2405 #[suggestion(
2406 lint_unexpected_cfg_boolean,
2407 applicability = "machine-applicable",
2408 style = "verbose",
2409 code = "{literal}"
2410 )]
2411 BooleanLiteral {
2412 #[primary_span]
2413 span: Span,
2414 literal: bool,
2415 },
2416 }
2417
2418 #[derive(Subdiagnostic)]
2419 #[help(lint_unexpected_cfg_name_expected_values)]
2420 pub(crate) struct ExpectedValues {
2421 pub best_match: Symbol,
2422 pub possibilities: DiagSymbolList,
2423 }
2424
2425 #[derive(Subdiagnostic)]
2426 #[suggestion(
2427 lint_unexpected_cfg_name_with_similar_value,
2428 applicability = "maybe-incorrect",
2429 code = "{code}"
2430 )]
2431 pub(crate) struct FoundWithSimilarValue {
2432 #[primary_span]
2433 pub span: Span,
2434 pub code: String,
2435 }
2436
2437 #[derive(Subdiagnostic)]
2438 #[help_once(lint_unexpected_cfg_name_expected_names)]
2439 pub(crate) struct ExpectedNames {
2440 pub possibilities: DiagSymbolList<Ident>,
2441 pub and_more: usize,
2442 }
2443
2444 #[derive(Subdiagnostic)]
2445 pub(crate) enum InvocationHelp {
2446 #[note(lint_unexpected_cfg_doc_cargo)]
2447 Cargo {
2448 #[subdiagnostic]
2449 macro_help: Option<super::UnexpectedCfgCargoMacroHelp>,
2450 #[subdiagnostic]
2451 help: Option<super::UnexpectedCfgCargoHelp>,
2452 },
2453 #[note(lint_unexpected_cfg_doc_rustc)]
2454 Rustc {
2455 #[subdiagnostic]
2456 macro_help: Option<super::UnexpectedCfgRustcMacroHelp>,
2457 #[subdiagnostic]
2458 help: super::UnexpectedCfgRustcHelp,
2459 },
2460 }
2461}
2462
2463#[derive(LintDiagnostic)]
2464#[diag(lint_unexpected_cfg_value)]
2465pub(crate) struct UnexpectedCfgValue {
2466 #[subdiagnostic]
2467 pub code_sugg: unexpected_cfg_value::CodeSuggestion,
2468 #[subdiagnostic]
2469 pub invocation_help: unexpected_cfg_value::InvocationHelp,
2470
2471 pub has_value: bool,
2472 pub value: String,
2473}
2474
2475pub(crate) mod unexpected_cfg_value {
2476 use rustc_errors::DiagSymbolList;
2477 use rustc_macros::Subdiagnostic;
2478 use rustc_span::{Span, Symbol};
2479
2480 #[derive(Subdiagnostic)]
2481 pub(crate) enum CodeSuggestion {
2482 ChangeValue {
2483 #[subdiagnostic]
2484 expected_values: ExpectedValues,
2485 #[subdiagnostic]
2486 suggestion: Option<ChangeValueSuggestion>,
2487 },
2488 #[note(lint_unexpected_cfg_value_no_expected_value)]
2489 RemoveValue {
2490 #[subdiagnostic]
2491 suggestion: Option<RemoveValueSuggestion>,
2492
2493 name: Symbol,
2494 },
2495 #[note(lint_unexpected_cfg_value_no_expected_values)]
2496 RemoveCondition {
2497 #[subdiagnostic]
2498 suggestion: RemoveConditionSuggestion,
2499
2500 name: Symbol,
2501 },
2502 }
2503
2504 #[derive(Subdiagnostic)]
2505 pub(crate) enum ChangeValueSuggestion {
2506 #[suggestion(
2507 lint_unexpected_cfg_value_similar_name,
2508 code = r#""{best_match}""#,
2509 applicability = "maybe-incorrect"
2510 )]
2511 SimilarName {
2512 #[primary_span]
2513 span: Span,
2514 best_match: Symbol,
2515 },
2516 #[suggestion(
2517 lint_unexpected_cfg_value_specify_value,
2518 code = r#" = "{first_possibility}""#,
2519 applicability = "maybe-incorrect"
2520 )]
2521 SpecifyValue {
2522 #[primary_span]
2523 span: Span,
2524 first_possibility: Symbol,
2525 },
2526 }
2527
2528 #[derive(Subdiagnostic)]
2529 #[suggestion(
2530 lint_unexpected_cfg_value_remove_value,
2531 code = "",
2532 applicability = "maybe-incorrect"
2533 )]
2534 pub(crate) struct RemoveValueSuggestion {
2535 #[primary_span]
2536 pub span: Span,
2537 }
2538
2539 #[derive(Subdiagnostic)]
2540 #[suggestion(
2541 lint_unexpected_cfg_value_remove_condition,
2542 code = "",
2543 applicability = "maybe-incorrect"
2544 )]
2545 pub(crate) struct RemoveConditionSuggestion {
2546 #[primary_span]
2547 pub span: Span,
2548 }
2549
2550 #[derive(Subdiagnostic)]
2551 #[note(lint_unexpected_cfg_value_expected_values)]
2552 pub(crate) struct ExpectedValues {
2553 pub name: Symbol,
2554 pub have_none_possibility: bool,
2555 pub possibilities: DiagSymbolList,
2556 pub and_more: usize,
2557 }
2558
2559 #[derive(Subdiagnostic)]
2560 pub(crate) enum InvocationHelp {
2561 #[note(lint_unexpected_cfg_doc_cargo)]
2562 Cargo {
2563 #[subdiagnostic]
2564 help: Option<CargoHelp>,
2565 #[subdiagnostic]
2566 macro_help: Option<super::UnexpectedCfgCargoMacroHelp>,
2567 },
2568 #[note(lint_unexpected_cfg_doc_rustc)]
2569 Rustc {
2570 #[subdiagnostic]
2571 help: Option<super::UnexpectedCfgRustcHelp>,
2572 #[subdiagnostic]
2573 macro_help: Option<super::UnexpectedCfgRustcMacroHelp>,
2574 },
2575 }
2576
2577 #[derive(Subdiagnostic)]
2578 pub(crate) enum CargoHelp {
2579 #[help(lint_unexpected_cfg_value_add_feature)]
2580 AddFeature {
2581 value: Symbol,
2582 },
2583 #[help(lint_unexpected_cfg_define_features)]
2584 DefineFeatures,
2585 Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp),
2586 }
2587}
2588
2589#[derive(LintDiagnostic)]
2590#[diag(lint_unused_crate_dependency)]
2591#[help]
2592pub(crate) struct UnusedCrateDependency {
2593 pub extern_crate: Symbol,
2594 pub local_crate: Symbol,
2595}
2596
2597#[derive(LintDiagnostic)]
2599#[diag(lint_ill_formed_attribute_input)]
2600pub(crate) struct IllFormedAttributeInput {
2601 pub num_suggestions: usize,
2602 pub suggestions: DiagArgValue,
2603 #[note]
2604 pub has_docs: bool,
2605 pub docs: &'static str,
2606}
2607
2608#[derive(LintDiagnostic)]
2609#[diag(lint_unicode_text_flow)]
2610#[note]
2611pub(crate) struct UnicodeTextFlow {
2612 #[label]
2613 pub comment_span: Span,
2614 #[subdiagnostic]
2615 pub characters: Vec<UnicodeCharNoteSub>,
2616 #[subdiagnostic]
2617 pub suggestions: Option<UnicodeTextFlowSuggestion>,
2618
2619 pub num_codepoints: usize,
2620}
2621
2622#[derive(Subdiagnostic)]
2623#[label(lint_label_comment_char)]
2624pub(crate) struct UnicodeCharNoteSub {
2625 #[primary_span]
2626 pub span: Span,
2627 pub c_debug: String,
2628}
2629
2630#[derive(Subdiagnostic)]
2631#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable", style = "hidden")]
2632pub(crate) struct UnicodeTextFlowSuggestion {
2633 #[suggestion_part(code = "")]
2634 pub spans: Vec<Span>,
2635}
2636
2637#[derive(LintDiagnostic)]
2638#[diag(lint_abs_path_with_module)]
2639pub(crate) struct AbsPathWithModule {
2640 #[subdiagnostic]
2641 pub sugg: AbsPathWithModuleSugg,
2642}
2643
2644#[derive(Subdiagnostic)]
2645#[suggestion(lint_suggestion, code = "{replacement}")]
2646pub(crate) struct AbsPathWithModuleSugg {
2647 #[primary_span]
2648 pub span: Span,
2649 #[applicability]
2650 pub applicability: Applicability,
2651 pub replacement: String,
2652}
2653
2654#[derive(LintDiagnostic)]
2655#[diag(lint_hidden_lifetime_parameters)]
2656pub(crate) struct ElidedLifetimesInPaths {
2657 #[subdiagnostic]
2658 pub subdiag: ElidedLifetimeInPathSubdiag,
2659}
2660
2661#[derive(LintDiagnostic)]
2662#[diag(lint_unused_imports)]
2663pub(crate) struct UnusedImports {
2664 #[subdiagnostic]
2665 pub sugg: UnusedImportsSugg,
2666 #[help]
2667 pub test_module_span: Option<Span>,
2668
2669 pub span_snippets: DiagArgValue,
2670 pub num_snippets: usize,
2671}
2672
2673#[derive(Subdiagnostic)]
2674pub(crate) enum UnusedImportsSugg {
2675 #[suggestion(
2676 lint_suggestion_remove_whole_use,
2677 applicability = "machine-applicable",
2678 code = "",
2679 style = "tool-only"
2680 )]
2681 RemoveWholeUse {
2682 #[primary_span]
2683 span: Span,
2684 },
2685 #[multipart_suggestion(
2686 lint_suggestion_remove_imports,
2687 applicability = "machine-applicable",
2688 style = "tool-only"
2689 )]
2690 RemoveImports {
2691 #[suggestion_part(code = "")]
2692 remove_spans: Vec<Span>,
2693 num_to_remove: usize,
2694 },
2695}
2696
2697#[derive(LintDiagnostic)]
2698#[diag(lint_redundant_import)]
2699pub(crate) struct RedundantImport {
2700 #[subdiagnostic]
2701 pub subs: Vec<RedundantImportSub>,
2702
2703 pub ident: Ident,
2704}
2705
2706#[derive(Subdiagnostic)]
2707pub(crate) enum RedundantImportSub {
2708 #[label(lint_label_imported_here)]
2709 ImportedHere(#[primary_span] Span),
2710 #[label(lint_label_defined_here)]
2711 DefinedHere(#[primary_span] Span),
2712 #[label(lint_label_imported_prelude)]
2713 ImportedPrelude(#[primary_span] Span),
2714 #[label(lint_label_defined_prelude)]
2715 DefinedPrelude(#[primary_span] Span),
2716}
2717
2718#[derive(LintDiagnostic)]
2719pub(crate) enum PatternsInFnsWithoutBody {
2720 #[diag(lint_pattern_in_foreign)]
2721 Foreign {
2722 #[subdiagnostic]
2723 sub: PatternsInFnsWithoutBodySub,
2724 },
2725 #[diag(lint_pattern_in_bodiless)]
2726 Bodiless {
2727 #[subdiagnostic]
2728 sub: PatternsInFnsWithoutBodySub,
2729 },
2730}
2731
2732#[derive(Subdiagnostic)]
2733#[suggestion(lint_remove_mut_from_pattern, code = "{ident}", applicability = "machine-applicable")]
2734pub(crate) struct PatternsInFnsWithoutBodySub {
2735 #[primary_span]
2736 pub span: Span,
2737
2738 pub ident: Ident,
2739}
2740
2741#[derive(LintDiagnostic)]
2742#[diag(lint_reserved_prefix)]
2743pub(crate) struct ReservedPrefix {
2744 #[label]
2745 pub label: Span,
2746 #[suggestion(code = " ", applicability = "machine-applicable")]
2747 pub suggestion: Span,
2748
2749 pub prefix: String,
2750}
2751
2752#[derive(LintDiagnostic)]
2753#[diag(lint_raw_prefix)]
2754pub(crate) struct RawPrefix {
2755 #[label]
2756 pub label: Span,
2757 #[suggestion(code = " ", applicability = "machine-applicable")]
2758 pub suggestion: Span,
2759}
2760
2761#[derive(LintDiagnostic)]
2762#[diag(lint_break_with_label_and_loop)]
2763pub(crate) struct BreakWithLabelAndLoop {
2764 #[subdiagnostic]
2765 pub sub: BreakWithLabelAndLoopSub,
2766}
2767
2768#[derive(Subdiagnostic)]
2769#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2770pub(crate) struct BreakWithLabelAndLoopSub {
2771 #[suggestion_part(code = "(")]
2772 pub left: Span,
2773 #[suggestion_part(code = ")")]
2774 pub right: Span,
2775}
2776
2777#[derive(LintDiagnostic)]
2778#[diag(lint_deprecated_where_clause_location)]
2779#[note]
2780pub(crate) struct DeprecatedWhereClauseLocation {
2781 #[subdiagnostic]
2782 pub suggestion: DeprecatedWhereClauseLocationSugg,
2783}
2784
2785#[derive(Subdiagnostic)]
2786pub(crate) enum DeprecatedWhereClauseLocationSugg {
2787 #[multipart_suggestion(lint_suggestion_move_to_end, applicability = "machine-applicable")]
2788 MoveToEnd {
2789 #[suggestion_part(code = "")]
2790 left: Span,
2791 #[suggestion_part(code = "{sugg}")]
2792 right: Span,
2793
2794 sugg: String,
2795 },
2796 #[suggestion(lint_suggestion_remove_where, code = "", applicability = "machine-applicable")]
2797 RemoveWhere {
2798 #[primary_span]
2799 span: Span,
2800 },
2801}
2802
2803#[derive(LintDiagnostic)]
2804#[diag(lint_single_use_lifetime)]
2805pub(crate) struct SingleUseLifetime {
2806 #[label(lint_label_param)]
2807 pub param_span: Span,
2808 #[label(lint_label_use)]
2809 pub use_span: Span,
2810 #[subdiagnostic]
2811 pub suggestion: Option<SingleUseLifetimeSugg>,
2812
2813 pub ident: Ident,
2814}
2815
2816#[derive(Subdiagnostic)]
2817#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
2818pub(crate) struct SingleUseLifetimeSugg {
2819 #[suggestion_part(code = "")]
2820 pub deletion_span: Option<Span>,
2821 #[suggestion_part(code = "{replace_lt}")]
2822 pub use_span: Span,
2823
2824 pub replace_lt: String,
2825}
2826
2827#[derive(LintDiagnostic)]
2828#[diag(lint_unused_lifetime)]
2829pub(crate) struct UnusedLifetime {
2830 #[suggestion(code = "", applicability = "machine-applicable")]
2831 pub deletion_span: Option<Span>,
2832
2833 pub ident: Ident,
2834}
2835
2836#[derive(LintDiagnostic)]
2837#[diag(lint_named_argument_used_positionally)]
2838pub(crate) struct NamedArgumentUsedPositionally {
2839 #[label(lint_label_named_arg)]
2840 pub named_arg_sp: Span,
2841 #[label(lint_label_position_arg)]
2842 pub position_label_sp: Option<Span>,
2843 #[suggestion(style = "verbose", code = "{name}", applicability = "maybe-incorrect")]
2844 pub suggestion: Option<Span>,
2845
2846 pub name: String,
2847 pub named_arg_name: String,
2848}
2849
2850#[derive(LintDiagnostic)]
2851#[diag(lint_ambiguous_glob_reexport)]
2852pub(crate) struct AmbiguousGlobReexports {
2853 #[label(lint_label_first_reexport)]
2854 pub first_reexport: Span,
2855 #[label(lint_label_duplicate_reexport)]
2856 pub duplicate_reexport: Span,
2857
2858 pub name: String,
2859 pub namespace: String,
2861}
2862
2863#[derive(LintDiagnostic)]
2864#[diag(lint_hidden_glob_reexport)]
2865pub(crate) struct HiddenGlobReexports {
2866 #[note(lint_note_glob_reexport)]
2867 pub glob_reexport: Span,
2868 #[note(lint_note_private_item)]
2869 pub private_item: Span,
2870
2871 pub name: String,
2872 pub namespace: String,
2874}
2875
2876#[derive(LintDiagnostic)]
2877#[diag(lint_unnecessary_qualification)]
2878pub(crate) struct UnusedQualifications {
2879 #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
2880 pub removal_span: Span,
2881}
2882
2883#[derive(LintDiagnostic)]
2884#[diag(lint_associated_const_elided_lifetime)]
2885pub(crate) struct AssociatedConstElidedLifetime {
2886 #[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
2887 pub span: Span,
2888
2889 pub code: &'static str,
2890 pub elided: bool,
2891 #[note]
2892 pub lifetimes_in_scope: MultiSpan,
2893}
2894
2895#[derive(LintDiagnostic)]
2896#[diag(lint_static_mut_refs_lint)]
2897pub(crate) struct RefOfMutStatic<'a> {
2898 #[label]
2899 pub span: Span,
2900 #[subdiagnostic]
2901 pub sugg: Option<MutRefSugg>,
2902 pub shared_label: &'a str,
2903 #[note(lint_shared_note)]
2904 pub shared_note: bool,
2905 #[note(lint_mut_note)]
2906 pub mut_note: bool,
2907}
2908
2909#[derive(Subdiagnostic)]
2910pub(crate) enum MutRefSugg {
2911 #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
2912 Shared {
2913 #[suggestion_part(code = "&raw const ")]
2914 span: Span,
2915 },
2916 #[multipart_suggestion(
2917 lint_suggestion_mut,
2918 style = "verbose",
2919 applicability = "maybe-incorrect"
2920 )]
2921 Mut {
2922 #[suggestion_part(code = "&raw mut ")]
2923 span: Span,
2924 },
2925}
2926
2927#[derive(LintDiagnostic)]
2928#[diag(lint_unqualified_local_imports)]
2929pub(crate) struct UnqualifiedLocalImportsDiag {}
2930
2931#[derive(LintDiagnostic)]
2932#[diag(lint_reserved_string)]
2933pub(crate) struct ReservedString {
2934 #[suggestion(code = " ", applicability = "machine-applicable")]
2935 pub suggestion: Span,
2936}
2937
2938#[derive(LintDiagnostic)]
2939#[diag(lint_reserved_multihash)]
2940pub(crate) struct ReservedMultihash {
2941 #[suggestion(code = " ", applicability = "machine-applicable")]
2942 pub suggestion: Span,
2943}
2944
2945#[derive(LintDiagnostic)]
2946#[diag(lint_function_casts_as_integer)]
2947pub(crate) struct FunctionCastsAsIntegerDiag<'tcx> {
2948 #[subdiagnostic]
2949 pub(crate) sugg: FunctionCastsAsIntegerSugg<'tcx>,
2950}
2951
2952#[derive(Subdiagnostic)]
2953#[suggestion(
2954 lint_cast_as_fn,
2955 code = " as *const ()",
2956 applicability = "machine-applicable",
2957 style = "verbose"
2958)]
2959pub(crate) struct FunctionCastsAsIntegerSugg<'tcx> {
2960 #[primary_span]
2961 pub suggestion: Span,
2962 pub cast_to_ty: Ty<'tcx>,
2963}
2964
2965#[derive(Debug)]
2966pub(crate) struct MismatchedLifetimeSyntaxes {
2967 pub inputs: LifetimeSyntaxCategories<Vec<Span>>,
2968 pub outputs: LifetimeSyntaxCategories<Vec<Span>>,
2969
2970 pub suggestions: Vec<MismatchedLifetimeSyntaxesSuggestion>,
2971}
2972
2973impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSyntaxes {
2974 fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) {
2975 let counts = self.inputs.len() + self.outputs.len();
2976 let message = match counts {
2977 LifetimeSyntaxCategories { hidden: 0, elided: 0, named: 0 } => {
2978 panic!("No lifetime mismatch detected")
2979 }
2980
2981 LifetimeSyntaxCategories { hidden: _, elided: _, named: 0 } => {
2982 fluent::lint_mismatched_lifetime_syntaxes_hiding_while_elided
2983 }
2984
2985 LifetimeSyntaxCategories { hidden: _, elided: 0, named: _ } => {
2986 fluent::lint_mismatched_lifetime_syntaxes_hiding_while_named
2987 }
2988
2989 LifetimeSyntaxCategories { hidden: 0, elided: _, named: _ } => {
2990 fluent::lint_mismatched_lifetime_syntaxes_eliding_while_named
2991 }
2992
2993 LifetimeSyntaxCategories { hidden: _, elided: _, named: _ } => {
2994 fluent::lint_mismatched_lifetime_syntaxes_hiding_and_eliding_while_named
2995 }
2996 };
2997 diag.primary_message(message);
2998
2999 for s in self.inputs.hidden {
3000 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_hidden);
3001 }
3002 for s in self.inputs.elided {
3003 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_elided);
3004 }
3005 for s in self.inputs.named {
3006 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_input_named);
3007 }
3008
3009 for s in self.outputs.hidden {
3010 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_hidden);
3011 }
3012 for s in self.outputs.elided {
3013 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_elided);
3014 }
3015 for s in self.outputs.named {
3016 diag.span_label(s, fluent::lint_mismatched_lifetime_syntaxes_output_named);
3017 }
3018
3019 diag.help(fluent::lint_mismatched_lifetime_syntaxes_help);
3020
3021 let mut suggestions = self.suggestions.into_iter();
3022 if let Some(s) = suggestions.next() {
3023 diag.subdiagnostic(s);
3024
3025 for mut s in suggestions {
3026 s.make_optional_alternative();
3027 diag.subdiagnostic(s);
3028 }
3029 }
3030 }
3031}
3032
3033#[derive(Debug)]
3034pub(crate) enum MismatchedLifetimeSyntaxesSuggestion {
3035 Implicit {
3036 suggestions: Vec<Span>,
3037 optional_alternative: bool,
3038 },
3039
3040 Mixed {
3041 implicit_suggestions: Vec<Span>,
3042 explicit_anonymous_suggestions: Vec<(Span, String)>,
3043 optional_alternative: bool,
3044 },
3045
3046 Explicit {
3047 lifetime_name: String,
3048 suggestions: Vec<(Span, String)>,
3049 optional_alternative: bool,
3050 },
3051}
3052
3053impl MismatchedLifetimeSyntaxesSuggestion {
3054 fn make_optional_alternative(&mut self) {
3055 use MismatchedLifetimeSyntaxesSuggestion::*;
3056
3057 let optional_alternative = match self {
3058 Implicit { optional_alternative, .. }
3059 | Mixed { optional_alternative, .. }
3060 | Explicit { optional_alternative, .. } => optional_alternative,
3061 };
3062
3063 *optional_alternative = true;
3064 }
3065}
3066
3067impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
3068 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
3069 use MismatchedLifetimeSyntaxesSuggestion::*;
3070
3071 let style = |optional_alternative| {
3072 if optional_alternative {
3073 SuggestionStyle::CompletelyHidden
3074 } else {
3075 SuggestionStyle::ShowAlways
3076 }
3077 };
3078
3079 let applicability = |optional_alternative| {
3080 if optional_alternative {
3083 Applicability::MaybeIncorrect
3084 } else {
3085 Applicability::MachineApplicable
3086 }
3087 };
3088
3089 match self {
3090 Implicit { suggestions, optional_alternative } => {
3091 let suggestions = suggestions.into_iter().map(|s| (s, String::new())).collect();
3092 diag.multipart_suggestion_with_style(
3093 fluent::lint_mismatched_lifetime_syntaxes_suggestion_implicit,
3094 suggestions,
3095 applicability(optional_alternative),
3096 style(optional_alternative),
3097 );
3098 }
3099
3100 Mixed {
3101 implicit_suggestions,
3102 explicit_anonymous_suggestions,
3103 optional_alternative,
3104 } => {
3105 let message = if implicit_suggestions.is_empty() {
3106 fluent::lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths
3107 } else {
3108 fluent::lint_mismatched_lifetime_syntaxes_suggestion_mixed
3109 };
3110
3111 let implicit_suggestions =
3112 implicit_suggestions.into_iter().map(|s| (s, String::new()));
3113
3114 let suggestions =
3115 implicit_suggestions.chain(explicit_anonymous_suggestions).collect();
3116
3117 diag.multipart_suggestion_with_style(
3118 message,
3119 suggestions,
3120 applicability(optional_alternative),
3121 style(optional_alternative),
3122 );
3123 }
3124
3125 Explicit { lifetime_name, suggestions, optional_alternative } => {
3126 diag.arg("lifetime_name", lifetime_name);
3127 let msg = diag.eagerly_translate(
3128 fluent::lint_mismatched_lifetime_syntaxes_suggestion_explicit,
3129 );
3130 diag.remove_arg("lifetime_name");
3131 diag.multipart_suggestion_with_style(
3132 msg,
3133 suggestions,
3134 applicability(optional_alternative),
3135 style(optional_alternative),
3136 );
3137 }
3138 }
3139 }
3140}
3141
3142#[derive(LintDiagnostic)]
3143#[diag(lint_empty_attribute)]
3144#[note]
3145pub(crate) struct EmptyAttributeList {
3146 #[suggestion(code = "", applicability = "machine-applicable")]
3147 pub attr_span: Span,
3148 pub attr_path: String,
3149 pub valid_without_list: bool,
3150}
3151
3152#[derive(LintDiagnostic)]
3153#[diag(lint_invalid_target)]
3154#[warning]
3155#[help]
3156pub(crate) struct InvalidTargetLint {
3157 pub name: String,
3158 pub target: &'static str,
3159 pub applied: DiagArgValue,
3160 pub only: &'static str,
3161 #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
3162 pub attr_span: Span,
3163}
3164
3165#[derive(LintDiagnostic)]
3166#[diag(lint_invalid_style)]
3167pub(crate) struct InvalidAttrStyle {
3168 pub name: String,
3169 pub is_used_as_inner: bool,
3170 #[note]
3171 pub target_span: Option<Span>,
3172 pub target: &'static str,
3173}
3174
3175#[derive(LintDiagnostic)]
3176#[diag(lint_unused_duplicate)]
3177pub(crate) struct UnusedDuplicate {
3178 #[suggestion(code = "", applicability = "machine-applicable")]
3179 pub this: Span,
3180 #[note]
3181 pub other: Span,
3182 #[warning]
3183 pub warning: bool,
3184}
3185
3186#[derive(LintDiagnostic)]
3187#[diag(lint_unsafe_attr_outside_unsafe)]
3188pub(crate) struct UnsafeAttrOutsideUnsafeLint {
3189 #[label]
3190 pub span: Span,
3191 #[subdiagnostic]
3192 pub suggestion: Option<UnsafeAttrOutsideUnsafeSuggestion>,
3193}
3194
3195#[derive(Subdiagnostic)]
3196#[multipart_suggestion(
3197 lint_unsafe_attr_outside_unsafe_suggestion,
3198 applicability = "machine-applicable"
3199)]
3200pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
3201 #[suggestion_part(code = "unsafe(")]
3202 pub left: Span,
3203 #[suggestion_part(code = ")")]
3204 pub right: Span,
3205}
3206
3207#[derive(LintDiagnostic)]
3208#[diag(lint_unused_visibilities)]
3209#[note]
3210pub(crate) struct UnusedVisibility {
3211 #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
3212 pub span: Span,
3213}
3214
3215#[derive(LintDiagnostic)]
3216#[diag(lint_doc_alias_duplicated)]
3217pub(crate) struct DocAliasDuplicated {
3218 #[label]
3219 pub first_defn: Span,
3220}
3221
3222#[derive(LintDiagnostic)]
3223#[diag(lint_doc_auto_cfg_expects_hide_or_show)]
3224pub(crate) struct DocAutoCfgExpectsHideOrShow;
3225
3226#[derive(LintDiagnostic)]
3227#[diag(lint_doc_auto_cfg_hide_show_unexpected_item)]
3228pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
3229 pub attr_name: Symbol,
3230}
3231
3232#[derive(LintDiagnostic)]
3233#[diag(lint_doc_auto_cfg_hide_show_expects_list)]
3234pub(crate) struct DocAutoCfgHideShowExpectsList {
3235 pub attr_name: Symbol,
3236}
3237
3238#[derive(LintDiagnostic)]
3239#[diag(lint_doc_invalid)]
3240pub(crate) struct DocInvalid;
3241
3242#[derive(LintDiagnostic)]
3243#[diag(lint_doc_unknown_include)]
3244pub(crate) struct DocUnknownInclude {
3245 pub inner: &'static str,
3246 pub value: Symbol,
3247 #[suggestion(code = "#{inner}[doc = include_str!(\"{value}\")]")]
3248 pub sugg: (Span, Applicability),
3249}
3250
3251#[derive(LintDiagnostic)]
3252#[diag(lint_doc_unknown_spotlight)]
3253#[note]
3254#[note(lint_no_op_note)]
3255pub(crate) struct DocUnknownSpotlight {
3256 #[suggestion(style = "short", applicability = "machine-applicable", code = "notable_trait")]
3257 pub sugg_span: Span,
3258}
3259
3260#[derive(LintDiagnostic)]
3261#[diag(lint_doc_unknown_passes)]
3262#[note]
3263#[note(lint_no_op_note)]
3264pub(crate) struct DocUnknownPasses {
3265 pub name: Symbol,
3266 #[label]
3267 pub note_span: Span,
3268}
3269
3270#[derive(LintDiagnostic)]
3271#[diag(lint_doc_unknown_plugins)]
3272#[note]
3273#[note(lint_no_op_note)]
3274pub(crate) struct DocUnknownPlugins {
3275 #[label]
3276 pub label_span: Span,
3277}
3278
3279#[derive(LintDiagnostic)]
3280#[diag(lint_doc_unknown_any)]
3281pub(crate) struct DocUnknownAny {
3282 pub name: Symbol,
3283}
3284
3285#[derive(LintDiagnostic)]
3286#[diag(lint_doc_auto_cfg_wrong_literal)]
3287pub(crate) struct DocAutoCfgWrongLiteral;
3288
3289#[derive(LintDiagnostic)]
3290#[diag(lint_doc_test_takes_list)]
3291pub(crate) struct DocTestTakesList;
3292
3293#[derive(LintDiagnostic)]
3294#[diag(lint_doc_test_unknown)]
3295pub(crate) struct DocTestUnknown {
3296 pub name: Symbol,
3297}
3298
3299#[derive(LintDiagnostic)]
3300#[diag(lint_doc_test_literal)]
3301pub(crate) struct DocTestLiteral;