From 451c9864c498f715c39b52dbbf0c6258c608c13f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 18 Oct 2020 22:52:36 +0200 Subject: [PATCH] Add test for the panic_fmt lint. --- src/test/ui/panic-brace.rs | 9 ++++++ src/test/ui/panic-brace.stderr | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/ui/panic-brace.rs create mode 100644 src/test/ui/panic-brace.stderr diff --git a/src/test/ui/panic-brace.rs b/src/test/ui/panic-brace.rs new file mode 100644 index 000000000000..744ecb30037c --- /dev/null +++ b/src/test/ui/panic-brace.rs @@ -0,0 +1,9 @@ +// build-pass (FIXME(62277): should be check-pass) + +#[allow(unreachable_code)] +fn main() { + panic!("here's a brace: {"); //~ WARN Panic message contains a brace + std::panic!("another one: }"); //~ WARN Panic message contains a brace + core::panic!("Hello { { {"); //~ WARN Panic message contains a brace + assert!(false, "} } }..."); //~ WARN Panic message contains a brace +} diff --git a/src/test/ui/panic-brace.stderr b/src/test/ui/panic-brace.stderr new file mode 100644 index 000000000000..c54044cb6c81 --- /dev/null +++ b/src/test/ui/panic-brace.stderr @@ -0,0 +1,51 @@ +warning: Panic message contains a brace + --> $DIR/panic-brace.rs:5:5 + | +LL | panic!("here's a brace: {"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(panic_fmt)]` on by default + = note: This message is not used as a format string, but will be in a future Rust version +help: add a "{}" format string to use the message literally + | +LL | panic!("{}", "here's a brace: {"); + | ^^^^^ + +warning: Panic message contains a brace + --> $DIR/panic-brace.rs:6:5 + | +LL | std::panic!("another one: }"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: This message is not used as a format string, but will be in a future Rust version +help: add a "{}" format string to use the message literally + | +LL | std::panic!("{}", "another one: }"); + | ^^^^^ + +warning: Panic message contains a brace + --> $DIR/panic-brace.rs:7:5 + | +LL | core::panic!("Hello { { {"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: This message is not used as a format string, but will be in a future Rust version +help: add a "{}" format string to use the message literally + | +LL | core::panic!("{}", "Hello { { {"); + | ^^^^^ + +warning: Panic message contains a brace + --> $DIR/panic-brace.rs:8:5 + | +LL | assert!(false, "} } }..."); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: This message is not used as a format string, but will be in a future Rust version +help: add a "{}" format string to use the message literally + | +LL | assert!(false, "{}", "} } }..."); + | ^^^^^ + +warning: 4 warnings emitted +