|
1 | | -use crate::{ |
2 | | - fluent_generated as fluent, |
3 | | - thir::pattern::{deconstruct_pat::WitnessPat, MatchCheckCtxt}, |
4 | | -}; |
| 1 | +use crate::fluent_generated as fluent; |
5 | 2 | use rustc_errors::DiagnosticArgValue; |
6 | 3 | use rustc_errors::{ |
7 | 4 | error_code, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, |
8 | 5 | Handler, IntoDiagnostic, MultiSpan, SubdiagnosticMessage, |
9 | 6 | }; |
10 | 7 | use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; |
11 | | -use rustc_middle::thir::Pat; |
12 | 8 | use rustc_middle::ty::{self, Ty}; |
| 9 | +use rustc_pattern_analysis::{errors::Uncovered, usefulness::MatchCheckCtxt}; |
13 | 10 | use rustc_span::symbol::Symbol; |
14 | 11 | use rustc_span::Span; |
15 | 12 |
|
@@ -812,94 +809,6 @@ pub struct NonPartialEqMatch<'tcx> { |
812 | 809 | pub non_peq_ty: Ty<'tcx>, |
813 | 810 | } |
814 | 811 |
|
815 | | -#[derive(LintDiagnostic)] |
816 | | -#[diag(mir_build_overlapping_range_endpoints)] |
817 | | -#[note] |
818 | | -pub struct OverlappingRangeEndpoints<'tcx> { |
819 | | - #[label(mir_build_range)] |
820 | | - pub range: Span, |
821 | | - #[subdiagnostic] |
822 | | - pub overlap: Vec<Overlap<'tcx>>, |
823 | | -} |
824 | | - |
825 | | -pub struct Overlap<'tcx> { |
826 | | - pub span: Span, |
827 | | - pub range: Pat<'tcx>, |
828 | | -} |
829 | | - |
830 | | -impl<'tcx> AddToDiagnostic for Overlap<'tcx> { |
831 | | - fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F) |
832 | | - where |
833 | | - F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage, |
834 | | - { |
835 | | - let Overlap { span, range } = self; |
836 | | - |
837 | | - // FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]` |
838 | | - // does not support `#[subdiagnostic(eager)]`... |
839 | | - let message = format!("this range overlaps on `{range}`..."); |
840 | | - diag.span_label(span, message); |
841 | | - } |
842 | | -} |
843 | | - |
844 | | -#[derive(LintDiagnostic)] |
845 | | -#[diag(mir_build_non_exhaustive_omitted_pattern)] |
846 | | -#[help] |
847 | | -#[note] |
848 | | -pub(crate) struct NonExhaustiveOmittedPattern<'tcx> { |
849 | | - pub scrut_ty: Ty<'tcx>, |
850 | | - #[subdiagnostic] |
851 | | - pub uncovered: Uncovered<'tcx>, |
852 | | -} |
853 | | - |
854 | | -#[derive(LintDiagnostic)] |
855 | | -#[diag(mir_build_non_exhaustive_omitted_pattern_lint_on_arm)] |
856 | | -#[help] |
857 | | -pub(crate) struct NonExhaustiveOmittedPatternLintOnArm { |
858 | | - #[label] |
859 | | - pub lint_span: Span, |
860 | | - #[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")] |
861 | | - pub suggest_lint_on_match: Option<Span>, |
862 | | - pub lint_level: &'static str, |
863 | | - pub lint_name: &'static str, |
864 | | -} |
865 | | - |
866 | | -#[derive(Subdiagnostic)] |
867 | | -#[label(mir_build_uncovered)] |
868 | | -pub(crate) struct Uncovered<'tcx> { |
869 | | - #[primary_span] |
870 | | - span: Span, |
871 | | - count: usize, |
872 | | - witness_1: Pat<'tcx>, |
873 | | - witness_2: Pat<'tcx>, |
874 | | - witness_3: Pat<'tcx>, |
875 | | - remainder: usize, |
876 | | -} |
877 | | - |
878 | | -impl<'tcx> Uncovered<'tcx> { |
879 | | - pub fn new<'p>( |
880 | | - span: Span, |
881 | | - cx: &MatchCheckCtxt<'p, 'tcx>, |
882 | | - witnesses: Vec<WitnessPat<'tcx>>, |
883 | | - ) -> Self { |
884 | | - let witness_1 = witnesses.get(0).unwrap().to_diagnostic_pat(cx); |
885 | | - Self { |
886 | | - span, |
887 | | - count: witnesses.len(), |
888 | | - // Substitute dummy values if witnesses is smaller than 3. These will never be read. |
889 | | - witness_2: witnesses |
890 | | - .get(1) |
891 | | - .map(|w| w.to_diagnostic_pat(cx)) |
892 | | - .unwrap_or_else(|| witness_1.clone()), |
893 | | - witness_3: witnesses |
894 | | - .get(2) |
895 | | - .map(|w| w.to_diagnostic_pat(cx)) |
896 | | - .unwrap_or_else(|| witness_1.clone()), |
897 | | - witness_1, |
898 | | - remainder: witnesses.len().saturating_sub(3), |
899 | | - } |
900 | | - } |
901 | | -} |
902 | | - |
903 | 812 | #[derive(Diagnostic)] |
904 | 813 | #[diag(mir_build_pattern_not_covered, code = "E0005")] |
905 | 814 | pub(crate) struct PatternNotCovered<'s, 'tcx> { |
|
0 commit comments