Auto merge of #5069 - JohnTitor:tweak-wording, r=flip1995

Tweak wording in `assertions_on_constants`

Displays actual macro names

changelog: none
This commit is contained in:
bors 2020-01-20 11:42:08 +00:00
commit 2695f00546
2 changed files with 9 additions and 5 deletions

View file

@ -33,12 +33,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
let lint_true = || {
let lint_true = |is_debug: bool| {
span_help_and_lint(
cx,
ASSERTIONS_ON_CONSTANTS,
e.span,
"`assert!(true)` will be optimized out by the compiler",
if is_debug {
"`debug_assert!(true)` will be optimized out by the compiler"
} else {
"`assert!(true)` will be optimized out by the compiler"
},
"remove it",
);
};
@ -70,7 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit);
if is_true;
then {
lint_true();
lint_true(true);
}
};
} else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") {
@ -81,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
match assert_match {
// matched assert but not message
AssertKind::WithoutMessage(false) => lint_false_without_message(),
AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(),
AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(false),
AssertKind::WithMessage(panic_message, false) => lint_false_with_message(panic_message),
};
}

View file

@ -63,7 +63,7 @@ LL | assert!(C, "C message");
|
= help: use `panic!("C message")` or `unreachable!("C message")`
error: `assert!(true)` will be optimized out by the compiler
error: `debug_assert!(true)` will be optimized out by the compiler
--> $DIR/assertions_on_constants.rs:24:5
|
LL | debug_assert!(true);