1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
4 fluent, AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
7 use rustc_macros::{Diagnostic, Subdiagnostic};
8 use rustc_session::lint::Level;
9 use rustc_span::{Span, Symbol};
12 #[diag(lint_overruled_attribute, code = "E0453")]
13 pub struct OverruledAttribute {
18 pub lint_level: String,
19 pub lint_source: Symbol,
21 pub sub: OverruledAttributeSub,
24 pub enum OverruledAttributeSub {
25 DefaultSource { id: String },
26 NodeSource { span: Span, reason: Option<Symbol> },
30 impl AddToDiagnostic for OverruledAttributeSub {
31 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
33 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
36 OverruledAttributeSub::DefaultSource { id } => {
37 diag.note(fluent::lint_default_source);
38 diag.set_arg("id", id);
40 OverruledAttributeSub::NodeSource { span, reason } => {
41 diag.span_label(span, fluent::lint_node_source);
42 if let Some(rationale) = reason {
43 #[allow(rustc::untranslatable_diagnostic)]
44 diag.note(rationale.as_str());
47 OverruledAttributeSub::CommandLineSource => {
48 diag.note(fluent::lint_command_line_source);
55 #[diag(lint_malformed_attribute, code = "E0452")]
56 pub struct MalformedAttribute {
60 pub sub: MalformedAttributeSub,
63 #[derive(Subdiagnostic)]
64 pub enum MalformedAttributeSub {
65 #[label(lint_bad_attribute_argument)]
66 BadAttributeArgument(#[primary_span] Span),
67 #[label(lint_reason_must_be_string_literal)]
68 ReasonMustBeStringLiteral(#[primary_span] Span),
69 #[label(lint_reason_must_come_last)]
70 ReasonMustComeLast(#[primary_span] Span),
74 #[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
75 pub struct UnknownToolInScopedLint {
77 pub span: Option<Span>,
78 pub tool_name: Symbol,
79 pub lint_name: String,
81 pub is_nightly_build: Option<()>,
85 #[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
86 pub struct BuiltinEllpisisInclusiveRangePatterns {
89 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
94 #[derive(Subdiagnostic)]
95 #[note(lint_requested_level)]
96 pub struct RequestedLevel {
98 pub lint_name: String,
101 #[derive(Diagnostic)]
102 #[diag(lint_unsupported_group, code = "E0602")]
103 pub struct UnsupportedGroup {
104 pub lint_group: String,
107 pub struct CheckNameUnknown {
108 pub lint_name: String,
109 pub suggestion: Option<Symbol>,
110 pub sub: RequestedLevel,
113 impl IntoDiagnostic<'_> for CheckNameUnknown {
117 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
118 let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
119 diag.code(rustc_errors::error_code!(E0602));
120 if let Some(suggestion) = self.suggestion {
121 diag.help(fluent::help);
122 diag.set_arg("suggestion", suggestion);
124 diag.set_arg("lint_name", self.lint_name);
125 diag.subdiagnostic(self.sub);
130 #[derive(Diagnostic)]
131 #[diag(lint_check_name_unknown_tool, code = "E0602")]
132 pub struct CheckNameUnknownTool {
133 pub tool_name: Symbol,
135 pub sub: RequestedLevel,
138 #[derive(Diagnostic)]
139 #[diag(lint_check_name_warning)]
140 pub struct CheckNameWarning {
143 pub sub: RequestedLevel,
146 #[derive(Diagnostic)]
147 #[diag(lint_check_name_deprecated)]
148 pub struct CheckNameDeprecated {
149 pub lint_name: String,
150 pub new_name: String,
152 pub sub: RequestedLevel,