Skip to main content

rustc_lint/
errors.rs

1use rustc_errors::codes::*;
2use rustc_errors::{Diag, EmissionGuarantee, Subdiagnostic, msg};
3use rustc_macros::{Diagnostic, Subdiagnostic};
4use rustc_session::lint::Level;
5use rustc_span::{Span, Symbol};
6
7#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            OverruledAttribute<'a> 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 {
                    OverruledAttribute {
                        span: __binding_0,
                        overruled: __binding_1,
                        lint_level: __binding_2,
                        lint_source: __binding_3,
                        sub: __binding_4 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$lint_level}({$lint_source}) incompatible with previous forbid")));
                        diag.code(E0453);
                        ;
                        diag.arg("lint_level", __binding_2);
                        diag.arg("lint_source", __binding_3);
                        diag.span(__binding_0);
                        diag.span_label(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overruled by previous forbid")));
                        diag.subdiagnostic(__binding_4);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
8#[diag("{$lint_level}({$lint_source}) incompatible with previous forbid", code = E0453)]
9pub(crate) struct OverruledAttribute<'a> {
10    #[primary_span]
11    pub span: Span,
12    #[label("overruled by previous forbid")]
13    pub overruled: Span,
14    pub lint_level: &'a str,
15    pub lint_source: Symbol,
16    #[subdiagnostic]
17    pub sub: OverruledAttributeSub,
18}
19
20pub(crate) enum OverruledAttributeSub {
21    DefaultSource { id: String },
22    NodeSource { span: Span, reason: Option<Symbol> },
23    CommandLineSource { id: Symbol },
24}
25
26impl Subdiagnostic for OverruledAttributeSub {
27    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
28        match self {
29            OverruledAttributeSub::DefaultSource { id } => {
30                diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` lint level is the default for {$id}"))msg!("`forbid` lint level is the default for {$id}"));
31                diag.arg("id", id);
32            }
33            OverruledAttributeSub::NodeSource { span, reason } => {
34                diag.span_label(span, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` level set here"))msg!("`forbid` level set here"));
35                if let Some(rationale) = reason {
36                    diag.note(rationale.to_string());
37                }
38            }
39            OverruledAttributeSub::CommandLineSource { id } => {
40                diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`forbid` lint level was set on command line (`-F {$id}`)"))msg!("`forbid` lint level was set on command line (`-F {$id}`)"));
41                diag.arg("id", id);
42            }
43        }
44    }
45}
46
47#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            MalformedAttribute 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 {
                    MalformedAttribute { span: __binding_0, sub: __binding_1 }
                        => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("malformed lint attribute input")));
                        diag.code(E0452);
                        ;
                        diag.span(__binding_0);
                        diag.subdiagnostic(__binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
48#[diag("malformed lint attribute input", code = E0452)]
49pub(crate) struct MalformedAttribute {
50    #[primary_span]
51    pub span: Span,
52    #[subdiagnostic]
53    pub sub: MalformedAttributeSub,
54}
55
56#[derive(const _: () =
    {
        impl rustc_errors::Subdiagnostic for MalformedAttributeSub {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    MalformedAttributeSub::BadAttributeArgument(__binding_0) =>
                        {
                        diag.store_args();
                        let __message =
                            diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("bad attribute argument")));
                        diag.span_label(__binding_0, __message);
                        diag.restore_args();
                    }
                    MalformedAttributeSub::ReasonMustBeStringLiteral(__binding_0)
                        => {
                        diag.store_args();
                        let __message =
                            diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reason must be a string literal")));
                        diag.span_label(__binding_0, __message);
                        diag.restore_args();
                    }
                    MalformedAttributeSub::ReasonMustComeLast(__binding_0) => {
                        diag.store_args();
                        let __message =
                            diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reason in lint attribute must come last")));
                        diag.span_label(__binding_0, __message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
57pub(crate) enum MalformedAttributeSub {
58    #[label("bad attribute argument")]
59    BadAttributeArgument(#[primary_span] Span),
60    #[label("reason must be a string literal")]
61    ReasonMustBeStringLiteral(#[primary_span] Span),
62    #[label("reason in lint attribute must come last")]
63    ReasonMustComeLast(#[primary_span] Span),
64}
65
66#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnknownToolInScopedLint 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 {
                    UnknownToolInScopedLint {
                        span: __binding_0,
                        tool_name: __binding_1,
                        lint_name: __binding_2,
                        is_nightly_build: __binding_3 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`")));
                        diag.code(E0710);
                        ;
                        diag.arg("tool_name", __binding_1);
                        diag.arg("lint_name", __binding_2);
                        if let Some(__binding_0) = __binding_0 {
                            diag.span(__binding_0);
                        }
                        if __binding_3 {
                            diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("add `#![register_tool({$tool_name})]` to the crate root")));
                        }
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
67#[diag("unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`", code = E0710)]
68pub(crate) struct UnknownToolInScopedLint {
69    #[primary_span]
70    pub span: Option<Span>,
71    pub tool_name: Symbol,
72    pub lint_name: String,
73    #[help("add `#![register_tool({$tool_name})]` to the crate root")]
74    pub is_nightly_build: bool,
75}
76
77#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            BuiltinEllipsisInclusiveRangePatterns 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 {
                    BuiltinEllipsisInclusiveRangePatterns {
                        span: __binding_0,
                        suggestion: __binding_1,
                        replace: __binding_2 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`...` range patterns are deprecated")));
                        let __code_2 =
                            [::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("{0}", __binding_2))
                                            })].into_iter();
                        diag.code(E0783);
                        ;
                        diag.arg("replace", __binding_2);
                        diag.span(__binding_0);
                        diag.span_suggestions_with_style(__binding_1,
                            rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("use `..=` for an inclusive range")),
                            __code_2, rustc_errors::Applicability::MachineApplicable,
                            rustc_errors::SuggestionStyle::HideCodeInline);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
78#[diag("`...` range patterns are deprecated", code = E0783)]
79pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
80    #[primary_span]
81    pub span: Span,
82    #[suggestion(
83        "use `..=` for an inclusive range",
84        style = "short",
85        code = "{replace}",
86        applicability = "machine-applicable"
87    )]
88    pub suggestion: Span,
89    pub replace: String,
90}
91
92#[derive(const _: () =
    {
        impl<'a> rustc_errors::Subdiagnostic for RequestedLevel<'a> {
            fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
                where __G: rustc_errors::EmissionGuarantee {
                match self {
                    RequestedLevel { level: __binding_0, lint_name: __binding_1
                        } => {
                        diag.store_args();
                        diag.arg("level", __binding_0);
                        diag.arg("lint_name", __binding_1);
                        let __message =
                            diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requested on the command line with `{$level} {$lint_name}`")));
                        diag.note(__message);
                        diag.restore_args();
                    }
                }
            }
        }
    };Subdiagnostic)]
