Avoid some packing/unpacking of the AssertLint enum
This commit is contained in:
parent
249ec9f08b
commit
3419273f1f
2 changed files with 41 additions and 49 deletions
|
@ -201,45 +201,39 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) enum AssertLint<P> {
|
||||
ArithmeticOverflow(Span, AssertKind<P>),
|
||||
UnconditionalPanic(Span, AssertKind<P>),
|
||||
pub(crate) struct AssertLint<P> {
|
||||
pub span: Span,
|
||||
pub assert_kind: AssertKind<P>,
|
||||
pub lint_kind: AssertLintKind,
|
||||
}
|
||||
|
||||
pub(crate) enum AssertLintKind {
|
||||
ArithmeticOverflow,
|
||||
UnconditionalPanic,
|
||||
}
|
||||
|
||||
impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, ()>) {
|
||||
let span = self.span();
|
||||
let assert_kind = self.panic();
|
||||
let message = assert_kind.diagnostic_message();
|
||||
assert_kind.add_args(&mut |name, value| {
|
||||
let message = self.assert_kind.diagnostic_message();
|
||||
self.assert_kind.add_args(&mut |name, value| {
|
||||
diag.arg(name, value);
|
||||
});
|
||||
diag.span_label(span, message);
|
||||
diag.span_label(self.span, message);
|
||||
}
|
||||
|
||||
fn msg(&self) -> DiagnosticMessage {
|
||||
match self {
|
||||
AssertLint::ArithmeticOverflow(..) => fluent::mir_transform_arithmetic_overflow,
|
||||
AssertLint::UnconditionalPanic(..) => fluent::mir_transform_operation_will_panic,
|
||||
match self.lint_kind {
|
||||
AssertLintKind::ArithmeticOverflow => fluent::mir_transform_arithmetic_overflow,
|
||||
AssertLintKind::UnconditionalPanic => fluent::mir_transform_operation_will_panic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> AssertLint<P> {
|
||||
impl AssertLintKind {
|
||||
pub fn lint(&self) -> &'static Lint {
|
||||
match self {
|
||||
AssertLint::ArithmeticOverflow(..) => lint::builtin::ARITHMETIC_OVERFLOW,
|
||||
AssertLint::UnconditionalPanic(..) => lint::builtin::UNCONDITIONAL_PANIC,
|
||||
}
|
||||
}
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
AssertLint::ArithmeticOverflow(sp, _) | AssertLint::UnconditionalPanic(sp, _) => *sp,
|
||||
}
|
||||
}
|
||||
pub fn panic(self) -> AssertKind<P> {
|
||||
match self {
|
||||
AssertLint::ArithmeticOverflow(_, p) | AssertLint::UnconditionalPanic(_, p) => p,
|
||||
AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
|
||||
AssertLintKind::UnconditionalPanic => lint::builtin::UNCONDITIONAL_PANIC,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue