Format code
This commit is contained in:
parent
5b836e344c
commit
40218bae0c
1 changed files with 27 additions and 12 deletions
|
@ -47,29 +47,44 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||||
if let ExprKind::Lit(ref inner) = lit.node {
|
if let ExprKind::Lit(ref inner) = lit.node {
|
||||||
match inner.node {
|
match inner.node {
|
||||||
LitKind::Bool(true) => {
|
LitKind::Bool(true) => {
|
||||||
span_help_and_lint(cx, ASSERTIONS_ON_CONSTANTS, e.span,
|
span_help_and_lint(
|
||||||
"assert!(true) will be optimized out by the compiler",
|
cx,
|
||||||
"remove it");
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
|
e.span,
|
||||||
|
"`assert!(true)` will be optimized out by the compiler",
|
||||||
|
"remove it"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
LitKind::Bool(false) if !is_debug_assert => {
|
LitKind::Bool(false) if !is_debug_assert => {
|
||||||
span_help_and_lint(
|
span_help_and_lint(
|
||||||
cx, ASSERTIONS_ON_CONSTANTS, e.span,
|
cx,
|
||||||
"assert!(false) should probably be replaced",
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
"use panic!() or unreachable!()");
|
e.span,
|
||||||
|
"`assert!(false)` should probably be replaced",
|
||||||
|
"use `panic!()` or `unreachable!()`"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if let Some(bool_const) = constant(cx, cx.tables, lit) {
|
} else if let Some(bool_const) = constant(cx, cx.tables, lit) {
|
||||||
match bool_const.0 {
|
match bool_const.0 {
|
||||||
Constant::Bool(true) => {
|
Constant::Bool(true) => {
|
||||||
span_help_and_lint(cx, ASSERTIONS_ON_CONSTANTS, e.span,
|
span_help_and_lint(
|
||||||
"assert!(const: true) will be optimized out by the compiler",
|
cx,
|
||||||
"remove it");
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
|
e.span,
|
||||||
|
"`assert!(const: true)` will be optimized out by the compiler",
|
||||||
|
"remove it"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
Constant::Bool(false) if !is_debug_assert => {
|
Constant::Bool(false) if !is_debug_assert => {
|
||||||
span_help_and_lint(cx, ASSERTIONS_ON_CONSTANTS, e.span,
|
span_help_and_lint(
|
||||||
"assert!(const: false) should probably be replaced",
|
cx,
|
||||||
"use panic!() or unreachable!()");
|
ASSERTIONS_ON_CONSTANTS,
|
||||||
|
e.span,
|
||||||
|
"`assert!(const: false)` should probably be replaced",
|
||||||
|
"use `panic!()` or `unreachable!()`"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue