rustc_lint/
errors.rs
1use rustc_errors::codes::*;
2use rustc_errors::{Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
3use rustc_macros::{Diagnostic, Subdiagnostic};
4use rustc_session::lint::Level;
5use rustc_span::{Span, Symbol};
6
7use crate::fluent_generated as fluent;
8
9#[derive(Diagnostic)]
10#[diag(lint_overruled_attribute, code = E0453)]
11pub(crate) struct OverruledAttribute<'a> {
12 #[primary_span]
13 pub span: Span,
14 #[label]
15 pub overruled: Span,
16 pub lint_level: &'a str,
17 pub lint_source: Symbol,
18 #[subdiagnostic]
19 pub sub: OverruledAttributeSub,
20}
21
22pub(crate) enum OverruledAttributeSub {
23 DefaultSource { id: String },
24 NodeSource { span: Span, reason: Option<Symbol> },
25 CommandLineSource,
26}
27
28impl Subdiagnostic for OverruledAttributeSub {
29 fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
30 self,
31 diag: &mut Diag<'_, G>,
32 _f: &F,
33 ) {
34 match self {
35 OverruledAttributeSub::DefaultSource { id } => {
36 diag.note(fluent::lint_default_source);
37 diag.arg("id", id);
38 }
39 OverruledAttributeSub::NodeSource { span, reason } => {
40 diag.span_label(span, fluent::lint_node_source);
41 if let Some(rationale) = reason {
42 #[allow(rustc::untranslatable_diagnostic)]
43 diag.note(rationale.to_string());
44 }
45 }
46 OverruledAttributeSub::CommandLineSource => {
47 diag.note(fluent::lint_command_line_source);
48 }
49 }
50 }
51}
52
53#[derive(Diagnostic)]
54#[diag(lint_malformed_attribute, code = E0452)]
55pub(crate) struct MalformedAttribute {
56 #[primary_span]
57 pub span: Span,
58 #[subdiagnostic]
59 pub sub: MalformedAttributeSub,
60}
61
62#[derive(Subdiagnostic)]
63pub(crate) enum MalformedAttributeSub {
64 #[label(lint_bad_attribute_argument)]
65 BadAttributeArgument(#[primary_span] Span),
66 #[label(lint_reason_must_be_string_literal)]
67 ReasonMustBeStringLiteral(#[primary_span] Span),
68 #[label(lint_reason_must_come_last)]
69 ReasonMustComeLast(#[primary_span] Span),
70}
71
72#[derive(Diagnostic)]
73#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
74pub(crate) struct UnknownToolInScopedLint {
75 #[primary_span]
76 pub span: Option<Span>,
77 pub tool_name: Symbol,
78 pub lint_name: String,
79 #[help]
80 pub is_nightly_build: bool,
81}
82
83#[derive(Diagnostic)]
84#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
85pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
86 #[primary_span]
87 pub span: Span,
88 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
89 pub suggestion: Span,
90 pub replace: String,
91}
92
93#[derive(Subdiagnostic)]
94#[note(lint_requested_level)]
95pub(crate) struct RequestedLevel<'a> {
96 pub level: Level,
97 pub lint_name: &'a str,
98}
99
100#[derive(Diagnostic)]
101#[diag(lint_unsupported_group, code = E0602)]
102pub(crate) struct UnsupportedGroup {
103 pub lint_group: String,
104}
105
106#[derive(Diagnostic)]
107#[diag(lint_check_name_unknown_tool, code = E0602)]
108pub(crate) struct CheckNameUnknownTool<'a> {
109 pub tool_name: Symbol,
110 #[subdiagnostic]
111 pub sub: RequestedLevel<'a>,
112}