Skip to content

Commit 2695f00

Browse files
committed
Auto merge of #5069 - JohnTitor:tweak-wording, r=flip1995
Tweak wording in `assertions_on_constants` Displays actual macro names changelog: none
2 parents f7b3e4f + fdda3c3 commit 2695f00

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clippy_lints/src/assertions_on_constants.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3333

3434
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
3535
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
36-
let lint_true = || {
36+
let lint_true = |is_debug: bool| {
3737
span_help_and_lint(
3838
cx,
3939
ASSERTIONS_ON_CONSTANTS,
4040
e.span,
41-
"`assert!(true)` will be optimized out by the compiler",
41+
if is_debug {
42+
"`debug_assert!(true)` will be optimized out by the compiler"
43+
} else {
44+
"`assert!(true)` will be optimized out by the compiler"
45+
},
4246
"remove it",
4347
);
4448
};
@@ -70,7 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
7074
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.tables, lit);
7175
if is_true;
7276
then {
73-
lint_true();
77+
lint_true(true);
7478
}
7579
};
7680
} 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 {
8185
match assert_match {
8286
// matched assert but not message
8387
AssertKind::WithoutMessage(false) => lint_false_without_message(),
84-
AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(),
88+
AssertKind::WithoutMessage(true) | AssertKind::WithMessage(_, true) => lint_true(false),
8589
AssertKind::WithMessage(panic_message, false) => lint_false_with_message(panic_message),
8690
};
8791
}

tests/ui/assertions_on_constants.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LL | assert!(C, "C message");
6363
|
6464
= help: use `panic!("C message")` or `unreachable!("C message")`
6565

66-
error: `assert!(true)` will be optimized out by the compiler
66+
error: `debug_assert!(true)` will be optimized out by the compiler
6767
--> $DIR/assertions_on_constants.rs:24:5
6868
|
6969
LL | debug_assert!(true);

0 commit comments

Comments
 (0)