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<'a> {
16 pub lint_level: &'a str,
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 #[allow(rustc::untranslatable_diagnostic)]
42 diag.note(rationale.as_str());
45 OverruledAttributeSub::CommandLineSource => {
46 diag.note(fluent::lint_command_line_source);
53 #[diag(lint_malformed_attribute, code = "E0452")]
54 pub struct MalformedAttribute {
58 pub sub: MalformedAttributeSub,
61 #[derive(Subdiagnostic)]
62 pub enum MalformedAttributeSub {
63 #[label(lint_bad_attribute_argument)]
64 BadAttributeArgument(#[primary_span] Span),
65 #[label(lint_reason_must_be_string_literal)]
66 ReasonMustBeStringLiteral(#[primary_span] Span),
67 #[label(lint_reason_must_come_last)]
68 ReasonMustComeLast(#[primary_span] Span),
72 #[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
73 pub struct UnknownToolInScopedLint {
75 pub span: Option<Span>,
76 pub tool_name: Symbol,
77 pub lint_name: String,
79 pub is_nightly_build: Option<()>,
83 #[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
84 pub struct BuiltinEllpisisInclusiveRangePatterns {
87 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
92 #[derive(Subdiagnostic)]
93 #[note(lint_requested_level)]
94 pub struct RequestedLevel {
96 pub lint_name: String,
100 #[diag(lint_unsupported_group, code = "E0602")]
101 pub struct UnsupportedGroup {
102 pub lint_group: String,
105 pub struct CheckNameUnknown {
106 pub lint_name: String,
107 pub suggestion: Option<Symbol>,
108 pub sub: RequestedLevel,
111 impl IntoDiagnostic<'_> for CheckNameUnknown {
115 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
116 let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
117 diag.code(rustc_errors::error_code!(E0602));
118 if let Some(suggestion) = self.suggestion {
119 diag.help(fluent::help);
120 diag.set_arg("suggestion", suggestion);
122 diag.set_arg("lint_name", self.lint_name);
123 diag.subdiagnostic(self.sub);
128 #[derive(Diagnostic)]
129 #[diag(lint_check_name_unknown_tool, code = "E0602")]
130 pub struct CheckNameUnknownTool {
131 pub tool_name: Symbol,
133 pub sub: RequestedLevel,
136 #[derive(Diagnostic)]
137 #[diag(lint_check_name_warning)]
138 pub struct CheckNameWarning {
141 pub sub: RequestedLevel,
144 #[derive(Diagnostic)]
145 #[diag(lint_check_name_deprecated)]
146 pub struct CheckNameDeprecated {
147 pub lint_name: String,
148 pub new_name: String,
150 pub sub: RequestedLevel,