1use rustc_macros::{Diagnostic, Subdiagnostic};
2use rustc_middle::ty::Ty;
3use rustc_span::Span;
4
5use crate::rustc::{RustcPatCtxt, WitnessPat};
6
7#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for Uncovered {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
Uncovered {
span: __binding_0,
count: __binding_1,
witness_1: __binding_2,
witness_2: __binding_3,
witness_3: __binding_4,
remainder: __binding_5 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("count".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("witness_1".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
sub_args.insert("witness_2".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_3,
&mut diag.long_ty_path));
sub_args.insert("witness_3".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_4,
&mut diag.long_ty_path));
sub_args.insert("remainder".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_5,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$count ->\n [1] pattern `{$witness_1}`\n [2] patterns `{$witness_1}` and `{$witness_2}`\n [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}`\n *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more\n } not covered")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
8#[label(
9 "{$count ->
10 [1] pattern `{$witness_1}`
11 [2] patterns `{$witness_1}` and `{$witness_2}`
12 [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}`
13 *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more
14 } not covered"
15)]
16pub struct Uncovered {
17 #[primary_span]
18 span: Span,
19 count: usize,
20 witness_1: String, witness_2: String, witness_3: String, remainder: usize,
24}
25
26impl Uncovered {
27 pub fn new<'p, 'tcx>(
28 span: Span,
29 cx: &RustcPatCtxt<'p, 'tcx>,
30 witnesses: Vec<WitnessPat<'p, 'tcx>>,
31 ) -> Self
32 where
33 'tcx: 'p,
34 {
35 let witness_1 = cx.print_witness_pat(witnesses.get(0).unwrap());
36 Self {
37 span,
38 count: witnesses.len(),
39 witness_2: witnesses.get(1).map(|w| cx.print_witness_pat(w)).unwrap_or_default(),
41 witness_3: witnesses.get(2).map(|w| cx.print_witness_pat(w)).unwrap_or_default(),
42 witness_1,
43 remainder: witnesses.len().saturating_sub(3),
44 }
45 }
46}
47
48#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
OverlappingRangeEndpoints where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
OverlappingRangeEndpoints {
range: __binding_0, overlap: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("multiple patterns overlap on their endpoints")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("you likely meant to write mutually exclusive ranges")));
;
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("... with this range")));
for __binding_1 in __binding_1 {
diag.subdiagnostic(__binding_1);
}
diag
}
}
}
}
};Diagnostic)]
49#[diag("multiple patterns overlap on their endpoints")]
50#[note("you likely meant to write mutually exclusive ranges")]
51pub struct OverlappingRangeEndpoints {
52 #[label("... with this range")]
53 pub range: Span,
54 #[subdiagnostic]
55 pub overlap: Vec<Overlap>,
56}
57
58#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for Overlap {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
Overlap { span: __binding_0, range: __binding_1 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("range".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this range overlaps on `{$range}`...")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
59#[label("this range overlaps on `{$range}`...")]
60pub struct Overlap {
61 #[primary_span]
62 pub span: Span,
63 pub range: String, }
65
66#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ExclusiveRangeMissingMax where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ExclusiveRangeMissingMax {
first_range: __binding_0,
suggestion: __binding_1,
max: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("exclusive range missing `{$max}`")));
let __code_0 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_1))
})].into_iter();
;
diag.arg("suggestion", __binding_1);
diag.arg("max", __binding_2);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this range doesn't match `{$max}` because `..` is an exclusive range")));
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use an inclusive range instead")),
__code_0, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
diag
}
}
}
}
};Diagnostic)]
67#[diag("exclusive range missing `{$max}`")]
68pub struct ExclusiveRangeMissingMax {
69 #[label("this range doesn't match `{$max}` because `..` is an exclusive range")]
70 #[suggestion(
71 "use an inclusive range instead",
72 code = "{suggestion}",
73 applicability = "maybe-incorrect"
74 )]
75 pub first_range: Span,
77 pub suggestion: String,
79 pub max: String, }
81
82#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ExclusiveRangeMissingGap where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
ExclusiveRangeMissingGap {
first_range: __binding_0,
gap: __binding_1,
suggestion: __binding_2,
gap_with: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("multiple ranges are one apart")));
let __code_1 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}", __binding_2))
})].into_iter();
;
diag.arg("gap", __binding_1);
diag.arg("suggestion", __binding_2);
diag.span_label(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this range doesn't match `{$gap}` because `..` is an exclusive range")));
diag.span_suggestions_with_style(__binding_0,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use an inclusive range instead")),
__code_1, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
for __binding_3 in __binding_3 {
diag.subdiagnostic(__binding_3);
}
diag
}
}
}
}
};Diagnostic)]
83#[diag("multiple ranges are one apart")]
84pub struct ExclusiveRangeMissingGap {
85 #[label("this range doesn't match `{$gap}` because `..` is an exclusive range")]
86 #[suggestion(
87 "use an inclusive range instead",
88 code = "{suggestion}",
89 applicability = "maybe-incorrect"
90 )]
91 pub first_range: Span,
93 pub gap: String, pub suggestion: String,
96 #[subdiagnostic]
97 pub gap_with: Vec<GappedRange>,
99}
100
101#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for GappedRange {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
GappedRange {
span: __binding_0,
gap: __binding_1,
first_range: __binding_2 } => {
let mut sub_args = rustc_errors::DiagArgMap::default();
sub_args.insert("gap".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_1,
&mut diag.long_ty_path));
sub_args.insert("first_range".into(),
rustc_errors::IntoDiagArg::into_diag_arg(__binding_2,
&mut diag.long_ty_path));
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this could appear to continue range `{$first_range}`, but `{$gap}` isn't matched by either of them")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
102#[label(
103 "this could appear to continue range `{$first_range}`, but `{$gap}` isn't matched by either of them"
104)]
105pub struct GappedRange {
106 #[primary_span]
107 pub span: Span,
108 pub gap: String, pub first_range: String, }
111
112#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonExhaustiveOmittedPattern<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonExhaustiveOmittedPattern {
scrut_ty: __binding_0, uncovered: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("some variants are not matched explicitly")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("ensure that all variants are matched explicitly by adding the suggested match arms")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found")));
;
diag.arg("scrut_ty", __binding_0);
diag.subdiagnostic(__binding_1);
diag
}
}
}
}
};Diagnostic)]
113#[diag("some variants are not matched explicitly")]
114#[help("ensure that all variants are matched explicitly by adding the suggested match arms")]
115#[note(
116 "the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found"
117)]
118pub(crate) struct NonExhaustiveOmittedPattern<'tcx> {
119 pub scrut_ty: Ty<'tcx>,
120 #[subdiagnostic]
121 pub uncovered: Uncovered,
122}
123
124#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
NonExhaustiveOmittedPatternLintOnArm where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonExhaustiveOmittedPatternLintOnArm {
span: __binding_0,
lint_span: __binding_1,
suggest_lint_on_match: __binding_2,
lint_level: __binding_3,
lint_name: __binding_4 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the lint level must be set on the whole match")));
let __code_2 =
[::alloc::__export::must_use({
::alloc::fmt::format(format_args!("#[{0}({1})]\n",
__binding_3, __binding_4))
})].into_iter();
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("it no longer has any effect to set the lint level on an individual match arm")));
;
diag.arg("lint_level", __binding_3);
diag.arg("lint_name", __binding_4);
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("remove this attribute")));
if let Some(__binding_2) = __binding_2 {
diag.span_suggestions_with_style(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("set the lint level on the whole match")),
__code_2, rustc_errors::Applicability::MaybeIncorrect,
rustc_errors::SuggestionStyle::ShowCode);
}
diag
}
}
}
}
};Diagnostic)]
125#[diag("the lint level must be set on the whole match")]
126#[help("it no longer has any effect to set the lint level on an individual match arm")]
127pub(crate) struct NonExhaustiveOmittedPatternLintOnArm {
128 #[primary_span]
129 pub span: Span,
130 #[label("remove this attribute")]
131 pub lint_span: Span,
132 #[suggestion(
133 "set the lint level on the whole match",
134 code = "#[{lint_level}({lint_name})]\n",
135 applicability = "maybe-incorrect"
136 )]
137 pub suggest_lint_on_match: Option<Span>,
138 pub lint_level: &'static str,
139 pub lint_name: &'static str,
140}
141
142#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
MixedDerefPatternConstructors<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MixedDerefPatternConstructors {
spans: __binding_0,
smart_pointer_ty: __binding_1,
deref_pattern_label: __binding_2,
normal_constructor_label: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("mix of deref patterns and normal constructors")));
;
diag.arg("smart_pointer_ty", __binding_1);
diag.span(__binding_0.clone());
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("matches on the result of dereferencing `{$smart_pointer_ty}`")));
diag.span_label(__binding_3,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("matches directly on `{$smart_pointer_ty}`")));
diag
}
}
}
}
};Diagnostic)]
143#[diag("mix of deref patterns and normal constructors")]
144pub(crate) struct MixedDerefPatternConstructors<'tcx> {
145 #[primary_span]
146 pub spans: Vec<Span>,
147 pub smart_pointer_ty: Ty<'tcx>,
148 #[label("matches on the result of dereferencing `{$smart_pointer_ty}`")]
149 pub deref_pattern_label: Span,
150 #[label("matches directly on `{$smart_pointer_ty}`")]
151 pub normal_constructor_label: Span,
152}