2022-10-13 04:13:02 -05:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-10-03 08:09:05 -05:00
|
|
|
use rustc_errors::{
|
2022-10-13 04:13:02 -05:00
|
|
|
AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic, SubdiagnosticMessage,
|
2022-10-03 08:09:05 -05:00
|
|
|
};
|
2022-09-18 10:47:31 -05:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-09-07 08:36:08 -05:00
|
|
|
use rustc_session::lint::Level;
|
2022-08-19 19:04:21 -05:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-19 14:50:38 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_overruled_attribute, code = "E0453")]
|
2022-10-06 19:28:51 -05:00
|
|
|
pub struct OverruledAttribute<'a> {
|
2022-08-19 19:47:05 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[label]
|
|
|
|
pub overruled: Span,
|
2022-10-06 19:28:51 -05:00
|
|
|
pub lint_level: &'a str,
|
2022-08-19 19:47:05 -05:00
|
|
|
pub lint_source: Symbol,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: OverruledAttributeSub,
|
|
|
|
}
|
|
|
|
//
|
|
|
|
pub enum OverruledAttributeSub {
|
|
|
|
DefaultSource { id: String },
|
|
|
|
NodeSource { span: Span, reason: Option<Symbol> },
|
|
|
|
CommandLineSource,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:16 -05:00
|
|
|
impl AddToDiagnostic for OverruledAttributeSub {
|
2022-10-03 08:09:05 -05:00
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
|
|
{
|
2022-08-19 19:47:05 -05:00
|
|
|
match self {
|
|
|
|
OverruledAttributeSub::DefaultSource { id } => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::lint_default_source);
|
2022-08-19 19:47:05 -05:00
|
|
|
diag.set_arg("id", id);
|
|
|
|
}
|
|
|
|
OverruledAttributeSub::NodeSource { span, reason } => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.span_label(span, fluent::lint_node_source);
|
2022-08-19 19:47:05 -05:00
|
|
|
if let Some(rationale) = reason {
|
2022-09-21 19:42:52 -05:00
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
2022-08-19 19:47:05 -05:00
|
|
|
diag.note(rationale.as_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OverruledAttributeSub::CommandLineSource => {
|
2022-10-22 04:07:54 -05:00
|
|
|
diag.note(fluent::lint_command_line_source);
|
2022-08-19 19:47:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_malformed_attribute, code = "E0452")]
|
2022-08-19 16:17:14 -05:00
|
|
|
pub struct MalformedAttribute {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: MalformedAttributeSub,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:47:31 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-19 16:17:14 -05:00
|
|
|
pub enum MalformedAttributeSub {
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_bad_attribute_argument)]
|
2022-08-19 16:17:14 -05:00
|
|
|
BadAttributeArgument(#[primary_span] Span),
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_reason_must_be_string_literal)]
|
2022-08-19 16:17:14 -05:00
|
|
|
ReasonMustBeStringLiteral(#[primary_span] Span),
|
2022-10-22 04:07:54 -05:00
|
|
|
#[label(lint_reason_must_come_last)]
|
2022-08-19 16:17:14 -05:00
|
|
|
ReasonMustComeLast(#[primary_span] Span),
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
|
2022-08-20 11:30:49 -05:00
|
|
|
pub struct UnknownToolInScopedLint {
|
2022-08-19 14:50:38 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Option<Span>,
|
2022-08-19 18:52:20 -05:00
|
|
|
pub tool_name: Symbol,
|
2022-08-19 14:50:38 -05:00
|
|
|
pub lint_name: String,
|
|
|
|
#[help]
|
|
|
|
pub is_nightly_build: Option<()>,
|
|
|
|
}
|
2022-08-20 11:11:07 -05:00
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
|
2023-04-09 16:35:02 -05:00
|
|
|
pub struct BuiltinEllipsisInclusiveRangePatterns {
|
2022-08-20 11:11:07 -05:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-10-22 08:48:55 -05:00
|
|
|
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
|
2022-08-20 11:11:07 -05:00
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: String,
|
|
|
|
}
|
2022-08-20 14:48:03 -05:00
|
|
|
|
2022-10-14 07:25:12 -05:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[note(lint_requested_level)]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct RequestedLevel {
|
|
|
|
pub level: Level,
|
|
|
|
pub lint_name: String,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_unsupported_group, code = "E0602")]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct UnsupportedGroup {
|
|
|
|
pub lint_group: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CheckNameUnknown {
|
|
|
|
pub lint_name: String,
|
|
|
|
pub suggestion: Option<Symbol>,
|
|
|
|
pub sub: RequestedLevel,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:45:41 -05:00
|
|
|
impl IntoDiagnostic<'_> for CheckNameUnknown {
|
2022-08-20 14:48:03 -05:00
|
|
|
fn into_diagnostic(
|
|
|
|
self,
|
2022-09-04 23:15:50 -05:00
|
|
|
handler: &Handler,
|
2022-08-20 14:48:03 -05:00
|
|
|
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
|
2022-10-22 04:07:54 -05:00
|
|
|
let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
|
2022-08-20 14:48:03 -05:00
|
|
|
diag.code(rustc_errors::error_code!(E0602));
|
|
|
|
if let Some(suggestion) = self.suggestion {
|
2022-10-13 04:13:02 -05:00
|
|
|
diag.help(fluent::lint_help);
|
2022-08-20 14:48:03 -05:00
|
|
|
diag.set_arg("suggestion", suggestion);
|
|
|
|
}
|
|
|
|
diag.set_arg("lint_name", self.lint_name);
|
|
|
|
diag.subdiagnostic(self.sub);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_check_name_unknown_tool, code = "E0602")]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct CheckNameUnknownTool {
|
|
|
|
pub tool_name: Symbol,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: RequestedLevel,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_check_name_warning)]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct CheckNameWarning {
|
|
|
|
pub msg: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: RequestedLevel,
|
|
|
|
}
|
|
|
|
|
2022-09-18 10:46:56 -05:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 04:07:54 -05:00
|
|
|
#[diag(lint_check_name_deprecated)]
|
2022-08-20 14:48:03 -05:00
|
|
|
pub struct CheckNameDeprecated {
|
|
|
|
pub lint_name: String,
|
|
|
|
pub new_name: String,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: RequestedLevel,
|
|
|
|
}
|