1 use crate::fluent_generated as fluent; 2 use rustc_errors::{ 3 AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic, SubdiagnosticMessage, 4 }; 5 use rustc_macros::{Diagnostic, Subdiagnostic}; 6 use rustc_session::lint::Level; 7 use rustc_span::{Span, Symbol}; 8 9 #[derive(Diagnostic)] 10 #[diag(lint_overruled_attribute, code = "E0453")] 11 pub 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 // 22 pub enum OverruledAttributeSub { 23 DefaultSource { id: String }, 24 NodeSource { span: Span, reason: Option<Symbol> }, 25 CommandLineSource, 26 } 27 28 impl AddToDiagnostic for OverruledAttributeSub { add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F) where F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,29 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F) 30 where 31 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage, 32 { 33 match self { 34 OverruledAttributeSub::DefaultSource { id } => { 35 diag.note(fluent::lint_default_source); 36 diag.set_arg("id", id); 37 } 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.to_string()); 43 } 44 } 45 OverruledAttributeSub::CommandLineSource => { 46 diag.note(fluent::lint_command_line_source); 47 } 48 } 49 } 50 } 51 52 #[derive(Diagnostic)] 53 #[diag(lint_malformed_attribute, code = "E0452")] 54 pub struct MalformedAttribute { 55 #[primary_span] 56 pub span: Span, 57 #[subdiagnostic] 58 pub sub: MalformedAttributeSub, 59 } 60 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), 69 } 70 71 #[derive(Diagnostic)] 72 #[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")] 73 pub struct UnknownToolInScopedLint { 74 #[primary_span] 75 pub span: Option<Span>, 76 pub tool_name: Symbol, 77 pub lint_name: String, 78 #[help] 79 pub is_nightly_build: Option<()>, 80 } 81 82 #[derive(Diagnostic)] 83 #[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")] 84 pub struct BuiltinEllipsisInclusiveRangePatterns { 85 #[primary_span] 86 pub span: Span, 87 #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")] 88 pub suggestion: Span, 89 pub replace: String, 90 } 91 92 #[derive(Subdiagnostic)] 93 #[note(lint_requested_level)] 94 pub struct RequestedLevel { 95 pub level: Level, 96 pub lint_name: String, 97 } 98 99 #[derive(Diagnostic)] 100 #[diag(lint_unsupported_group, code = "E0602")] 101 pub struct UnsupportedGroup { 102 pub lint_group: String, 103 } 104 105 pub struct CheckNameUnknown { 106 pub lint_name: String, 107 pub suggestion: Option<Symbol>, 108 pub sub: RequestedLevel, 109 } 110 111 impl IntoDiagnostic<'_> for CheckNameUnknown { into_diagnostic( self, handler: &Handler, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed>112 fn into_diagnostic( 113 self, 114 handler: &Handler, 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::lint_help); 120 diag.set_arg("suggestion", suggestion); 121 } 122 diag.set_arg("lint_name", self.lint_name); 123 diag.subdiagnostic(self.sub); 124 diag 125 } 126 } 127 128 #[derive(Diagnostic)] 129 #[diag(lint_check_name_unknown_tool, code = "E0602")] 130 pub struct CheckNameUnknownTool { 131 pub tool_name: Symbol, 132 #[subdiagnostic] 133 pub sub: RequestedLevel, 134 } 135 136 #[derive(Diagnostic)] 137 #[diag(lint_check_name_warning)] 138 pub struct CheckNameWarning { 139 pub msg: String, 140 #[subdiagnostic] 141 pub sub: RequestedLevel, 142 } 143 144 #[derive(Diagnostic)] 145 #[diag(lint_check_name_deprecated)] 146 pub struct CheckNameDeprecated { 147 pub lint_name: String, 148 pub new_name: String, 149 #[subdiagnostic] 150 pub sub: RequestedLevel, 151 } 152