diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-08-16 17:33:42 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2021-08-16 17:33:42 +0200 |
| commit | 82d530577b3366cc62e175771e85139590275a55 (patch) | |
| tree | 2641ee78e39ae95c25f5db782a89751af7958407 | |
| parent | 00ca4d0dd3f9e8432420c234e44e21a3502db382 (diff) | |
| download | rust-82d530577b3366cc62e175771e85139590275a55.tar.gz rust-82d530577b3366cc62e175771e85139590275a55.zip | |
Add tests for non_fmt_panics in generic functions.
| -rw-r--r-- | src/test/ui/non-fmt-panic.fixed | 21 | ||||
| -rw-r--r-- | src/test/ui/non-fmt-panic.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/non-fmt-panic.stderr | 64 |
3 files changed, 105 insertions, 1 deletions
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<T: Send + 'static>(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn b<T: std::fmt::Debug + Send + 'static>(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn c<T: std::fmt::Display + Send + 'static>(v: T) { + std::panic::panic_any(v); //~ WARN panic message is not a string literal +} + +fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(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<T: Send + 'static>(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn b<T: std::fmt::Debug + Send + 'static>(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn c<T: std::fmt::Display + Send + 'static>(v: T) { + panic!(v); //~ WARN panic message is not a string literal +} + +fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html> + +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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html> +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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html> +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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html> +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 |
