From 00ca4d0dd3f9e8432420c234e44e21a3502db382 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 16 Aug 2021 17:26:08 +0200 Subject: Update non_fmt_panics test. --- src/test/ui/non-fmt-panic.fixed | 5 +++ src/test/ui/non-fmt-panic.rs | 5 +++ src/test/ui/non-fmt-panic.stderr | 73 +++++++++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/test/ui/non-fmt-panic.fixed b/src/test/ui/non-fmt-panic.fixed index c85e1887d96..0686b08eaad 100644 --- a/src/test/ui/non-fmt-panic.fixed +++ b/src/test/ui/non-fmt-panic.fixed @@ -17,11 +17,16 @@ fn main() { //~^ WARN panic message contains unused formatting placeholders assert!(false, "{}", S); //~^ WARN panic message is not a string literal + assert!(false, "{}", 123); + //~^ WARN panic message is not a string literal + assert!(false, "{:?}", Some(123)); + //~^ WARN panic message is not a string literal debug_assert!(false, "{}", "{{}} bla"); //~ WARN panic message contains braces panic!("{}", C); //~ WARN panic message is not a string literal panic!("{}", S); //~ WARN panic message is not a string literal std::panic::panic_any(123); //~ WARN panic message is not a string literal core::panic!("{}", &*"abc"); //~ WARN panic message is not a string literal + std::panic::panic_any(Some(123)); //~ WARN panic message is not a string literal panic!("{}", concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder panic!("{}", concat!("{", "{")); //~ WARN panic message contains braces diff --git a/src/test/ui/non-fmt-panic.rs b/src/test/ui/non-fmt-panic.rs index 020bcf00a01..e086e2dfdbd 100644 --- a/src/test/ui/non-fmt-panic.rs +++ b/src/test/ui/non-fmt-panic.rs @@ -17,11 +17,16 @@ fn main() { //~^ WARN panic message contains unused formatting placeholders assert!(false, S); //~^ WARN panic message is not a string literal + assert!(false, 123); + //~^ WARN panic message is not a string literal + assert!(false, Some(123)); + //~^ WARN panic message is not a string literal debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces panic!(C); //~ WARN panic message is not a string literal panic!(S); //~ WARN panic message is not a string literal std::panic!(123); //~ WARN panic message is not a string literal core::panic!(&*"abc"); //~ WARN panic message is not a string literal + panic!(Some(123)); //~ WARN panic message is not a string literal panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder panic!(concat!("{", "{")); //~ WARN panic message contains braces diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index 513ffd37dc3..5506ead4c7b 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -68,8 +68,34 @@ help: add a "{}" format string to Display the message LL | assert!(false, "{}", S); | +++++ +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:20:20 + | +LL | assert!(false, 123); + | ^^^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{}" format string to Display the message + | +LL | assert!(false, "{}", 123); + | +++++ + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:22:20 + | +LL | assert!(false, Some(123)); + | ^^^^^^^^^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{:?}" format string to use the Debug implementation of `Option` + | +LL | assert!(false, "{:?}", Some(123)); + | +++++++ + warning: panic message contains braces - --> $DIR/non-fmt-panic.rs:20:27 + --> $DIR/non-fmt-panic.rs:24:27 | LL | debug_assert!(false, "{{}} bla"); | ^^^^ @@ -81,7 +107,7 @@ LL | debug_assert!(false, "{}", "{{}} bla"); | +++++ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:21:12 + --> $DIR/non-fmt-panic.rs:25:12 | LL | panic!(C); | ^ @@ -94,7 +120,7 @@ LL | panic!("{}", C); | +++++ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:22:12 + --> $DIR/non-fmt-panic.rs:26:12 | LL | panic!(S); | ^ @@ -107,7 +133,7 @@ LL | panic!("{}", S); | +++++ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:23:17 + --> $DIR/non-fmt-panic.rs:27:17 | LL | std::panic!(123); | ^^^ @@ -124,7 +150,7 @@ LL | std::panic::panic_any(123); | ~~~~~~~~~~~~~~~~~~~~~ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:24:18 + --> $DIR/non-fmt-panic.rs:28:18 | LL | core::panic!(&*"abc"); | ^^^^^^^ @@ -136,8 +162,25 @@ help: add a "{}" format string to Display the message LL | core::panic!("{}", &*"abc"); | +++++ +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:29:12 + | +LL | panic!(Some(123)); + | ^^^^^^^^^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{:?}" format string to use the Debug implementation of `Option` + | +LL | panic!("{:?}", Some(123)); + | +++++++ +help: or use std::panic::panic_any instead + | +LL | std::panic::panic_any(Some(123)); + | ~~~~~~~~~~~~~~~~~~~~~ + warning: panic message contains an unused formatting placeholder - --> $DIR/non-fmt-panic.rs:25:12 + --> $DIR/non-fmt-panic.rs:30:12 | LL | panic!(concat!("{", "}")); | ^^^^^^^^^^^^^^^^^ @@ -153,7 +196,7 @@ LL | panic!("{}", concat!("{", "}")); | +++++ warning: panic message contains braces - --> $DIR/non-fmt-panic.rs:26:5 + --> $DIR/non-fmt-panic.rs:31:5 | LL | panic!(concat!("{", "{")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +208,7 @@ LL | panic!("{}", concat!("{", "{")); | +++++ warning: panic message contains an unused formatting placeholder - --> $DIR/non-fmt-panic.rs:28:37 + --> $DIR/non-fmt-panic.rs:33:37 | LL | fancy_panic::fancy_panic!("test {} 123"); | ^^ @@ -173,7 +216,7 @@ LL | fancy_panic::fancy_panic!("test {} 123"); = note: this message is not used as a format string when given without arguments, but will be in Rust 2021 warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:38:12 + --> $DIR/non-fmt-panic.rs:43:12 | LL | panic!(a!()); | ^^^^ @@ -190,7 +233,7 @@ LL | std::panic::panic_any(a!()); | ~~~~~~~~~~~~~~~~~~~~~ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:40:12 + --> $DIR/non-fmt-panic.rs:45:12 | LL | panic!(format!("{}", 1)); | ^^^^^^^^^^^^^^^^ @@ -205,7 +248,7 @@ LL + panic!("{}", 1); | warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:41:20 + --> $DIR/non-fmt-panic.rs:46:20 | LL | assert!(false, format!("{}", 1)); | ^^^^^^^^^^^^^^^^ @@ -220,7 +263,7 @@ LL + assert!(false, "{}", 1); | warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:42:26 + --> $DIR/non-fmt-panic.rs:47:26 | LL | debug_assert!(false, format!("{}", 1)); | ^^^^^^^^^^^^^^^^ @@ -235,7 +278,7 @@ LL + debug_assert!(false, "{}", 1); | warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:44:12 + --> $DIR/non-fmt-panic.rs:49:12 | LL | panic![123]; | ^^^ @@ -252,7 +295,7 @@ LL | std::panic::panic_any(123); | ~~~~~~~~~~~~~~~~~~~~~~ ~ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:45:12 + --> $DIR/non-fmt-panic.rs:50:12 | LL | panic!{123}; | ^^^ @@ -268,5 +311,5 @@ help: or use std::panic::panic_any instead LL | std::panic::panic_any(123); | ~~~~~~~~~~~~~~~~~~~~~~ ~ -warning: 19 warnings emitted +warning: 22 warnings emitted -- cgit 1.4.1-3-g733a5 From 82d530577b3366cc62e175771e85139590275a55 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 16 Aug 2021 17:33:42 +0200 Subject: Add tests for non_fmt_panics in generic functions. --- src/test/ui/non-fmt-panic.fixed | 21 +++++++++++++ src/test/ui/non-fmt-panic.rs | 21 +++++++++++++ src/test/ui/non-fmt-panic.stderr | 64 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/ui/non-fmt-panic.fixed b/src/test/ui/non-fmt-panic.fixed index 0686b08eaad..0f55f1ae817 100644 --- a/src/test/ui/non-fmt-panic.fixed +++ b/src/test/ui/non-fmt-panic.fixed @@ -56,4 +56,25 @@ fn main() { } panic!("{}"); // OK panic!(S); // OK + + a(1); + b(1); + c(1); + d(1); +} + +fn a(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn b(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn c(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn d(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal } diff --git a/src/test/ui/non-fmt-panic.rs b/src/test/ui/non-fmt-panic.rs index e086e2dfdbd..6e9bdb21f0c 100644 --- a/src/test/ui/non-fmt-panic.rs +++ b/src/test/ui/non-fmt-panic.rs @@ -56,4 +56,25 @@ fn main() { } panic!("{}"); // OK panic!(S); // OK + + a(1); + b(1); + c(1); + d(1); +} + +fn a(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn b(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn c(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn d(v: T) { + panic!(v); //~ WARN panic message is not a string literal } diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index 5506ead4c7b..1d3346d7756 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -311,5 +311,67 @@ help: or use std::panic::panic_any instead LL | std::panic::panic_any(123); | ~~~~~~~~~~~~~~~~~~~~~~ ~ -warning: 22 warnings emitted +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:67:12 + | +LL | panic!(v); + | ------ ^ + | | + | help: use std::panic::panic_any instead: `std::panic::panic_any` + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:71:12 + | +LL | panic!(v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{:?}" format string to use the Debug implementation of `T` + | +LL | panic!("{:?}", v); + | +++++++ +help: or use std::panic::panic_any instead + | +LL | std::panic::panic_any(v); + | ~~~~~~~~~~~~~~~~~~~~~ + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:75:12 + | +LL | panic!(v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{}" format string to Display the message + | +LL | panic!("{}", v); + | +++++ +help: or use std::panic::panic_any instead + | +LL | std::panic::panic_any(v); + | ~~~~~~~~~~~~~~~~~~~~~ + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:79:12 + | +LL | panic!(v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{}" format string to Display the message + | +LL | panic!("{}", v); + | +++++ +help: or use std::panic::panic_any instead + | +LL | std::panic::panic_any(v); + | ~~~~~~~~~~~~~~~~~~~~~ + +warning: 26 warnings emitted -- cgit 1.4.1-3-g733a5 From 86bc236a4cf2a786b8eef43439729cd2a8a61b1f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 16 Aug 2021 17:35:49 +0200 Subject: Add more assert!() tests for non_fmt_panics. --- src/test/ui/non-fmt-panic.fixed | 4 +++ src/test/ui/non-fmt-panic.rs | 4 +++ src/test/ui/non-fmt-panic.stderr | 56 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/test/ui/non-fmt-panic.fixed b/src/test/ui/non-fmt-panic.fixed index 0f55f1ae817..d226f4129aa 100644 --- a/src/test/ui/non-fmt-panic.fixed +++ b/src/test/ui/non-fmt-panic.fixed @@ -65,16 +65,20 @@ fn main() { fn a(v: T) { std::panic::panic_any(v); //~ WARN panic message is not a string literal + assert!(false, v); //~ WARN panic message is not a string literal } fn b(v: T) { std::panic::panic_any(v); //~ WARN panic message is not a string literal + assert!(false, "{:?}", v); //~ WARN panic message is not a string literal } fn c(v: T) { std::panic::panic_any(v); //~ WARN panic message is not a string literal + assert!(false, "{}", v); //~ WARN panic message is not a string literal } fn d(v: T) { std::panic::panic_any(v); //~ WARN panic message is not a string literal + assert!(false, "{}", v); //~ WARN panic message is not a string literal } diff --git a/src/test/ui/non-fmt-panic.rs b/src/test/ui/non-fmt-panic.rs index 6e9bdb21f0c..2ffd7638ae0 100644 --- a/src/test/ui/non-fmt-panic.rs +++ b/src/test/ui/non-fmt-panic.rs @@ -65,16 +65,20 @@ fn main() { fn a(v: T) { panic!(v); //~ WARN panic message is not a string literal + assert!(false, v); //~ WARN panic message is not a string literal } fn b(v: T) { panic!(v); //~ WARN panic message is not a string literal + assert!(false, v); //~ WARN panic message is not a string literal } fn c(v: T) { panic!(v); //~ WARN panic message is not a string literal + assert!(false, v); //~ WARN panic message is not a string literal } fn d(v: T) { panic!(v); //~ WARN panic message is not a string literal + assert!(false, v); //~ WARN panic message is not a string literal } diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index 1d3346d7756..7b5e0ee324b 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -323,7 +323,16 @@ LL | panic!(v); = note: for more information, see warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:71:12 + --> $DIR/non-fmt-panic.rs:68:20 + | +LL | assert!(false, v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:72:12 | LL | panic!(v); | ^ @@ -340,7 +349,20 @@ LL | std::panic::panic_any(v); | ~~~~~~~~~~~~~~~~~~~~~ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:75:12 + --> $DIR/non-fmt-panic.rs:73:20 + | +LL | assert!(false, v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{:?}" format string to use the Debug implementation of `T` + | +LL | assert!(false, "{:?}", v); + | +++++++ + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:77:12 | LL | panic!(v); | ^ @@ -357,7 +379,20 @@ LL | std::panic::panic_any(v); | ~~~~~~~~~~~~~~~~~~~~~ warning: panic message is not a string literal - --> $DIR/non-fmt-panic.rs:79:12 + --> $DIR/non-fmt-panic.rs:78:20 + | +LL | assert!(false, v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{}" format string to Display the message + | +LL | assert!(false, "{}", v); + | +++++ + +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:82:12 | LL | panic!(v); | ^ @@ -373,5 +408,18 @@ help: or use std::panic::panic_any instead LL | std::panic::panic_any(v); | ~~~~~~~~~~~~~~~~~~~~~ -warning: 26 warnings emitted +warning: panic message is not a string literal + --> $DIR/non-fmt-panic.rs:83:20 + | +LL | assert!(false, v); + | ^ + | + = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: for more information, see +help: add a "{}" format string to Display the message + | +LL | assert!(false, "{}", v); + | +++++ + +warning: 30 warnings emitted -- cgit 1.4.1-3-g733a5 From ab8cbc31905ccd010318fc572fea7bf92c46a70f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 16 Aug 2021 17:39:50 +0200 Subject: Show correct macro name in non_fmt_panics message. --- compiler/rustc_lint/src/non_fmt_panic.rs | 2 +- src/test/ui/non-fmt-panic.stderr | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index 7e2b62f00cc..3848547f6c3 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -102,7 +102,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc cx.struct_span_lint(NON_FMT_PANICS, arg_span, |lint| { let mut l = lint.build("panic message is not a string literal"); - l.note("this usage of panic!() is deprecated; it will be a hard error in Rust 2021"); + l.note(&format!("this usage of {}!() is deprecated; it will be a hard error in Rust 2021", symbol_str)); l.note("for more information, see "); if !span.contains(arg_span) { // No clue where this argument is coming from. diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index 7b5e0ee324b..b62cc378aa5 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -61,7 +61,7 @@ warning: panic message is not a string literal LL | assert!(false, S); | ^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | @@ -74,7 +74,7 @@ warning: panic message is not a string literal LL | assert!(false, 123); | ^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | @@ -87,7 +87,7 @@ warning: panic message is not a string literal LL | assert!(false, Some(123)); | ^^^^^^^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{:?}" format string to use the Debug implementation of `Option` | @@ -138,7 +138,7 @@ warning: panic message is not a string literal LL | std::panic!(123); | ^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of std::panic!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | @@ -155,7 +155,7 @@ warning: panic message is not a string literal LL | core::panic!(&*"abc"); | ^^^^^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of core::panic!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | @@ -253,7 +253,7 @@ warning: panic message is not a string literal LL | assert!(false, format!("{}", 1)); | ^^^^^^^^^^^^^^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see = note: the assert!() macro supports formatting, so there's no need for the format!() macro here help: remove the `format!(..)` macro call @@ -268,7 +268,7 @@ warning: panic message is not a string literal LL | debug_assert!(false, format!("{}", 1)); | ^^^^^^^^^^^^^^^^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of debug_assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see = note: the debug_assert!() macro supports formatting, so there's no need for the format!() macro here help: remove the `format!(..)` macro call @@ -328,7 +328,7 @@ warning: panic message is not a string literal LL | assert!(false, v); | ^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see warning: panic message is not a string literal @@ -354,7 +354,7 @@ warning: panic message is not a string literal LL | assert!(false, v); | ^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{:?}" format string to use the Debug implementation of `T` | @@ -384,7 +384,7 @@ warning: panic message is not a string literal LL | assert!(false, v); | ^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | @@ -414,7 +414,7 @@ warning: panic message is not a string literal LL | assert!(false, v); | ^ | - = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021 + = note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021 = note: for more information, see help: add a "{}" format string to Display the message | -- cgit 1.4.1-3-g733a5