Skip to content

Commit beaef7d

Browse files
authored
fix compile bug with panic!
```bash Compiling playground v0.0.1 (/playground) warning: panic message is not a string literal --> src/main.rs:48:32 | 48 | Err(why) => panic!(match why { | ________________________________^ 49 | | MathError::NonPositiveLogarithm 50 | | => "logarithm of non-positive number", 51 | | MathError::DivisionByZero ... | 54 | | => "square root of negative number", 55 | | }), | |_____________^ | = note: `#[warn(non_fmt_panic)]` on by default = note: this is no longer accepted in Rust 2021 help: add a "{}" format string to Display the message | 48 | Err(why) => panic!("{}", match why { | ^^^^^ help: or use std::panic::panic_any instead | 48 | Err(why) => std::panic::panic_any(match why { | ^^^^^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted Finished dev [unoptimized + debuginfo] target(s) in 1.46s Running `target/debug/playground` thread 'main' panicked at 'square root of negative number', src/main.rs:48:25 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
1 parent 29d91f5 commit beaef7d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/std/result/question_mark.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod checked {
5454
5555
pub fn op(x: f64, y: f64) {
5656
match op_(x, y) {
57-
Err(why) => panic!(match why {
57+
Err(why) => panic!("{}", match why {
5858
MathError::NonPositiveLogarithm
5959
=> "logarithm of non-positive number",
6060
MathError::DivisionByZero

0 commit comments

Comments
 (0)