2 fluent_generated
as fluent
,
3 thir
::pattern
::{deconstruct_pat::WitnessPat, MatchCheckCtxt}
,
6 error_code
, AddToDiagnostic
, Applicability
, Diagnostic
, DiagnosticBuilder
, ErrorGuaranteed
,
7 Handler
, IntoDiagnostic
, MultiSpan
, SubdiagnosticMessage
,
9 use rustc_macros
::{Diagnostic, LintDiagnostic, Subdiagnostic}
;
10 use rustc_middle
::thir
::Pat
;
11 use rustc_middle
::ty
::{self, Ty}
;
12 use rustc_span
::symbol
::Symbol
;
15 #[derive(LintDiagnostic)]
16 #[diag(mir_build_unconditional_recursion)]
18 pub struct UnconditionalRecursion
{
21 #[label(mir_build_unconditional_recursion_call_site_label)]
22 pub call_sites
: Vec
<Span
>,
25 #[derive(LintDiagnostic)]
26 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe)]
28 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe
<'a
> {
31 pub function
: &'a
str,
33 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
36 #[derive(LintDiagnostic)]
37 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe_nameless)]
39 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafeNameless
{
43 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
46 #[derive(LintDiagnostic)]
47 #[diag(mir_build_unsafe_op_in_unsafe_fn_inline_assembly_requires_unsafe)]
49 pub struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe
{
53 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
56 #[derive(LintDiagnostic)]
57 #[diag(mir_build_unsafe_op_in_unsafe_fn_initializing_type_with_requires_unsafe)]
59 pub struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe
{
63 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
66 #[derive(LintDiagnostic)]
67 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutable_static_requires_unsafe)]
69 pub struct UnsafeOpInUnsafeFnUseOfMutableStaticRequiresUnsafe
{
73 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
76 #[derive(LintDiagnostic)]
77 #[diag(mir_build_unsafe_op_in_unsafe_fn_extern_static_requires_unsafe)]
79 pub struct UnsafeOpInUnsafeFnUseOfExternStaticRequiresUnsafe
{
83 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
86 #[derive(LintDiagnostic)]
87 #[diag(mir_build_unsafe_op_in_unsafe_fn_deref_raw_pointer_requires_unsafe)]
89 pub struct UnsafeOpInUnsafeFnDerefOfRawPointerRequiresUnsafe
{
93 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
96 #[derive(LintDiagnostic)]
97 #[diag(mir_build_unsafe_op_in_unsafe_fn_union_field_requires_unsafe)]
99 pub struct UnsafeOpInUnsafeFnAccessToUnionFieldRequiresUnsafe
{
103 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
106 #[derive(LintDiagnostic)]
107 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutation_of_layout_constrained_field_requires_unsafe)]
109 pub struct UnsafeOpInUnsafeFnMutationOfLayoutConstrainedFieldRequiresUnsafe
{
113 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
116 #[derive(LintDiagnostic)]
117 #[diag(mir_build_unsafe_op_in_unsafe_fn_borrow_of_layout_constrained_field_requires_unsafe)]
118 pub struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe
{
122 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
125 #[derive(LintDiagnostic)]
126 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe)]
128 pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe
<'a
> {
131 pub function
: &'a
str,
133 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
136 #[derive(Diagnostic)]
137 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe, code = "E0133")]
139 pub struct CallToUnsafeFunctionRequiresUnsafe
<'a
> {
143 pub function
: &'a
str,
145 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
148 #[derive(Diagnostic)]
149 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_nameless, code = "E0133")]
151 pub struct CallToUnsafeFunctionRequiresUnsafeNameless
{
156 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
159 #[derive(Diagnostic)]
160 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
162 pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed
<'a
> {
166 pub function
: &'a
str,
168 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
171 #[derive(Diagnostic)]
173 mir_build_call_to_unsafe_fn_requires_unsafe_nameless_unsafe_op_in_unsafe_fn_allowed
,
177 pub struct CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed
{
182 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
185 #[derive(Diagnostic)]
186 #[diag(mir_build_inline_assembly_requires_unsafe, code = "E0133")]
188 pub struct UseOfInlineAssemblyRequiresUnsafe
{
193 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
196 #[derive(Diagnostic)]
197 #[diag(mir_build_inline_assembly_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
199 pub struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
204 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
207 #[derive(Diagnostic)]
208 #[diag(mir_build_initializing_type_with_requires_unsafe, code = "E0133")]
210 pub struct InitializingTypeWithRequiresUnsafe
{
215 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
218 #[derive(Diagnostic)]
220 mir_build_initializing_type_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
224 pub struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
229 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
232 #[derive(Diagnostic)]
233 #[diag(mir_build_mutable_static_requires_unsafe, code = "E0133")]
235 pub struct UseOfMutableStaticRequiresUnsafe
{
240 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
243 #[derive(Diagnostic)]
244 #[diag(mir_build_mutable_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
246 pub struct UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
251 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
254 #[derive(Diagnostic)]
255 #[diag(mir_build_extern_static_requires_unsafe, code = "E0133")]
257 pub struct UseOfExternStaticRequiresUnsafe
{
262 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
265 #[derive(Diagnostic)]
266 #[diag(mir_build_extern_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
268 pub struct UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
273 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
276 #[derive(Diagnostic)]
277 #[diag(mir_build_deref_raw_pointer_requires_unsafe, code = "E0133")]
279 pub struct DerefOfRawPointerRequiresUnsafe
{
284 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
287 #[derive(Diagnostic)]
288 #[diag(mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
290 pub struct DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
295 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
298 #[derive(Diagnostic)]
299 #[diag(mir_build_union_field_requires_unsafe, code = "E0133")]
301 pub struct AccessToUnionFieldRequiresUnsafe
{
306 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
309 #[derive(Diagnostic)]
310 #[diag(mir_build_union_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
312 pub struct AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
317 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
320 #[derive(Diagnostic)]
321 #[diag(mir_build_mutation_of_layout_constrained_field_requires_unsafe, code = "E0133")]
323 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafe
{
328 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
331 #[derive(Diagnostic)]
333 mir_build_mutation_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
337 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
342 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
345 #[derive(Diagnostic)]
346 #[diag(mir_build_borrow_of_layout_constrained_field_requires_unsafe, code = "E0133")]
348 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafe
{
353 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
356 #[derive(Diagnostic)]
358 mir_build_borrow_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
362 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
367 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
370 #[derive(Diagnostic)]
371 #[diag(mir_build_call_to_fn_with_requires_unsafe, code = "E0133")]
373 pub struct CallToFunctionWithRequiresUnsafe
<'a
> {
377 pub function
: &'a
str,
379 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
382 #[derive(Diagnostic)]
383 #[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
385 pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed
<'a
> {
389 pub function
: &'a
str,
391 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
394 #[derive(Subdiagnostic)]
395 #[label(mir_build_unsafe_not_inherited)]
396 pub struct UnsafeNotInheritedNote
{
401 pub struct UnsafeNotInheritedLintNote
{
402 pub signature_span
: Span
,
406 impl AddToDiagnostic
for UnsafeNotInheritedLintNote
{
407 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
409 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
411 diag
.span_note(self.signature_span
, fluent
::mir_build_unsafe_fn_safe_body
);
412 let body_start
= self.body_span
.shrink_to_lo();
413 let body_end
= self.body_span
.shrink_to_hi();
414 diag
.tool_only_multipart_suggestion(
415 fluent
::mir_build_wrap_suggestion
,
416 vec
![(body_start
, "{ unsafe ".into()), (body_end, "}".into())],
417 Applicability
::MaybeIncorrect
,
422 #[derive(LintDiagnostic)]
423 #[diag(mir_build_unused_unsafe)]
424 pub struct UnusedUnsafe
{
428 pub enclosing
: Option
<UnusedUnsafeEnclosing
>,
431 #[derive(Subdiagnostic)]
432 pub enum UnusedUnsafeEnclosing
{
433 #[label(mir_build_unused_unsafe_enclosing_block_label)]
440 pub(crate) struct NonExhaustivePatternsTypeNotEmpty
<'p
, 'tcx
, 'm
> {
441 pub cx
: &'m MatchCheckCtxt
<'p
, 'tcx
>,
447 impl<'a
> IntoDiagnostic
<'a
> for NonExhaustivePatternsTypeNotEmpty
<'_
, '_
, '_
> {
448 fn into_diagnostic(self, handler
: &'a Handler
) -> DiagnosticBuilder
<'_
, ErrorGuaranteed
> {
449 let mut diag
= handler
.struct_span_err_with_code(
451 fluent
::mir_build_non_exhaustive_patterns_type_not_empty
,
455 let peeled_ty
= self.ty
.peel_refs();
456 diag
.set_arg("ty", self.ty
);
457 diag
.set_arg("peeled_ty", peeled_ty
);
459 if let ty
::Adt(def
, _
) = peeled_ty
.kind() {
464 .get_if_local(def
.did())
465 .and_then(|node
| node
.ident())
466 .map(|ident
| ident
.span
)
467 .unwrap_or_else(|| self.cx
.tcx
.def_span(def
.did()));
469 // workaround to make test pass
470 let mut span
: MultiSpan
= def_span
.into();
471 span
.push_span_label(def_span
, "");
473 diag
.span_note(span
, fluent
::mir_build_def_note
);
476 let is_variant_list_non_exhaustive
= matches
!(self.ty
.kind(),
477 ty
::Adt(def
, _
) if def
.is_variant_list_non_exhaustive() && !def
.did().is_local());
478 if is_variant_list_non_exhaustive
{
479 diag
.note(fluent
::mir_build_non_exhaustive_type_note
);
481 diag
.note(fluent
::mir_build_type_note
);
484 if let ty
::Ref(_
, sub_ty
, _
) = self.ty
.kind() {
485 if !sub_ty
.is_inhabited_from(self.cx
.tcx
, self.cx
.module
, self.cx
.param_env
) {
486 diag
.note(fluent
::mir_build_reference_note
);
490 let mut suggestion
= None
;
491 let sm
= self.cx
.tcx
.sess
.source_map();
492 if self.span
.eq_ctxt(self.expr_span
) {
493 // Get the span for the empty match body `{}`.
494 let (indentation
, more
) = if let Some(snippet
) = sm
.indentation_before(self.span
) {
495 (format
!("\n{snippet}"), " ")
497 (" ".to_string(), "")
500 self.span
.shrink_to_hi().with_hi(self.expr_span
.hi()),
501 format
!(" {{{indentation}{more}_ => todo!(),{indentation}}}",),
505 if let Some((span
, sugg
)) = suggestion
{
506 diag
.span_suggestion_verbose(
508 fluent
::mir_build_suggestion
,
510 Applicability
::HasPlaceholders
,
513 diag
.help(fluent
::mir_build_help
);
520 #[derive(Subdiagnostic)]
521 #[note(mir_build_non_exhaustive_match_all_arms_guarded)]
522 pub struct NonExhaustiveMatchAllArmsGuarded
;
524 #[derive(Diagnostic)]
525 #[diag(mir_build_static_in_pattern, code = "E0158")]
526 pub struct StaticInPattern
{
531 #[derive(Diagnostic)]
532 #[diag(mir_build_assoc_const_in_pattern, code = "E0158")]
533 pub struct AssocConstInPattern
{
538 #[derive(Diagnostic)]
539 #[diag(mir_build_const_param_in_pattern, code = "E0158")]
540 pub struct ConstParamInPattern
{
545 #[derive(Diagnostic)]
546 #[diag(mir_build_non_const_path, code = "E0080")]
547 pub struct NonConstPath
{
552 #[derive(LintDiagnostic)]
553 #[diag(mir_build_unreachable_pattern)]
554 pub struct UnreachablePattern
{
556 pub span
: Option
<Span
>,
557 #[label(mir_build_catchall_label)]
558 pub catchall
: Option
<Span
>,
561 #[derive(Diagnostic)]
562 #[diag(mir_build_const_pattern_depends_on_generic_parameter)]
563 pub struct ConstPatternDependsOnGenericParameter
{
568 #[derive(Diagnostic)]
569 #[diag(mir_build_could_not_eval_const_pattern)]
570 pub struct CouldNotEvalConstPattern
{
575 #[derive(Diagnostic)]
576 #[diag(mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper, code = "E0030")]
577 pub struct LowerRangeBoundMustBeLessThanOrEqualToUpper
{
581 #[note(mir_build_teach_note)]
582 pub teach
: Option
<()>,
585 #[derive(Diagnostic)]
586 #[diag(mir_build_literal_in_range_out_of_bounds)]
587 pub struct LiteralOutOfRange
<'tcx
> {
596 #[derive(Diagnostic)]
597 #[diag(mir_build_lower_range_bound_must_be_less_than_upper, code = "E0579")]
598 pub struct LowerRangeBoundMustBeLessThanUpper
{
603 #[derive(LintDiagnostic)]
604 #[diag(mir_build_leading_irrefutable_let_patterns)]
607 pub struct LeadingIrrefutableLetPatterns
{
611 #[derive(LintDiagnostic)]
612 #[diag(mir_build_trailing_irrefutable_let_patterns)]
615 pub struct TrailingIrrefutableLetPatterns
{
619 #[derive(LintDiagnostic)]
620 #[diag(mir_build_bindings_with_variant_name, code = "E0170")]
621 pub struct BindingsWithVariantName
{
622 #[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
623 pub suggestion
: Option
<Span
>,
628 #[derive(LintDiagnostic)]
629 #[diag(mir_build_irrefutable_let_patterns_if_let)]
632 pub struct IrrefutableLetPatternsIfLet
{
636 #[derive(LintDiagnostic)]
637 #[diag(mir_build_irrefutable_let_patterns_if_let_guard)]
640 pub struct IrrefutableLetPatternsIfLetGuard
{
644 #[derive(LintDiagnostic)]
645 #[diag(mir_build_irrefutable_let_patterns_let_else)]
648 pub struct IrrefutableLetPatternsLetElse
{
652 #[derive(LintDiagnostic)]
653 #[diag(mir_build_irrefutable_let_patterns_while_let)]
656 pub struct IrrefutableLetPatternsWhileLet
{
660 #[derive(Diagnostic)]
661 #[diag(mir_build_borrow_of_moved_value)]
662 pub struct BorrowOfMovedValue
<'tcx
> {
665 #[label(mir_build_occurs_because_label)]
666 pub binding_span
: Span
,
667 #[label(mir_build_value_borrowed_label)]
668 pub conflicts_ref
: Vec
<Span
>,
671 #[suggestion(code = "ref ", applicability = "machine-applicable")]
672 pub suggest_borrowing
: Option
<Span
>,
675 #[derive(Diagnostic)]
676 #[diag(mir_build_multiple_mut_borrows)]
677 pub struct MultipleMutBorrows
{
681 pub occurrences
: Vec
<Conflict
>,
684 #[derive(Diagnostic)]
685 #[diag(mir_build_already_borrowed)]
686 pub struct AlreadyBorrowed
{
690 pub occurrences
: Vec
<Conflict
>,
693 #[derive(Diagnostic)]
694 #[diag(mir_build_already_mut_borrowed)]
695 pub struct AlreadyMutBorrowed
{
699 pub occurrences
: Vec
<Conflict
>,
702 #[derive(Diagnostic)]
703 #[diag(mir_build_moved_while_borrowed)]
704 pub struct MovedWhileBorrowed
{
708 pub occurrences
: Vec
<Conflict
>,
711 #[derive(Subdiagnostic)]
713 #[label(mir_build_mutable_borrow)]
719 #[label(mir_build_borrow)]
725 #[label(mir_build_moved)]
733 #[derive(Diagnostic)]
734 #[diag(mir_build_union_pattern)]
735 pub struct UnionPattern
{
740 #[derive(Diagnostic)]
741 #[diag(mir_build_type_not_structural)]
742 #[note(mir_build_type_not_structural_tip)]
743 #[note(mir_build_type_not_structural_more_info)]
744 pub struct TypeNotStructural
<'tcx
> {
747 pub non_sm_ty
: Ty
<'tcx
>,
750 #[derive(Diagnostic)]
751 #[diag(mir_build_invalid_pattern)]
752 pub struct InvalidPattern
<'tcx
> {
755 pub non_sm_ty
: Ty
<'tcx
>,
758 #[derive(Diagnostic)]
759 #[diag(mir_build_unsized_pattern)]
760 pub struct UnsizedPattern
<'tcx
> {
763 pub non_sm_ty
: Ty
<'tcx
>,
766 #[derive(LintDiagnostic)]
767 #[diag(mir_build_float_pattern)]
768 pub struct FloatPattern
;
770 #[derive(LintDiagnostic)]
771 #[diag(mir_build_pointer_pattern)]
772 pub struct PointerPattern
;
774 #[derive(LintDiagnostic)]
775 #[diag(mir_build_indirect_structural_match)]
776 #[note(mir_build_type_not_structural_tip)]
777 #[note(mir_build_type_not_structural_more_info)]
778 pub struct IndirectStructuralMatch
<'tcx
> {
779 pub non_sm_ty
: Ty
<'tcx
>,
782 #[derive(LintDiagnostic)]
783 #[diag(mir_build_nontrivial_structural_match)]
784 #[note(mir_build_type_not_structural_tip)]
785 #[note(mir_build_type_not_structural_more_info)]
786 pub struct NontrivialStructuralMatch
<'tcx
> {
787 pub non_sm_ty
: Ty
<'tcx
>,
790 #[derive(LintDiagnostic)]
791 #[diag(mir_build_non_partial_eq_match)]
792 pub struct NonPartialEqMatch
<'tcx
> {
793 pub non_peq_ty
: Ty
<'tcx
>,
796 #[derive(LintDiagnostic)]
797 #[diag(mir_build_overlapping_range_endpoints)]
799 pub struct OverlappingRangeEndpoints
<'tcx
> {
800 #[label(mir_build_range)]
803 pub overlap
: Vec
<Overlap
<'tcx
>>,
806 pub struct Overlap
<'tcx
> {
808 pub range
: Pat
<'tcx
>,
811 impl<'tcx
> AddToDiagnostic
for Overlap
<'tcx
> {
812 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
814 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
816 let Overlap { span, range }
= self;
818 // FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
819 // does not support `#[subdiagnostic(eager)]`...
820 let message
= format
!("this range overlaps on `{range}`...");
821 diag
.span_label(span
, message
);
825 #[derive(LintDiagnostic)]
826 #[diag(mir_build_non_exhaustive_omitted_pattern)]
829 pub(crate) struct NonExhaustiveOmittedPattern
<'tcx
> {
830 pub scrut_ty
: Ty
<'tcx
>,
832 pub uncovered
: Uncovered
<'tcx
>,
835 #[derive(LintDiagnostic)]
836 #[diag(mir_build_non_exhaustive_omitted_pattern_lint_on_arm)]
838 pub(crate) struct NonExhaustiveOmittedPatternLintOnArm
{
841 #[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")]
842 pub suggest_lint_on_match
: Option
<Span
>,
843 pub lint_level
: &'
static str,
844 pub lint_name
: &'
static str,
847 #[derive(Subdiagnostic)]
848 #[label(mir_build_uncovered)]
849 pub(crate) struct Uncovered
<'tcx
> {
853 witness_1
: Pat
<'tcx
>,
854 witness_2
: Pat
<'tcx
>,
855 witness_3
: Pat
<'tcx
>,
859 impl<'tcx
> Uncovered
<'tcx
> {
862 cx
: &MatchCheckCtxt
<'p
, 'tcx
>,
863 witnesses
: Vec
<WitnessPat
<'tcx
>>,
865 let witness_1
= witnesses
.get(0).unwrap().to_diagnostic_pat(cx
);
868 count
: witnesses
.len(),
869 // Substitute dummy values if witnesses is smaller than 3. These will never be read.
872 .map(|w
| w
.to_diagnostic_pat(cx
))
873 .unwrap_or_else(|| witness_1
.clone()),
876 .map(|w
| w
.to_diagnostic_pat(cx
))
877 .unwrap_or_else(|| witness_1
.clone()),
879 remainder
: witnesses
.len().saturating_sub(3),
884 #[derive(Diagnostic)]
885 #[diag(mir_build_pattern_not_covered, code = "E0005")]
886 pub(crate) struct PatternNotCovered
<'s
, 'tcx
> {
891 pub uncovered
: Uncovered
<'tcx
>,
893 pub inform
: Option
<Inform
>,
895 pub interpreted_as_const
: Option
<InterpretedAsConst
>,
897 pub adt_defined_here
: Option
<AdtDefinedHere
<'tcx
>>,
898 #[note(mir_build_privately_uninhabited)]
899 pub witness_1_is_privately_uninhabited
: Option
<()>,
900 #[note(mir_build_pattern_ty)]
902 pub pattern_ty
: Ty
<'tcx
>,
904 pub let_suggestion
: Option
<SuggestLet
>,
906 pub misc_suggestion
: Option
<MiscPatternSuggestion
>,
909 #[derive(Subdiagnostic)]
910 #[note(mir_build_inform_irrefutable)]
911 #[note(mir_build_more_information)]
914 pub struct AdtDefinedHere
<'tcx
> {
915 pub adt_def_span
: Span
,
917 pub variants
: Vec
<Variant
>,
924 impl<'tcx
> AddToDiagnostic
for AdtDefinedHere
<'tcx
> {
925 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
927 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
929 diag
.set_arg("ty", self.ty
);
930 let mut spans
= MultiSpan
::from(self.adt_def_span
);
932 for Variant { span }
in self.variants
{
933 spans
.push_span_label(span
, fluent
::mir_build_variant_defined_here
);
936 diag
.span_note(spans
, fluent
::mir_build_adt_defined_here
);
940 #[derive(Subdiagnostic)]
942 mir_build_interpreted_as_const
,
943 code
= "{variable}_var",
944 applicability
= "maybe-incorrect"
946 #[label(mir_build_confused)]
947 pub struct InterpretedAsConst
{
950 pub variable
: String
,
953 #[derive(Subdiagnostic)]
954 pub enum SuggestLet
{
955 #[multipart_suggestion(mir_build_suggest_if_let, applicability = "has-placeholders")]
957 #[suggestion_part(code = "if ")]
959 #[suggestion_part(code = " {{ todo!() }}")]
964 mir_build_suggest_let_else
,
965 code
= " else {{ todo!() }}",
966 applicability
= "has-placeholders"
975 #[derive(Subdiagnostic)]
976 pub enum MiscPatternSuggestion
{
978 mir_build_suggest_attempted_int_lit
,
980 applicability
= "maybe-incorrect"
982 AttemptedIntegerLiteral
{
988 #[derive(Diagnostic)]
989 #[diag(mir_build_rustc_box_attribute_error)]
990 pub struct RustcBoxAttributeError
{
994 pub reason
: RustcBoxAttrReason
,
997 #[derive(Subdiagnostic)]
998 pub enum RustcBoxAttrReason
{
999 #[note(mir_build_attributes)]
1001 #[note(mir_build_not_box)]
1003 #[note(mir_build_missing_box)]