Skip to content

Commit

Permalink
Add more assert!() tests for non_fmt_panics.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Aug 16, 2021
1 parent 82d5305 commit 86bc236
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/test/ui/non-fmt-panic.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ fn main() {

fn a<T: Send + 'static>(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<T: std::fmt::Debug + Send + 'static>(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<T: std::fmt::Display + Send + 'static>(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<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(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
}
4 changes: 4 additions & 0 deletions src/test/ui/non-fmt-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ fn main() {

fn a<T: Send + 'static>(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<T: std::fmt::Debug + Send + 'static>(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<T: std::fmt::Display + Send + 'static>(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<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
panic!(v); //~ WARN panic message is not a string literal
assert!(false, v); //~ WARN panic message is not a string literal
}
56 changes: 52 additions & 4 deletions src/test/ui/non-fmt-panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ LL | panic!(v);
= 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
--> $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 <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:72:12
|
LL | panic!(v);
| ^
Expand All @@ -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 <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 | assert!(false, "{:?}", v);
| +++++++

warning: panic message is not a string literal
--> $DIR/non-fmt-panic.rs:77:12
|
LL | panic!(v);
| ^
Expand All @@ -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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
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);
| ^
Expand All @@ -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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message
|
LL | assert!(false, "{}", v);
| +++++

warning: 30 warnings emitted

0 comments on commit 86bc236

Please sign in to comment.