From 9f97a0b364bcbb261f05d6ac62436b6802bfa80b Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 14 Feb 2021 18:53:10 +0100 Subject: [PATCH] Add test for panic!(format!(..)) lint. --- src/test/ui/non-fmt-panic.rs | 2 ++ src/test/ui/non-fmt-panic.stderr | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/ui/non-fmt-panic.rs b/src/test/ui/non-fmt-panic.rs index ff9e3b497f2..c20df5ffd10 100644 --- a/src/test/ui/non-fmt-panic.rs +++ b/src/test/ui/non-fmt-panic.rs @@ -35,6 +35,8 @@ fn main() { panic!(a!()); //~ WARN panic message is not a string literal + panic!(format!("{}", 1)); //~ WARN panic message is not a string literal + // Check that the lint only triggers for std::panic and core::panic, // not any panic macro: macro_rules! panic { diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index 2f33f04cb19..043c4b0f750 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -199,5 +199,18 @@ help: or use std::panic::panic_any instead LL | std::panic::panic_any(a!()); | ^^^^^^^^^^^^^^^^^^^^^^ -warning: 15 warnings emitted +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:38:12 + | +LL | panic!(format!("{}", 1)); + | ^^^^^^^^^^^^^^^^ + | + = note: this is no longer accepted in Rust 2021 + = note: the panic!() macro supports formatting, so there's no need for the format!() macro here +help: remove the `format!(..)` macro call + | +LL | panic!("{}", 1); + | -- -- + +warning: 16 warnings emitted