rust/compiler/rustc_lint/src/errors.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
3.1 KiB
Rust
Raw Normal View History

use crate::fluent_generated as fluent;
use rustc_errors::{AddToDiagnostic, Diagnostic, SubdiagnosticMessage};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::lint::Level;
2022-08-19 19:04:21 -05:00
use rustc_span::{Span, Symbol};
#[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,
}
impl AddToDiagnostic for OverruledAttributeSub {
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);
diag.arg("id", id);
2022-08-19 19:47:05 -05:00
}
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)]
diag.note(rationale.to_string());
2022-08-19 19:47:05 -05:00
}
}
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
}
}
}
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(lint_malformed_attribute, code = "E0452")]
pub struct MalformedAttribute {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: MalformedAttributeSub,
}
#[derive(Subdiagnostic)]
pub enum MalformedAttributeSub {
2022-10-22 04:07:54 -05:00
#[label(lint_bad_attribute_argument)]
BadAttributeArgument(#[primary_span] Span),
2022-10-22 04:07:54 -05:00
#[label(lint_reason_must_be_string_literal)]
ReasonMustBeStringLiteral(#[primary_span] Span),
2022-10-22 04:07:54 -05:00
#[label(lint_reason_must_come_last)]
ReasonMustComeLast(#[primary_span] Span),
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(lint_unknown_tool_in_scoped_lint, code = "E0710")]
pub struct UnknownToolInScopedLint {
#[primary_span]
pub span: Option<Span>,
pub tool_name: Symbol,
pub lint_name: String,
#[help]
pub is_nightly_build: Option<()>,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(lint_builtin_ellipsis_inclusive_range_patterns, code = "E0783")]
pub struct BuiltinEllipsisInclusiveRangePatterns {
#[primary_span]
pub span: Span,
#[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")]
pub suggestion: Span,
pub replace: String,
}
2022-08-20 14:48:03 -05:00
#[derive(Subdiagnostic)]
2022-10-22 04:07:54 -05:00
#[note(lint_requested_level)]
pub struct RequestedLevel<'a> {
2022-08-20 14:48:03 -05:00
pub level: Level,
pub lint_name: &'a str,
2022-08-20 14:48:03 -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,
}
#[derive(Diagnostic)]
2022-10-22 04:07:54 -05:00
#[diag(lint_check_name_unknown_tool, code = "E0602")]
pub struct CheckNameUnknownTool<'a> {
2022-08-20 14:48:03 -05:00
pub tool_name: Symbol,
#[subdiagnostic]
pub sub: RequestedLevel<'a>,
2022-08-20 14:48:03 -05:00
}