Skip to content

Commit 86bc236

Browse files
committed
Add more assert!() tests for non_fmt_panics.
1 parent 82d5305 commit 86bc236

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

src/test/ui/non-fmt-panic.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ fn main() {
6565

6666
fn a<T: Send + 'static>(v: T) {
6767
std::panic::panic_any(v); //~ WARN panic message is not a string literal
68+
assert!(false, v); //~ WARN panic message is not a string literal
6869
}
6970

7071
fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
7172
std::panic::panic_any(v); //~ WARN panic message is not a string literal
73+
assert!(false, "{:?}", v); //~ WARN panic message is not a string literal
7274
}
7375

7476
fn c<T: std::fmt::Display + Send + 'static>(v: T) {
7577
std::panic::panic_any(v); //~ WARN panic message is not a string literal
78+
assert!(false, "{}", v); //~ WARN panic message is not a string literal
7679
}
7780

7881
fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
7982
std::panic::panic_any(v); //~ WARN panic message is not a string literal
83+
assert!(false, "{}", v); //~ WARN panic message is not a string literal
8084
}

src/test/ui/non-fmt-panic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ fn main() {
6565

6666
fn a<T: Send + 'static>(v: T) {
6767
panic!(v); //~ WARN panic message is not a string literal
68+
assert!(false, v); //~ WARN panic message is not a string literal
6869
}
6970

7071
fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
7172
panic!(v); //~ WARN panic message is not a string literal
73+
assert!(false, v); //~ WARN panic message is not a string literal
7274
}
7375

7476
fn c<T: std::fmt::Display + Send + 'static>(v: T) {
7577
panic!(v); //~ WARN panic message is not a string literal
78+
assert!(false, v); //~ WARN panic message is not a string literal
7679
}
7780

7881
fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
7982
panic!(v); //~ WARN panic message is not a string literal
83+
assert!(false, v); //~ WARN panic message is not a string literal
8084
}

src/test/ui/non-fmt-panic.stderr

+52-4
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,16 @@ LL | panic!(v);
323323
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
324324

325325
warning: panic message is not a string literal
326-
--> $DIR/non-fmt-panic.rs:71:12
326+
--> $DIR/non-fmt-panic.rs:68:20
327+
|
328+
LL | assert!(false, v);
329+
| ^
330+
|
331+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
332+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
333+
334+
warning: panic message is not a string literal
335+
--> $DIR/non-fmt-panic.rs:72:12
327336
|
328337
LL | panic!(v);
329338
| ^
@@ -340,7 +349,20 @@ LL | std::panic::panic_any(v);
340349
| ~~~~~~~~~~~~~~~~~~~~~
341350

342351
warning: panic message is not a string literal
343-
--> $DIR/non-fmt-panic.rs:75:12
352+
--> $DIR/non-fmt-panic.rs:73:20
353+
|
354+
LL | assert!(false, v);
355+
| ^
356+
|
357+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
358+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
359+
help: add a "{:?}" format string to use the Debug implementation of `T`
360+
|
361+
LL | assert!(false, "{:?}", v);
362+
| +++++++
363+
364+
warning: panic message is not a string literal
365+
--> $DIR/non-fmt-panic.rs:77:12
344366
|
345367
LL | panic!(v);
346368
| ^
@@ -357,7 +379,20 @@ LL | std::panic::panic_any(v);
357379
| ~~~~~~~~~~~~~~~~~~~~~
358380

359381
warning: panic message is not a string literal
360-
--> $DIR/non-fmt-panic.rs:79:12
382+
--> $DIR/non-fmt-panic.rs:78:20
383+
|
384+
LL | assert!(false, v);
385+
| ^
386+
|
387+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
388+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
389+
help: add a "{}" format string to Display the message
390+
|
391+
LL | assert!(false, "{}", v);
392+
| +++++
393+
394+
warning: panic message is not a string literal
395+
--> $DIR/non-fmt-panic.rs:82:12
361396
|
362397
LL | panic!(v);
363398
| ^
@@ -373,5 +408,18 @@ help: or use std::panic::panic_any instead
373408
LL | std::panic::panic_any(v);
374409
| ~~~~~~~~~~~~~~~~~~~~~
375410

376-
warning: 26 warnings emitted
411+
warning: panic message is not a string literal
412+
--> $DIR/non-fmt-panic.rs:83:20
413+
|
414+
LL | assert!(false, v);
415+
| ^
416+
|
417+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
418+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
419+
help: add a "{}" format string to Display the message
420+
|
421+
LL | assert!(false, "{}", v);
422+
| +++++
423+
424+
warning: 30 warnings emitted
377425

0 commit comments

Comments
 (0)