1 use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler};
2 use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
3 use rustc_session::{lint::Level, SessionDiagnostic};
4 use rustc_span::{Span, Symbol};
6 #[derive(SessionDiagnostic)]
7 #[diag(lint::overruled_attribute, code = "E0453")]
8 pub struct OverruledAttribute {
13 pub lint_level: String,
14 pub lint_source: Symbol,
16 pub sub: OverruledAttributeSub,
19 pub enum OverruledAttributeSub {
20 DefaultSource { id: String },
21 NodeSource { span: Span, reason: Option<Symbol> },
25 impl AddSubdiagnostic for OverruledAttributeSub {
26 fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
28 OverruledAttributeSub::DefaultSource { id } => {
29 diag.note(fluent::lint::default_source);
30 diag.set_arg("id", id);
32 OverruledAttributeSub::NodeSource { span, reason } => {
33 diag.span_label(span, fluent::lint::node_source);
34 if let Some(rationale) = reason {
35 diag.note(rationale.as_str());
38 OverruledAttributeSub::CommandLineSource => {
39 diag.note(fluent::lint::command_line_source);
45 #[derive(SessionDiagnostic)]
46 #[diag(lint::malformed_attribute, code = "E0452")]
47 pub struct MalformedAttribute {
51 pub sub: MalformedAttributeSub,
54 #[derive(SessionSubdiagnostic)]
55 pub enum MalformedAttributeSub {
56 #[label(lint::bad_attribute_argument)]
57 BadAttributeArgument(#[primary_span] Span),
58 #[label(lint::reason_must_be_string_literal)]
59 ReasonMustBeStringLiteral(#[primary_span] Span),
60 #[label(lint::reason_must_come_last)]
61 ReasonMustComeLast(#[primary_span] Span),
64 #[derive(SessionDiagnostic)]
65 #[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")]
66 pub struct UnknownToolInScopedLint {
68 pub span: Option<Span>,
69 pub tool_name: Symbol,
70 pub lint_name: String,
72 pub is_nightly_build: Option<()>,
75 #[derive(SessionDiagnostic)]
76 #[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
77 pub struct BuiltinEllpisisInclusiveRangePatterns {
80 #[suggestion_short(code = "{replace}", applicability = "machine-applicable")]
85 pub struct RequestedLevel {
87 pub lint_name: String,
90 impl AddSubdiagnostic for RequestedLevel {
91 fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
92 diag.note(fluent::lint::requested_level);
98 Level::ForceWarn(_) => "--force-warn",
100 Level::Forbid => "-F",
101 Level::Expect(_) => {
102 unreachable!("lints with the level of `expect` should not run this code");
106 diag.set_arg("lint_name", self.lint_name);
110 #[derive(SessionDiagnostic)]
111 #[diag(lint::unsupported_group, code = "E0602")]
112 pub struct UnsupportedGroup {
113 pub lint_group: String,
116 pub struct CheckNameUnknown {
117 pub lint_name: String,
118 pub suggestion: Option<Symbol>,
119 pub sub: RequestedLevel,
122 impl SessionDiagnostic<'_> for CheckNameUnknown {
126 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
127 let mut diag = handler.struct_err(fluent::lint::check_name_unknown);
128 diag.code(rustc_errors::error_code!(E0602));
129 if let Some(suggestion) = self.suggestion {
130 diag.help(fluent::lint::help);
131 diag.set_arg("suggestion", suggestion);
133 diag.set_arg("lint_name", self.lint_name);
134 diag.subdiagnostic(self.sub);
139 #[derive(SessionDiagnostic)]
140 #[diag(lint::check_name_unknown_tool, code = "E0602")]
141 pub struct CheckNameUnknownTool {
142 pub tool_name: Symbol,
144 pub sub: RequestedLevel,
147 #[derive(SessionDiagnostic)]
148 #[diag(lint::check_name_warning)]
149 pub struct CheckNameWarning {
152 pub sub: RequestedLevel,
155 #[derive(SessionDiagnostic)]
156 #[diag(lint::check_name_deprecated)]
157 pub struct CheckNameDeprecated {
158 pub lint_name: String,
159 pub new_name: String,
161 pub sub: RequestedLevel,