2 fluent, AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
5 use rustc_macros::{Diagnostic, Subdiagnostic};
6 use rustc_session::lint::Level;
7 use rustc_span::{Span, Symbol};
10 #[diag(lint_overruled_attribute, code = "E0453")]
11 pub struct OverruledAttribute {
16 pub lint_level: String,
17 pub lint_source: Symbol,
19 pub sub: OverruledAttributeSub,
22 pub enum OverruledAttributeSub {
23 DefaultSource { id: String },
24 NodeSource { span: Span, reason: Option<Symbol> },
28 impl AddToDiagnostic for OverruledAttributeSub {
29 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
31 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
34 OverruledAttributeSub::DefaultSource { id } => {
35 diag.note(fluent::lint_default_source);
36 diag.set_arg("id", id);
38 OverruledAttributeSub::NodeSource { span, reason } => {
39 diag.span_label(span, fluent::lint_node_source);
40 if let Some(rationale) = reason {
41 diag.note(rationale.as_str());
44 OverruledAttributeSub::CommandLineSource => {
45 diag.note(fluent::lint_command_line_source);
52 #[diag(lint_malformed_attribute, code = "E0452")]
53 pub struct MalformedAttribute {
57 pub sub: MalformedAttributeSub,
60 #[derive(Subdiagnostic)]
61 pub enum MalformedAttributeSub {
62 #[label(lint_bad_attribute_argument)]
63 BadAttributeArgument(#[primary_span] Span),
64 #[label(lint_reason_must_be_string_literal)]
65 ReasonMustBeStringLiteral(#[primary_span] Span),
66 #[label(lint_reason_must_come_last)]
67 ReasonMustComeLast(#[primary_span] Span),
71 #[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
72 pub struct UnknownToolInScopedLint {
74 pub span: Option<Span>,
75 pub tool_name: Symbol,
76 pub lint_name: String,
78 pub is_nightly_build: Option<()>,
82 #[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
83 pub struct BuiltinEllpisisInclusiveRangePatterns {
86 #[suggestion_short(code = "{replace}", applicability = "machine-applicable")]
91 #[derive(Subdiagnostic)]
92 #[note(lint_requested_level)]
93 pub struct RequestedLevel {
95 pub lint_name: String,
99 #[diag(lint_unsupported_group, code = "E0602")]
100 pub struct UnsupportedGroup {
101 pub lint_group: String,
104 pub struct CheckNameUnknown {
105 pub lint_name: String,
106 pub suggestion: Option<Symbol>,
107 pub sub: RequestedLevel,
110 impl IntoDiagnostic<'_> for CheckNameUnknown {
114 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
115 let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
116 diag.code(rustc_errors::error_code!(E0602));
117 if let Some(suggestion) = self.suggestion {
118 diag.help(fluent::help);
119 diag.set_arg("suggestion", suggestion);
121 diag.set_arg("lint_name", self.lint_name);
122 diag.subdiagnostic(self.sub);
127 #[derive(Diagnostic)]
128 #[diag(lint_check_name_unknown_tool, code = "E0602")]
129 pub struct CheckNameUnknownTool {
130 pub tool_name: Symbol,
132 pub sub: RequestedLevel,
135 #[derive(Diagnostic)]
136 #[diag(lint_check_name_warning)]
137 pub struct CheckNameWarning {
140 pub sub: RequestedLevel,
143 #[derive(Diagnostic)]
144 #[diag(lint_check_name_deprecated)]
145 pub struct CheckNameDeprecated {
146 pub lint_name: String,
147 pub new_name: String,
149 pub sub: RequestedLevel,