Skip to content

Commit 82d5305

Browse files
committed
Add tests for non_fmt_panics in generic functions.
1 parent 00ca4d0 commit 82d5305

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,25 @@ fn main() {
5656
}
5757
panic!("{}"); // OK
5858
panic!(S); // OK
59+
60+
a(1);
61+
b(1);
62+
c(1);
63+
d(1);
64+
}
65+
66+
fn a<T: Send + 'static>(v: T) {
67+
std::panic::panic_any(v); //~ WARN panic message is not a string literal
68+
}
69+
70+
fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
71+
std::panic::panic_any(v); //~ WARN panic message is not a string literal
72+
}
73+
74+
fn c<T: std::fmt::Display + Send + 'static>(v: T) {
75+
std::panic::panic_any(v); //~ WARN panic message is not a string literal
76+
}
77+
78+
fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
79+
std::panic::panic_any(v); //~ WARN panic message is not a string literal
5980
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,25 @@ fn main() {
5656
}
5757
panic!("{}"); // OK
5858
panic!(S); // OK
59+
60+
a(1);
61+
b(1);
62+
c(1);
63+
d(1);
64+
}
65+
66+
fn a<T: Send + 'static>(v: T) {
67+
panic!(v); //~ WARN panic message is not a string literal
68+
}
69+
70+
fn b<T: std::fmt::Debug + Send + 'static>(v: T) {
71+
panic!(v); //~ WARN panic message is not a string literal
72+
}
73+
74+
fn c<T: std::fmt::Display + Send + 'static>(v: T) {
75+
panic!(v); //~ WARN panic message is not a string literal
76+
}
77+
78+
fn d<T: std::fmt::Display + std::fmt::Debug + Send + 'static>(v: T) {
79+
panic!(v); //~ WARN panic message is not a string literal
5980
}

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,67 @@ help: or use std::panic::panic_any instead
311311
LL | std::panic::panic_any(123);
312312
| ~~~~~~~~~~~~~~~~~~~~~~ ~
313313

314-
warning: 22 warnings emitted
314+
warning: panic message is not a string literal
315+
--> $DIR/non-fmt-panic.rs:67:12
316+
|
317+
LL | panic!(v);
318+
| ------ ^
319+
| |
320+
| help: use std::panic::panic_any instead: `std::panic::panic_any`
321+
|
322+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
323+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
324+
325+
warning: panic message is not a string literal
326+
--> $DIR/non-fmt-panic.rs:71:12
327+
|
328+
LL | panic!(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+
help: add a "{:?}" format string to use the Debug implementation of `T`
334+
|
335+
LL | panic!("{:?}", v);
336+
| +++++++
337+
help: or use std::panic::panic_any instead
338+
|
339+
LL | std::panic::panic_any(v);
340+
| ~~~~~~~~~~~~~~~~~~~~~
341+
342+
warning: panic message is not a string literal
343+
--> $DIR/non-fmt-panic.rs:75:12
344+
|
345+
LL | panic!(v);
346+
| ^
347+
|
348+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
349+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
350+
help: add a "{}" format string to Display the message
351+
|
352+
LL | panic!("{}", v);
353+
| +++++
354+
help: or use std::panic::panic_any instead
355+
|
356+
LL | std::panic::panic_any(v);
357+
| ~~~~~~~~~~~~~~~~~~~~~
358+
359+
warning: panic message is not a string literal
360+
--> $DIR/non-fmt-panic.rs:79:12
361+
|
362+
LL | panic!(v);
363+
| ^
364+
|
365+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
366+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
367+
help: add a "{}" format string to Display the message
368+
|
369+
LL | panic!("{}", v);
370+
| +++++
371+
help: or use std::panic::panic_any instead
372+
|
373+
LL | std::panic::panic_any(v);
374+
| ~~~~~~~~~~~~~~~~~~~~~
375+
376+
warning: 26 warnings emitted
315377

0 commit comments

Comments
 (0)