From 14dcf0a8ac632e6073ec979da72e286a57c50f4c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 18 Oct 2020 23:36:00 +0200 Subject: [PATCH] Test for formating placeholders in panic_fmt lint test. --- src/test/ui/panic-brace.rs | 4 ++-- src/test/ui/panic-brace.stderr | 36 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/test/ui/panic-brace.rs b/src/test/ui/panic-brace.rs index 744ecb30037..01ffb800768 100644 --- a/src/test/ui/panic-brace.rs +++ b/src/test/ui/panic-brace.rs @@ -4,6 +4,6 @@ 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 + core::panic!("Hello {}"); //~ WARN Panic message contains an unused formatting placeholder + assert!(false, "{:03x} bla"); //~ WARN Panic message contains an unused formatting placeholder } diff --git a/src/test/ui/panic-brace.stderr b/src/test/ui/panic-brace.stderr index c54044cb6c8..b91ce8f603a 100644 --- a/src/test/ui/panic-brace.stderr +++ b/src/test/ui/panic-brace.stderr @@ -23,28 +23,36 @@ 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 +warning: Panic message contains an unused formatting placeholder + --> $DIR/panic-brace.rs:7:18 | -LL | core::panic!("Hello { { {"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +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 + = note: This message is not used as a format string when given without arguments, but will be in a future Rust version +help: add the missing argument(s) | -LL | core::panic!("{}", "Hello { { {"); +LL | core::panic!("Hello {}", argument); + | ^^^^^^^^^^ +help: or 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 +warning: Panic message contains an unused formatting placeholder + --> $DIR/panic-brace.rs:8:20 | -LL | assert!(false, "} } }..."); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | assert!(false, "{:03x} bla"); + | ^^^^^^^^^^^^ | - = 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 + = note: This message is not used as a format string when given without arguments, but will be in a future Rust version +help: add the missing argument(s) | -LL | assert!(false, "{}", "} } }..."); +LL | assert!(false, "{:03x} bla", argument); + | ^^^^^^^^^^ +help: or add a "{}" format string to use the message literally + | +LL | assert!(false, "{}", "{:03x} bla"); | ^^^^^ warning: 4 warnings emitted