2022-10-13 10:13:02 +01:00
|
|
|
use crate::fluent_generated as fluent;
|
2022-10-03 14:09:05 +01:00
|
|
|
use rustc_errors::{
|
2022-10-13 10:13:02 +01:00
|
|
|
AddToDiagnostic, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic, SubdiagnosticMessage,
|
2022-10-03 14:09:05 +01:00
|
|
|
};
|
2022-09-18 11:47:31 -04:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-09-07 09:36:08 -04:00
|
|
|
use rustc_session::lint::Level;
|
2022-08-19 20:04:21 -04:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-19 15:50:38 -04:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_overruled_attribute, code = "E0453")]
|
2022-10-06 20:28:51 -04:00
|
|
|
pub struct OverruledAttribute<'a> {
|
2022-08-19 20:47:05 -04:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[label]
|
|
|
|
pub overruled: Span,
|
2022-10-06 20:28:51 -04:00
|
|
|
pub lint_level: &'a str,
|
2022-08-19 20:47:05 -04: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 11:46:16 -04:00
|
|
|
impl AddToDiagnostic for OverruledAttributeSub {
|
2022-10-03 14:09:05 +01:00
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
|
|
where
|
|
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
|
|
{
|
2022-08-19 20:47:05 -04:00
|
|
|
match self {
|
|
|
|
OverruledAttributeSub::DefaultSource { id } => {
|
2022-10-22 11:07:54 +02:00
|
|
|
diag.note(fluent::lint_default_source);
|
2022-08-19 20:47:05 -04:00
|
|
|
diag.set_arg("id", id);
|
|
|
|
}
|
|
|
|
OverruledAttributeSub::NodeSource { span, reason } => {
|
2022-10-22 11:07:54 +02:00
|
|
|
diag.span_label(span, fluent::lint_node_source);
|
2022-08-19 20:47:05 -04:00
|
|
|
if let Some(rationale) = reason {
|
2022-09-21 20:42:52 -04:00
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
Use `Cow` in `{D,Subd}iagnosticMessage`.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.
This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.
Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-04 10:55:21 +10:00
|
|
|
diag.note(rationale.to_string());
|
2022-08-19 20:47:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OverruledAttributeSub::CommandLineSource => {
|
2022-10-22 11:07:54 +02:00
|
|
|
diag.note(fluent::lint_command_line_source);
|
2022-08-19 20:47:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_malformed_attribute, code = "E0452")]
|
2022-08-19 17:17:14 -04:00
|
|
|
pub struct MalformedAttribute {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub sub: MalformedAttributeSub,
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:47:31 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-19 17:17:14 -04:00
|
|
|
pub enum MalformedAttributeSub {
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(lint_bad_attribute_argument)]
|
2022-08-19 17:17:14 -04:00
|
|
|
BadAttributeArgument(#[primary_span] Span),
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(lint_reason_must_be_string_literal)]
|
2022-08-19 17:17:14 -04:00
|
|
|
ReasonMustBeStringLiteral(#[primary_span] Span),
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(lint_reason_must_come_last)]
|
2022-08-19 17:17:14 -04:00
|
|
|
ReasonMustComeLast(#[primary_span] Span),
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
|
2022-08-20 12:30:49 -04:00
|
|
|
pub struct UnknownToolInScopedLint {
|
2022-08-19 15:50:38 -04:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Option<Span>,
|
2022-08-19 19:52:20 -04:00
|
|
|
pub tool_name: Symbol,
|
2022-08-19 15:50:38 -04:00
|
|
|
pub lint_name: String,
|
|
|
|
#[help]
|
|
|
|
pub is_nightly_build: Option<()>,
|
|
|
|
}
|
2022-08-20 12:11:07 -04:00
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
|
2023-04-09 17:35:02 -04:00
|
|
|
pub struct BuiltinEllipsisInclusiveRangePatterns {
|
2022-08-20 12:11:07 -04:00
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
2022-10-22 15:48:55 +02:00
|
|
|
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
|
2022-08-20 12:11:07 -04:00
|
|
|
pub suggestion: Span,
|
|
|
|
pub replace: String,
|
|
|
|
}
|
2022-08-20 15:48:03 -04:00
|
|
|
|
2022-10-14 13:25:12 +01:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[note(lint_requested_level)]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct RequestedLevel<'a> {
|
2022-08-20 15:48:03 -04:00
|
|
|
pub level: Level,
|
2023-08-24 00:23:01 +01:00
|
|
|
pub lint_name: &'a str,
|
2022-08-20 15:48:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_unsupported_group, code = "E0602")]
|
2022-08-20 15:48:03 -04:00
|
|
|
pub struct UnsupportedGroup {
|
|
|
|
pub lint_group: String,
|
|
|
|
}
|
|
|
|
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct CheckNameUnknown<'a> {
|
|
|
|
pub lint_name: &'a str,
|
2022-08-20 15:48:03 -04:00
|
|
|
pub suggestion: Option<Symbol>,
|
2023-08-24 00:23:01 +01:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2022-08-20 15:48:03 -04:00
|
|
|
}
|
|
|
|
|
2023-08-24 00:23:01 +01:00
|
|
|
impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
|
2022-08-20 15:48:03 -04:00
|
|
|
fn into_diagnostic(
|
|
|
|
self,
|
2022-09-05 00:15:50 -04:00
|
|
|
handler: &Handler,
|
2022-08-20 15:48:03 -04:00
|
|
|
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
|
2022-10-22 11:07:54 +02:00
|
|
|
let mut diag = handler.struct_err(fluent::lint_check_name_unknown);
|
2022-08-20 15:48:03 -04:00
|
|
|
diag.code(rustc_errors::error_code!(E0602));
|
|
|
|
if let Some(suggestion) = self.suggestion {
|
2022-10-13 10:13:02 +01:00
|
|
|
diag.help(fluent::lint_help);
|
2022-08-20 15:48:03 -04:00
|
|
|
diag.set_arg("suggestion", suggestion);
|
|
|
|
}
|
|
|
|
diag.set_arg("lint_name", self.lint_name);
|
|
|
|
diag.subdiagnostic(self.sub);
|
|
|
|
diag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_check_name_unknown_tool, code = "E0602")]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct CheckNameUnknownTool<'a> {
|
2022-08-20 15:48:03 -04:00
|
|
|
pub tool_name: Symbol,
|
|
|
|
#[subdiagnostic]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2022-08-20 15:48:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2023-08-23 23:53:37 +01:00
|
|
|
#[diag(lint_check_name_renamed)]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct CheckNameRenamed<'a> {
|
|
|
|
pub lint_name: &'a str,
|
|
|
|
pub replace: &'a str,
|
2023-08-23 23:53:37 +01:00
|
|
|
#[subdiagnostic]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2023-08-23 23:53:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Diagnostic)]
|
|
|
|
#[diag(lint_check_name_removed)]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct CheckNameRemoved<'a> {
|
|
|
|
pub lint_name: &'a str,
|
|
|
|
pub reason: &'a str,
|
2022-08-20 15:48:03 -04:00
|
|
|
#[subdiagnostic]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2022-08-20 15:48:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:46:56 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(lint_check_name_deprecated)]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub struct CheckNameDeprecated<'a> {
|
|
|
|
pub lint_name: &'a str,
|
|
|
|
pub new_name: &'a str,
|
2022-08-20 15:48:03 -04:00
|
|
|
#[subdiagnostic]
|
2023-08-24 00:23:01 +01:00
|
|
|
pub sub: RequestedLevel<'a>,
|
2022-08-20 15:48:03 -04:00
|
|
|
}
|