1use rustc_errors::codes::*;
2use rustc_errors::{Diag, EmissionGuarantee, 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<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
30 match self {
31 OverruledAttributeSub::DefaultSource { id } => {
32 diag.note(fluent::lint_default_source);
33 diag.arg("id", id);
34 }
35 OverruledAttributeSub::NodeSource { span, reason } => {
36 diag.span_label(span, fluent::lint_node_source);
37 if let Some(rationale) = reason {
38 #[allow(rustc::untranslatable_diagnostic)]
39 diag.note(rationale.to_string());
40 }
41 }
42 OverruledAttributeSub::CommandLineSource => {
43 diag.note(fluent::lint_command_line_source);
44 }
45 }
46 }
47}
48
49#[derive(Diagnostic)]
50#[diag(lint_malformed_attribute, code = E0452)]
51pub(crate) struct MalformedAttribute {
52 #[primary_span]
53 pub span: Span,
54 #[subdiagnostic]
55 pub sub: MalformedAttributeSub,
56}
57
58#[derive(Subdiagnostic)]
59pub(crate) enum MalformedAttributeSub {
60 #[label(lint_bad_attribute_argument)]
61 BadAttributeArgument(#[primary_span] Span),
62 #[label(lint_reason_must_be_string_literal)]
63 ReasonMustBeStringLiteral(#[primary_span] Span),
64 #[label(lint_reason_must_come_last)]
65 ReasonMustComeLast(#[primary_span] Span),
66}
67
68#[derive(Diagnostic)]
69#[diag(lint_unknown_tool_in_scoped_lint, code = E0710)]
70pub(crate) struct UnknownToolInScopedLint {
71 #[primary_span]
72 pub span: Option<Span>,
73 pub tool_name: Symbol,
74 pub lint_name: String,
75 #[help]
76 pub is_nightly_build: bool,
77}
78
79#[derive(Diagnostic)]
80#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = E0783)]
81pub(crate) struct BuiltinEllipsisInclusiveRangePatterns {
82 #[primary_span]
83 pub span: Span,
84 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
85 pub suggestion: Span,
86 pub replace: String,
87}
88
89#[derive(Subdiagnostic)]
90#[note(lint_requested_level)]
91pub(crate) struct RequestedLevel<'a> {
92 pub level: Level,
93 pub lint_name: &'a str,
94}
95
96#[derive(Diagnostic)]
97#[diag(lint_unsupported_group, code = E0602)]
98pub(crate) struct UnsupportedGroup {
99 pub lint_group: String,
100}
101
102#[derive(Diagnostic)]
103#[diag(lint_check_name_unknown_tool, code = E0602)]
104pub(crate) struct CheckNameUnknownTool<'a> {
105 pub tool_name: Symbol,
106 #[subdiagnostic]
107 pub sub: RequestedLevel<'a>,
108}