1 use crate::fluent_generated
as fluent
;
2 use rustc_errors
::DiagnosticArgValue
;
4 error_code
, AddToDiagnostic
, Applicability
, DiagCtxt
, Diagnostic
, DiagnosticBuilder
,
5 ErrorGuaranteed
, IntoDiagnostic
, MultiSpan
, SubdiagnosticMessage
,
7 use rustc_macros
::{Diagnostic, LintDiagnostic, Subdiagnostic}
;
8 use rustc_middle
::ty
::{self, Ty}
;
9 use rustc_pattern_analysis
::{errors::Uncovered, rustc::RustcMatchCheckCtxt}
;
10 use rustc_span
::symbol
::Symbol
;
13 #[derive(LintDiagnostic)]
14 #[diag(mir_build_unconditional_recursion)]
16 pub struct UnconditionalRecursion
{
19 #[label(mir_build_unconditional_recursion_call_site_label)]
20 pub call_sites
: Vec
<Span
>,
23 #[derive(LintDiagnostic)]
24 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe)]
26 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe
<'a
> {
29 pub function
: &'a
str,
31 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
34 #[derive(LintDiagnostic)]
35 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe_nameless)]
37 pub struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafeNameless
{
41 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
44 #[derive(LintDiagnostic)]
45 #[diag(mir_build_unsafe_op_in_unsafe_fn_inline_assembly_requires_unsafe)]
47 pub struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe
{
51 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
54 #[derive(LintDiagnostic)]
55 #[diag(mir_build_unsafe_op_in_unsafe_fn_initializing_type_with_requires_unsafe)]
57 pub struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe
{
61 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
64 #[derive(LintDiagnostic)]
65 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutable_static_requires_unsafe)]
67 pub struct UnsafeOpInUnsafeFnUseOfMutableStaticRequiresUnsafe
{
71 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
74 #[derive(LintDiagnostic)]
75 #[diag(mir_build_unsafe_op_in_unsafe_fn_extern_static_requires_unsafe)]
77 pub struct UnsafeOpInUnsafeFnUseOfExternStaticRequiresUnsafe
{
81 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
84 #[derive(LintDiagnostic)]
85 #[diag(mir_build_unsafe_op_in_unsafe_fn_deref_raw_pointer_requires_unsafe)]
87 pub struct UnsafeOpInUnsafeFnDerefOfRawPointerRequiresUnsafe
{
91 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
94 #[derive(LintDiagnostic)]
95 #[diag(mir_build_unsafe_op_in_unsafe_fn_union_field_requires_unsafe)]
97 pub struct UnsafeOpInUnsafeFnAccessToUnionFieldRequiresUnsafe
{
101 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
104 #[derive(LintDiagnostic)]
105 #[diag(mir_build_unsafe_op_in_unsafe_fn_mutation_of_layout_constrained_field_requires_unsafe)]
107 pub struct UnsafeOpInUnsafeFnMutationOfLayoutConstrainedFieldRequiresUnsafe
{
111 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
114 #[derive(LintDiagnostic)]
115 #[diag(mir_build_unsafe_op_in_unsafe_fn_borrow_of_layout_constrained_field_requires_unsafe)]
116 pub struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe
{
120 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
123 #[derive(LintDiagnostic)]
124 #[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe)]
126 pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe
<'a
> {
129 pub function
: &'a
str,
130 pub missing_target_features
: DiagnosticArgValue
<'a
>,
131 pub missing_target_features_count
: usize,
133 pub note
: Option
<()>,
134 pub build_target_features
: DiagnosticArgValue
<'a
>,
135 pub build_target_features_count
: usize,
137 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedLintNote
>,
140 #[derive(Diagnostic)]
141 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe, code = "E0133")]
143 pub struct CallToUnsafeFunctionRequiresUnsafe
<'a
> {
147 pub function
: &'a
str,
149 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
152 #[derive(Diagnostic)]
153 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_nameless, code = "E0133")]
155 pub struct CallToUnsafeFunctionRequiresUnsafeNameless
{
160 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
163 #[derive(Diagnostic)]
164 #[diag(mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
166 pub struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed
<'a
> {
170 pub function
: &'a
str,
172 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
175 #[derive(Diagnostic)]
177 mir_build_call_to_unsafe_fn_requires_unsafe_nameless_unsafe_op_in_unsafe_fn_allowed
,
181 pub struct CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed
{
186 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
189 #[derive(Diagnostic)]
190 #[diag(mir_build_inline_assembly_requires_unsafe, code = "E0133")]
192 pub struct UseOfInlineAssemblyRequiresUnsafe
{
197 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
200 #[derive(Diagnostic)]
201 #[diag(mir_build_inline_assembly_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
203 pub struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
208 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
211 #[derive(Diagnostic)]
212 #[diag(mir_build_initializing_type_with_requires_unsafe, code = "E0133")]
214 pub struct InitializingTypeWithRequiresUnsafe
{
219 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
222 #[derive(Diagnostic)]
224 mir_build_initializing_type_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
228 pub struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
233 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
236 #[derive(Diagnostic)]
237 #[diag(mir_build_mutable_static_requires_unsafe, code = "E0133")]
239 pub struct UseOfMutableStaticRequiresUnsafe
{
244 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
247 #[derive(Diagnostic)]
248 #[diag(mir_build_mutable_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
250 pub struct UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
255 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
258 #[derive(Diagnostic)]
259 #[diag(mir_build_extern_static_requires_unsafe, code = "E0133")]
261 pub struct UseOfExternStaticRequiresUnsafe
{
266 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
269 #[derive(Diagnostic)]
270 #[diag(mir_build_extern_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
272 pub struct UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
277 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
280 #[derive(Diagnostic)]
281 #[diag(mir_build_deref_raw_pointer_requires_unsafe, code = "E0133")]
283 pub struct DerefOfRawPointerRequiresUnsafe
{
288 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
291 #[derive(Diagnostic)]
292 #[diag(mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
294 pub struct DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
299 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
302 #[derive(Diagnostic)]
303 #[diag(mir_build_union_field_requires_unsafe, code = "E0133")]
305 pub struct AccessToUnionFieldRequiresUnsafe
{
310 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
313 #[derive(Diagnostic)]
314 #[diag(mir_build_union_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
316 pub struct AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
321 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
324 #[derive(Diagnostic)]
325 #[diag(mir_build_mutation_of_layout_constrained_field_requires_unsafe, code = "E0133")]
327 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafe
{
332 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
335 #[derive(Diagnostic)]
337 mir_build_mutation_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
341 pub struct MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
346 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
349 #[derive(Diagnostic)]
350 #[diag(mir_build_borrow_of_layout_constrained_field_requires_unsafe, code = "E0133")]
352 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafe
{
357 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
360 #[derive(Diagnostic)]
362 mir_build_borrow_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed
,
366 pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
{
371 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
374 #[derive(Diagnostic)]
375 #[diag(mir_build_call_to_fn_with_requires_unsafe, code = "E0133")]
377 pub struct CallToFunctionWithRequiresUnsafe
<'a
> {
381 pub function
: &'a
str,
382 pub missing_target_features
: DiagnosticArgValue
<'a
>,
383 pub missing_target_features_count
: usize,
385 pub note
: Option
<()>,
386 pub build_target_features
: DiagnosticArgValue
<'a
>,
387 pub build_target_features_count
: usize,
389 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
392 #[derive(Diagnostic)]
393 #[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
395 pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed
<'a
> {
399 pub function
: &'a
str,
400 pub missing_target_features
: DiagnosticArgValue
<'a
>,
401 pub missing_target_features_count
: usize,
403 pub note
: Option
<()>,
404 pub build_target_features
: DiagnosticArgValue
<'a
>,
405 pub build_target_features_count
: usize,
407 pub unsafe_not_inherited_note
: Option
<UnsafeNotInheritedNote
>,
410 #[derive(Subdiagnostic)]
411 #[label(mir_build_unsafe_not_inherited)]
412 pub struct UnsafeNotInheritedNote
{
417 pub struct UnsafeNotInheritedLintNote
{
418 pub signature_span
: Span
,
422 impl AddToDiagnostic
for UnsafeNotInheritedLintNote
{
423 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
425 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
427 diag
.span_note(self.signature_span
, fluent
::mir_build_unsafe_fn_safe_body
);
428 let body_start
= self.body_span
.shrink_to_lo();
429 let body_end
= self.body_span
.shrink_to_hi();
430 diag
.tool_only_multipart_suggestion(
431 fluent
::mir_build_wrap_suggestion
,
432 vec
![(body_start
, "{ unsafe ".into()), (body_end, "}".into())],
433 Applicability
::MaybeIncorrect
,
438 #[derive(LintDiagnostic)]
439 #[diag(mir_build_unused_unsafe)]
440 pub struct UnusedUnsafe
{
444 pub enclosing
: Option
<UnusedUnsafeEnclosing
>,
447 #[derive(Subdiagnostic)]
448 pub enum UnusedUnsafeEnclosing
{
449 #[label(mir_build_unused_unsafe_enclosing_block_label)]
456 pub(crate) struct NonExhaustivePatternsTypeNotEmpty
<'p
, 'tcx
, 'm
> {
457 pub cx
: &'m RustcMatchCheckCtxt
<'p
, 'tcx
>,
463 impl<'a
> IntoDiagnostic
<'a
> for NonExhaustivePatternsTypeNotEmpty
<'_
, '_
, '_
> {
464 fn into_diagnostic(self, dcx
: &'a DiagCtxt
) -> DiagnosticBuilder
<'_
, ErrorGuaranteed
> {
465 let mut diag
= dcx
.struct_span_err_with_code(
467 fluent
::mir_build_non_exhaustive_patterns_type_not_empty
,
471 let peeled_ty
= self.ty
.peel_refs();
472 diag
.set_arg("ty", self.ty
);
473 diag
.set_arg("peeled_ty", peeled_ty
);
475 if let ty
::Adt(def
, _
) = peeled_ty
.kind() {
480 .get_if_local(def
.did())
481 .and_then(|node
| node
.ident())
482 .map(|ident
| ident
.span
)
483 .unwrap_or_else(|| self.cx
.tcx
.def_span(def
.did()));
485 // workaround to make test pass
486 let mut span
: MultiSpan
= def_span
.into();
487 span
.push_span_label(def_span
, "");
489 diag
.span_note(span
, fluent
::mir_build_def_note
);
492 let is_variant_list_non_exhaustive
= matches
!(self.ty
.kind(),
493 ty
::Adt(def
, _
) if def
.is_variant_list_non_exhaustive() && !def
.did().is_local());
494 if is_variant_list_non_exhaustive
{
495 diag
.note(fluent
::mir_build_non_exhaustive_type_note
);
497 diag
.note(fluent
::mir_build_type_note
);
500 if let ty
::Ref(_
, sub_ty
, _
) = self.ty
.kind() {
501 if !sub_ty
.is_inhabited_from(self.cx
.tcx
, self.cx
.module
, self.cx
.param_env
) {
502 diag
.note(fluent
::mir_build_reference_note
);
506 let mut suggestion
= None
;
507 let sm
= self.cx
.tcx
.sess
.source_map();
508 if self.span
.eq_ctxt(self.expr_span
) {
509 // Get the span for the empty match body `{}`.
510 let (indentation
, more
) = if let Some(snippet
) = sm
.indentation_before(self.span
) {
511 (format
!("\n{snippet}"), " ")
513 (" ".to_string(), "")
516 self.span
.shrink_to_hi().with_hi(self.expr_span
.hi()),
517 format
!(" {{{indentation}{more}_ => todo!(),{indentation}}}",),
521 if let Some((span
, sugg
)) = suggestion
{
522 diag
.span_suggestion_verbose(
524 fluent
::mir_build_suggestion
,
526 Applicability
::HasPlaceholders
,
529 diag
.help(fluent
::mir_build_help
);
536 #[derive(Subdiagnostic)]
537 #[note(mir_build_non_exhaustive_match_all_arms_guarded)]
538 pub struct NonExhaustiveMatchAllArmsGuarded
;
540 #[derive(Diagnostic)]
541 #[diag(mir_build_static_in_pattern, code = "E0158")]
542 pub struct StaticInPattern
{
547 #[derive(Diagnostic)]
548 #[diag(mir_build_assoc_const_in_pattern, code = "E0158")]
549 pub struct AssocConstInPattern
{
554 #[derive(Diagnostic)]
555 #[diag(mir_build_const_param_in_pattern, code = "E0158")]
556 pub struct ConstParamInPattern
{
561 #[derive(Diagnostic)]
562 #[diag(mir_build_non_const_path, code = "E0080")]
563 pub struct NonConstPath
{
568 #[derive(LintDiagnostic)]
569 #[diag(mir_build_unreachable_pattern)]
570 pub struct UnreachablePattern
{
572 pub span
: Option
<Span
>,
573 #[label(mir_build_catchall_label)]
574 pub catchall
: Option
<Span
>,
577 #[derive(Diagnostic)]
578 #[diag(mir_build_const_pattern_depends_on_generic_parameter)]
579 pub struct ConstPatternDependsOnGenericParameter
{
584 #[derive(Diagnostic)]
585 #[diag(mir_build_could_not_eval_const_pattern)]
586 pub struct CouldNotEvalConstPattern
{
591 #[derive(Diagnostic)]
592 #[diag(mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper, code = "E0030")]
593 pub struct LowerRangeBoundMustBeLessThanOrEqualToUpper
{
597 #[note(mir_build_teach_note)]
598 pub teach
: Option
<()>,
601 #[derive(Diagnostic)]
602 #[diag(mir_build_literal_in_range_out_of_bounds)]
603 pub struct LiteralOutOfRange
<'tcx
> {
612 #[derive(Diagnostic)]
613 #[diag(mir_build_lower_range_bound_must_be_less_than_upper, code = "E0579")]
614 pub struct LowerRangeBoundMustBeLessThanUpper
{
619 #[derive(LintDiagnostic)]
620 #[diag(mir_build_leading_irrefutable_let_patterns)]
623 pub struct LeadingIrrefutableLetPatterns
{
627 #[derive(LintDiagnostic)]
628 #[diag(mir_build_trailing_irrefutable_let_patterns)]
631 pub struct TrailingIrrefutableLetPatterns
{
635 #[derive(LintDiagnostic)]
636 #[diag(mir_build_bindings_with_variant_name, code = "E0170")]
637 pub struct BindingsWithVariantName
{
638 #[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
639 pub suggestion
: Option
<Span
>,
644 #[derive(LintDiagnostic)]
645 #[diag(mir_build_irrefutable_let_patterns_if_let)]
648 pub struct IrrefutableLetPatternsIfLet
{
652 #[derive(LintDiagnostic)]
653 #[diag(mir_build_irrefutable_let_patterns_if_let_guard)]
656 pub struct IrrefutableLetPatternsIfLetGuard
{
660 #[derive(LintDiagnostic)]
661 #[diag(mir_build_irrefutable_let_patterns_let_else)]
664 pub struct IrrefutableLetPatternsLetElse
{
668 #[derive(LintDiagnostic)]
669 #[diag(mir_build_irrefutable_let_patterns_while_let)]
672 pub struct IrrefutableLetPatternsWhileLet
{
676 #[derive(Diagnostic)]
677 #[diag(mir_build_borrow_of_moved_value)]
678 pub struct BorrowOfMovedValue
<'tcx
> {
681 #[label(mir_build_occurs_because_label)]
682 pub binding_span
: Span
,
683 #[label(mir_build_value_borrowed_label)]
684 pub conflicts_ref
: Vec
<Span
>,
687 #[suggestion(code = "ref ", applicability = "machine-applicable")]
688 pub suggest_borrowing
: Option
<Span
>,
691 #[derive(Diagnostic)]
692 #[diag(mir_build_multiple_mut_borrows)]
693 pub struct MultipleMutBorrows
{
697 pub occurrences
: Vec
<Conflict
>,
700 #[derive(Diagnostic)]
701 #[diag(mir_build_already_borrowed)]
702 pub struct AlreadyBorrowed
{
706 pub occurrences
: Vec
<Conflict
>,
709 #[derive(Diagnostic)]
710 #[diag(mir_build_already_mut_borrowed)]
711 pub struct AlreadyMutBorrowed
{
715 pub occurrences
: Vec
<Conflict
>,
718 #[derive(Diagnostic)]
719 #[diag(mir_build_moved_while_borrowed)]
720 pub struct MovedWhileBorrowed
{
724 pub occurrences
: Vec
<Conflict
>,
727 #[derive(Subdiagnostic)]
729 #[label(mir_build_mutable_borrow)]
735 #[label(mir_build_borrow)]
741 #[label(mir_build_moved)]
749 #[derive(Diagnostic)]
750 #[diag(mir_build_union_pattern)]
751 pub struct UnionPattern
{
756 #[derive(Diagnostic)]
757 #[diag(mir_build_type_not_structural)]
758 #[note(mir_build_type_not_structural_tip)]
759 #[note(mir_build_type_not_structural_more_info)]
760 pub struct TypeNotStructural
<'tcx
> {
763 pub non_sm_ty
: Ty
<'tcx
>,
766 #[derive(Diagnostic)]
767 #[diag(mir_build_invalid_pattern)]
768 pub struct InvalidPattern
<'tcx
> {
771 pub non_sm_ty
: Ty
<'tcx
>,
774 #[derive(Diagnostic)]
775 #[diag(mir_build_unsized_pattern)]
776 pub struct UnsizedPattern
<'tcx
> {
779 pub non_sm_ty
: Ty
<'tcx
>,
782 #[derive(LintDiagnostic)]
783 #[diag(mir_build_float_pattern)]
784 pub struct FloatPattern
;
786 #[derive(LintDiagnostic)]
787 #[diag(mir_build_pointer_pattern)]
788 pub struct PointerPattern
;
790 #[derive(LintDiagnostic)]
791 #[diag(mir_build_indirect_structural_match)]
792 #[note(mir_build_type_not_structural_tip)]
793 #[note(mir_build_type_not_structural_more_info)]
794 pub struct IndirectStructuralMatch
<'tcx
> {
795 pub non_sm_ty
: Ty
<'tcx
>,
798 #[derive(LintDiagnostic)]
799 #[diag(mir_build_nontrivial_structural_match)]
800 #[note(mir_build_type_not_structural_tip)]
801 #[note(mir_build_type_not_structural_more_info)]
802 pub struct NontrivialStructuralMatch
<'tcx
> {
803 pub non_sm_ty
: Ty
<'tcx
>,
806 #[derive(LintDiagnostic)]
807 #[diag(mir_build_non_partial_eq_match)]
808 pub struct NonPartialEqMatch
<'tcx
> {
809 pub non_peq_ty
: Ty
<'tcx
>,
812 #[derive(Diagnostic)]
813 #[diag(mir_build_pattern_not_covered, code = "E0005")]
814 pub(crate) struct PatternNotCovered
<'s
, 'tcx
> {
819 pub uncovered
: Uncovered
<'tcx
>,
821 pub inform
: Option
<Inform
>,
823 pub interpreted_as_const
: Option
<InterpretedAsConst
>,
825 pub adt_defined_here
: Option
<AdtDefinedHere
<'tcx
>>,
826 #[note(mir_build_privately_uninhabited)]
827 pub witness_1_is_privately_uninhabited
: Option
<()>,
828 #[note(mir_build_pattern_ty)]
830 pub pattern_ty
: Ty
<'tcx
>,
832 pub let_suggestion
: Option
<SuggestLet
>,
834 pub misc_suggestion
: Option
<MiscPatternSuggestion
>,
837 #[derive(Subdiagnostic)]
838 #[note(mir_build_inform_irrefutable)]
839 #[note(mir_build_more_information)]
842 pub struct AdtDefinedHere
<'tcx
> {
843 pub adt_def_span
: Span
,
845 pub variants
: Vec
<Variant
>,
852 impl<'tcx
> AddToDiagnostic
for AdtDefinedHere
<'tcx
> {
853 fn add_to_diagnostic_with
<F
>(self, diag
: &mut Diagnostic
, _
: F
)
855 F
: Fn(&mut Diagnostic
, SubdiagnosticMessage
) -> SubdiagnosticMessage
,
857 diag
.set_arg("ty", self.ty
);
858 let mut spans
= MultiSpan
::from(self.adt_def_span
);
860 for Variant { span }
in self.variants
{
861 spans
.push_span_label(span
, fluent
::mir_build_variant_defined_here
);
864 diag
.span_note(spans
, fluent
::mir_build_adt_defined_here
);
868 #[derive(Subdiagnostic)]
870 mir_build_interpreted_as_const
,
871 code
= "{variable}_var",
872 applicability
= "maybe-incorrect"
874 #[label(mir_build_confused)]
875 pub struct InterpretedAsConst
{
878 pub variable
: String
,
881 #[derive(Subdiagnostic)]
882 pub enum SuggestLet
{
883 #[multipart_suggestion(mir_build_suggest_if_let, applicability = "has-placeholders")]
885 #[suggestion_part(code = "if ")]
887 #[suggestion_part(code = " {{ todo!() }}")]
892 mir_build_suggest_let_else
,
893 code
= " else {{ todo!() }}",
894 applicability
= "has-placeholders"
903 #[derive(Subdiagnostic)]
904 pub enum MiscPatternSuggestion
{
906 mir_build_suggest_attempted_int_lit
,
908 applicability
= "maybe-incorrect"
910 AttemptedIntegerLiteral
{
916 #[derive(Diagnostic)]
917 #[diag(mir_build_rustc_box_attribute_error)]
918 pub struct RustcBoxAttributeError
{
922 pub reason
: RustcBoxAttrReason
,
925 #[derive(Subdiagnostic)]
926 pub enum RustcBoxAttrReason
{
927 #[note(mir_build_attributes)]
929 #[note(mir_build_not_box)]
931 #[note(mir_build_missing_box)]