93#[note("requested on the command line with `{$level} {$lint_name}`")]
94pub(crate) struct RequestedLevel<'a> {
95    pub level: Level,
96    pub lint_name: &'a str,
97}
98
99#[derive(const _: () =
    {
        impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
            UnsupportedGroup 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 {
                    UnsupportedGroup { lint_group: __binding_0 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`{$lint_group}` lint group is not supported with ´--force-warn´")));
                        diag.code(E0602);
                        ;
                        diag.arg("lint_group", __binding_0);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
100#[diag("`{$lint_group}` lint group is not supported with ´--force-warn´", code = E0602)]
101pub(crate) struct UnsupportedGroup {
102    pub lint_group: String,
103}
104
105#[derive(const _: () =
    {
        impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
            CheckNameUnknownTool<'a> 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 {
                    CheckNameUnknownTool {
                        tool_name: __binding_0, sub: __binding_1 } => {
                        let mut diag =
                            rustc_errors::Diag::new(dcx, level,
                                rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown lint tool: `{$tool_name}`")));
                        diag.code(E0602);
                        ;
                        diag.arg("tool_name", __binding_0);
                        diag.subdiagnostic(__binding_1);
                        diag
                    }
                }
            }
        }
    };Diagnostic)]
106#[diag("unknown lint tool: `{$tool_name}`", code = E0602)]
107pub(crate) struct CheckNameUnknownTool<'a> {
108    pub tool_name: Symbol,
109    #[subdiagnostic]
110    pub sub: RequestedLevel<'a>,
111}