lint: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
ea5d258a75
commit
21d3bbd8b6
2 changed files with 20 additions and 26 deletions
|
@ -1,14 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
fluent, DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg,
|
fluent, DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg,
|
||||||
};
|
};
|
||||||
use rustc_target::abi::TargetDataLayoutErrors;
|
|
||||||
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
|
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_lint_defs::Level;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
|
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
|
||||||
|
use rustc_target::abi::TargetDataLayoutErrors;
|
||||||
|
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
@ -155,6 +155,21 @@ impl IntoDiagnosticArg for ast::token::TokenKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for Level {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Borrowed(match self {
|
||||||
|
Level::Allow => "-A",
|
||||||
|
Level::Warn => "-W",
|
||||||
|
Level::ForceWarn(_) => "--force-warn",
|
||||||
|
Level::Deny => "-D",
|
||||||
|
Level::Forbid => "-F",
|
||||||
|
Level::Expect(_) => {
|
||||||
|
unreachable!("lints with the level of `expect` should not run this code");
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
|
impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> {
|
||||||
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
|
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
|
||||||
let mut diag;
|
let mut diag;
|
||||||
|
|
|
@ -88,34 +88,13 @@ pub struct BuiltinEllpisisInclusiveRangePatterns {
|
||||||
pub replace: String,
|
pub replace: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[note(lint::requested_level)]
|
||||||
pub struct RequestedLevel {
|
pub struct RequestedLevel {
|
||||||
pub level: Level,
|
pub level: Level,
|
||||||
pub lint_name: String,
|
pub lint_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddToDiagnostic for RequestedLevel {
|
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
||||||
where
|
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
||||||
{
|
|
||||||
diag.note(fluent::lint::requested_level);
|
|
||||||
diag.set_arg(
|
|
||||||
"level",
|
|
||||||
match self.level {
|
|
||||||
Level::Allow => "-A",
|
|
||||||
Level::Warn => "-W",
|
|
||||||
Level::ForceWarn(_) => "--force-warn",
|
|
||||||
Level::Deny => "-D",
|
|
||||||
Level::Forbid => "-F",
|
|
||||||
Level::Expect(_) => {
|
|
||||||
unreachable!("lints with the level of `expect` should not run this code");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
diag.set_arg("lint_name", self.lint_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(lint::unsupported_group, code = "E0602")]
|
#[diag(lint::unsupported_group, code = "E0602")]
|
||||||
pub struct UnsupportedGroup {
|
pub struct UnsupportedGroup {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue