Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 87b269a

Browse files
authoredFeb 4, 2021
Rollup merge of #81645 - m-ou-se:panic-lint, r=estebank,flip1995
Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of #80162. r? ```@estebank```
2 parents c5990dd + 0870c15 commit 87b269a

32 files changed

+396
-258
lines changed
 

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait ExpectOne<A: Array> {
2828

2929
impl<A: Array> ExpectOne<A> for SmallVec<A> {
3030
fn expect_one(self, err: &'static str) -> A::Item {
31-
assert!(self.len() == 1, err);
31+
assert!(self.len() == 1, "{}", err);
3232
self.into_iter().next().unwrap()
3333
}
3434
}

‎compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ impl HandlerInner {
901901

902902
fn span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) -> ! {
903903
self.emit_diag_at_span(Diagnostic::new(Bug, msg), sp);
904-
panic!(ExplicitBug);
904+
panic::panic_any(ExplicitBug);
905905
}
906906

907907
fn emit_diag_at_span(&mut self, mut diag: Diagnostic, sp: impl Into<MultiSpan>) {
@@ -955,7 +955,7 @@ impl HandlerInner {
955955

956956
fn bug(&mut self, msg: &str) -> ! {
957957
self.emit_diagnostic(&Diagnostic::new(Bug, msg));
958-
panic!(ExplicitBug);
958+
panic::panic_any(ExplicitBug);
959959
}
960960

961961
fn delay_as_bug(&mut self, diagnostic: Diagnostic) {

‎compiler/rustc_lint/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ mod late;
5555
mod levels;
5656
mod methods;
5757
mod non_ascii_idents;
58+
mod non_fmt_panic;
5859
mod nonstandard_style;
59-
mod panic_fmt;
6060
mod passes;
6161
mod redundant_semicolon;
6262
mod traits;
@@ -81,8 +81,8 @@ use builtin::*;
8181
use internal::*;
8282
use methods::*;
8383
use non_ascii_idents::*;
84+
use non_fmt_panic::NonPanicFmt;
8485
use nonstandard_style::*;
85-
use panic_fmt::PanicFmt;
8686
use redundant_semicolon::*;
8787
use traits::*;
8888
use types::*;
@@ -169,7 +169,7 @@ macro_rules! late_lint_passes {
169169
ClashingExternDeclarations: ClashingExternDeclarations::new(),
170170
DropTraitConstraints: DropTraitConstraints,
171171
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
172-
PanicFmt: PanicFmt,
172+
NonPanicFmt: NonPanicFmt,
173173
]
174174
);
175175
};
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
use crate::{LateContext, LateLintPass, LintContext};
2+
use rustc_ast as ast;
3+
use rustc_errors::{pluralize, Applicability};
4+
use rustc_hir as hir;
5+
use rustc_middle::ty;
6+
use rustc_parse_format::{ParseMode, Parser, Piece};
7+
use rustc_span::{sym, symbol::kw, InnerSpan, Span, Symbol};
8+
9+
declare_lint! {
10+
/// The `non_fmt_panic` lint detects `panic!(..)` invocations where the first
11+
/// argument is not a formatting string.
12+
///
13+
/// ### Example
14+
///
15+
/// ```rust,no_run
16+
/// panic!("{}");
17+
/// panic!(123);
18+
/// ```
19+
///
20+
/// {{produces}}
21+
///
22+
/// ### Explanation
23+
///
24+
/// In Rust 2018 and earlier, `panic!(x)` directly uses `x` as the message.
25+
/// That means that `panic!("{}")` panics with the message `"{}"` instead
26+
/// of using it as a formatting string, and `panic!(123)` will panic with
27+
/// an `i32` as message.
28+
///
29+
/// Rust 2021 always interprets the first argument as format string.
30+
NON_FMT_PANIC,
31+
Warn,
32+
"detect single-argument panic!() invocations in which the argument is not a format string",
33+
report_in_external_macro
34+
}
35+
36+
declare_lint_pass!(NonPanicFmt => [NON_FMT_PANIC]);
37+
38+
impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
39+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
40+
if let hir::ExprKind::Call(f, [arg]) = &expr.kind {
41+
if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() {
42+
if Some(def_id) == cx.tcx.lang_items().begin_panic_fn()
43+
|| Some(def_id) == cx.tcx.lang_items().panic_fn()
44+
|| Some(def_id) == cx.tcx.lang_items().panic_str()
45+
{
46+
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
47+
if cx.tcx.is_diagnostic_item(sym::std_panic_2015_macro, id)
48+
|| cx.tcx.is_diagnostic_item(sym::core_panic_2015_macro, id)
49+
{
50+
check_panic(cx, f, arg);
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
59+
fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>) {
60+
if let hir::ExprKind::Lit(lit) = &arg.kind {
61+
if let ast::LitKind::Str(sym, _) = lit.node {
62+
// The argument is a string literal.
63+
check_panic_str(cx, f, arg, &sym.as_str());
64+
return;
65+
}
66+
}
67+
68+
// The argument is *not* a string literal.
69+
70+
let (span, panic) = panic_call(cx, f);
71+
72+
cx.struct_span_lint(NON_FMT_PANIC, arg.span, |lint| {
73+
let mut l = lint.build("panic message is not a string literal");
74+
l.note("this is no longer accepted in Rust 2021");
75+
if span.contains(arg.span) {
76+
l.span_suggestion_verbose(
77+
arg.span.shrink_to_lo(),
78+
"add a \"{}\" format string to Display the message",
79+
"\"{}\", ".into(),
80+
Applicability::MaybeIncorrect,
81+
);
82+
if panic == sym::std_panic_macro {
83+
l.span_suggestion_verbose(
84+
span.until(arg.span),
85+
"or use std::panic::panic_any instead",
86+
"std::panic::panic_any(".into(),
87+
Applicability::MachineApplicable,
88+
);
89+
}
90+
}
91+
l.emit();
92+
});
93+
}
94+
95+
fn check_panic_str<'tcx>(
96+
cx: &LateContext<'tcx>,
97+
f: &'tcx hir::Expr<'tcx>,
98+
arg: &'tcx hir::Expr<'tcx>,
99+
fmt: &str,
100+
) {
101+
if !fmt.contains(&['{', '}'][..]) {
102+
// No brace, no problem.
103+
return;
104+
}
105+
106+
let fmt_span = arg.span.source_callsite();
107+
108+
let (snippet, style) = match cx.sess().parse_sess.source_map().span_to_snippet(fmt_span) {
109+
Ok(snippet) => {
110+
// Count the number of `#`s between the `r` and `"`.
111+
let style = snippet.strip_prefix('r').and_then(|s| s.find('"'));
112+
(Some(snippet), style)
113+
}
114+
Err(_) => (None, None),
115+
};
116+
117+
let mut fmt_parser =
118+
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
119+
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
120+
121+
let (span, _) = panic_call(cx, f);
122+
123+
if n_arguments > 0 && fmt_parser.errors.is_empty() {
124+
let arg_spans: Vec<_> = match &fmt_parser.arg_places[..] {
125+
[] => vec![fmt_span],
126+
v => v.iter().map(|span| fmt_span.from_inner(*span)).collect(),
127+
};
128+
cx.struct_span_lint(NON_FMT_PANIC, arg_spans, |lint| {
129+
let mut l = lint.build(match n_arguments {
130+
1 => "panic message contains an unused formatting placeholder",
131+
_ => "panic message contains unused formatting placeholders",
132+
});
133+
l.note("this message is not used as a format string when given without arguments, but will be in Rust 2021");
134+
if span.contains(arg.span) {
135+
l.span_suggestion(
136+
arg.span.shrink_to_hi(),
137+
&format!("add the missing argument{}", pluralize!(n_arguments)),
138+
", ...".into(),
139+
Applicability::HasPlaceholders,
140+
);
141+
l.span_suggestion(
142+
arg.span.shrink_to_lo(),
143+
"or add a \"{}\" format string to use the message literally",
144+
"\"{}\", ".into(),
145+
Applicability::MachineApplicable,
146+
);
147+
}
148+
l.emit();
149+
});
150+
} else {
151+
let brace_spans: Option<Vec<_>> =
152+
snippet.filter(|s| s.starts_with('"') || s.starts_with("r#")).map(|s| {
153+
s.char_indices()
154+
.filter(|&(_, c)| c == '{' || c == '}')
155+
.map(|(i, _)| fmt_span.from_inner(InnerSpan { start: i, end: i + 1 }))
156+
.collect()
157+
});
158+
let msg = match &brace_spans {
159+
Some(v) if v.len() == 1 => "panic message contains a brace",
160+
_ => "panic message contains braces",
161+
};
162+
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or(vec![span]), |lint| {
163+
let mut l = lint.build(msg);
164+
l.note("this message is not used as a format string, but will be in Rust 2021");
165+
if span.contains(arg.span) {
166+
l.span_suggestion(
167+
arg.span.shrink_to_lo(),
168+
"add a \"{}\" format string to use the message literally",
169+
"\"{}\", ".into(),
170+
Applicability::MachineApplicable,
171+
);
172+
}
173+
l.emit();
174+
});
175+
}
176+
}
177+
178+
fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol) {
179+
let mut expn = f.span.ctxt().outer_expn_data();
180+
181+
let mut panic_macro = kw::Empty;
182+
183+
// Unwrap more levels of macro expansion, as panic_2015!()
184+
// was likely expanded from panic!() and possibly from
185+
// [debug_]assert!().
186+
for &i in
187+
&[sym::std_panic_macro, sym::core_panic_macro, sym::assert_macro, sym::debug_assert_macro]
188+
{
189+
let parent = expn.call_site.ctxt().outer_expn_data();
190+
if parent.macro_def_id.map_or(false, |id| cx.tcx.is_diagnostic_item(i, id)) {
191+
expn = parent;
192+
panic_macro = i;
193+
}
194+
}
195+
196+
(expn.call_site, panic_macro)
197+
}

‎compiler/rustc_lint/src/panic_fmt.rs

Lines changed: 0 additions & 155 deletions
This file was deleted.

‎compiler/rustc_middle/src/util/bug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::ty::{tls, TyCtxt};
44
use rustc_span::{MultiSpan, Span};
55
use std::fmt;
6-
use std::panic::Location;
6+
use std::panic::{panic_any, Location};
77

88
#[cold]
99
#[inline(never)]
@@ -32,7 +32,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
3232
match (tcx, span) {
3333
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
3434
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
35-
(None, _) => panic!(msg),
35+
(None, _) => panic_any(msg),
3636
}
3737
});
3838
unreachable!();

‎library/core/src/macros/panic.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ tests. `panic!` is closely tied with the `unwrap` method of both
1010
`panic!` when they are set to [`None`] or [`Err`] variants.
1111

1212
This macro is used to inject panic into a Rust thread, causing the thread to
13-
panic entirely. Each thread's panic can be reaped as the [`Box`]`<`[`Any`]`>` type,
14-
and the single-argument form of the `panic!` macro will be the value which
15-
is transmitted.
13+
panic entirely. This macro panics with a string and uses the [`format!`] syntax
14+
for building the message.
15+
16+
Each thread's panic can be reaped as the [`Box`]`<`[`Any`]`>` type,
17+
which contains either a `&str` or `String` for regular `panic!()` invocations.
18+
To panic with a value of another other type, [`panic_any`] can be used.
1619

1720
[`Result`] enum is often a better solution for recovering from errors than
1821
using the `panic!` macro. This macro should be used to avoid proceeding using
1922
incorrect values, such as from external sources. Detailed information about
2023
error handling is found in the [book].
2124

22-
The multi-argument form of this macro panics with a string and has the
23-
[`format!`] syntax for building a string.
24-
2525
See also the macro [`compile_error!`], for raising errors during compilation.
2626

2727
[ounwrap]: Option::unwrap
2828
[runwrap]: Result::unwrap
29+
[`panic_any`]: ../std/panic/fn.panic_any.html
2930
[`Box`]: ../std/boxed/struct.Box.html
3031
[`Any`]: crate::any::Any
3132
[`format!`]: ../std/macro.format.html
@@ -42,6 +43,6 @@ program with code `101`.
4243
# #![allow(unreachable_code)]
4344
panic!();
4445
panic!("this is a terrible mistake!");
45-
panic!(4); // panic with the value of 4 to be collected elsewhere
4646
panic!("this is a {} {message}", "fancy", message = "message");
47+
std::panic::panic_any(4); // panic with the value of 4 to be collected elsewhere
4748
```

‎library/term/src/terminfo/parm/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ fn test_comparison_ops() {
7777
for &(op, bs) in v.iter() {
7878
let s = format!("%{{1}}%{{2}}%{}%d", op);
7979
let res = expand(s.as_bytes(), &[], &mut Variables::new());
80-
assert!(res.is_ok(), res.unwrap_err());
80+
assert!(res.is_ok(), "{}", res.unwrap_err());
8181
assert_eq!(res.unwrap(), vec![b'0' + bs[0]]);
8282
let s = format!("%{{1}}%{{1}}%{}%d", op);
8383
let res = expand(s.as_bytes(), &[], &mut Variables::new());
84-
assert!(res.is_ok(), res.unwrap_err());
84+
assert!(res.is_ok(), "{}", res.unwrap_err());
8585
assert_eq!(res.unwrap(), vec![b'0' + bs[1]]);
8686
let s = format!("%{{2}}%{{1}}%{}%d", op);
8787
let res = expand(s.as_bytes(), &[], &mut Variables::new());
88-
assert!(res.is_ok(), res.unwrap_err());
88+
assert!(res.is_ok(), "{}", res.unwrap_err());
8989
assert_eq!(res.unwrap(), vec![b'0' + bs[2]]);
9090
}
9191
}
@@ -95,13 +95,13 @@ fn test_conditionals() {
9595
let mut vars = Variables::new();
9696
let s = b"\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m";
9797
let res = expand(s, &[Number(1)], &mut vars);
98-
assert!(res.is_ok(), res.unwrap_err());
98+
assert!(res.is_ok(), "{}", res.unwrap_err());
9999
assert_eq!(res.unwrap(), "\\E[31m".bytes().collect::<Vec<_>>());
100100
let res = expand(s, &[Number(8)], &mut vars);
101-
assert!(res.is_ok(), res.unwrap_err());
101+
assert!(res.is_ok(), "{}", res.unwrap_err());
102102
assert_eq!(res.unwrap(), "\\E[90m".bytes().collect::<Vec<_>>());
103103
let res = expand(s, &[Number(42)], &mut vars);
104-
assert!(res.is_ok(), res.unwrap_err());
104+
assert!(res.is_ok(), "{}", res.unwrap_err());
105105
assert_eq!(res.unwrap(), "\\E[38;5;42m".bytes().collect::<Vec<_>>());
106106
}
107107

‎library/test/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn test_should_panic_bad_message() {
199199
fn test_should_panic_non_string_message_type() {
200200
use crate::tests::TrFailedMsg;
201201
fn f() {
202-
panic!(1i32);
202+
std::panic::panic_any(1i32);
203203
}
204204
let expected = "foobar";
205205
let failed_msg = format!(

‎src/test/ui-fulldeps/issue-15149.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn test() {
5050
.output().unwrap();
5151

5252
assert!(child_output.status.success(),
53-
format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
54-
str::from_utf8(&child_output.stdout).unwrap(),
55-
str::from_utf8(&child_output.stderr).unwrap()));
53+
"child assertion failed\n child stdout:\n {}\n child stderr:\n {}",
54+
str::from_utf8(&child_output.stdout).unwrap(),
55+
str::from_utf8(&child_output.stderr).unwrap());
5656
}

‎src/test/ui/consts/const-eval/const_panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(const_panic)]
2+
#![allow(non_fmt_panic)]
23
#![crate_type = "lib"]
34

45
const MSG: &str = "hello";

‎src/test/ui/consts/const-eval/const_panic.stderr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,119 @@
11
error: any use of this value will cause an error
2-
--> $DIR/const_panic.rs:6:15
2+
--> $DIR/const_panic.rs:7:15
33
|
44
LL | const Z: () = std::panic!("cheese");
55
| --------------^^^^^^^^^^^^^^^^^^^^^-
66
| |
7-
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:6:15
7+
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:7:15
88
|
99
= note: `#[deny(const_err)]` on by default
1010
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1111
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1212
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1313

1414
error: any use of this value will cause an error
15-
--> $DIR/const_panic.rs:10:16
15+
--> $DIR/const_panic.rs:11:16
1616
|
1717
LL | const Z2: () = std::panic!();
1818
| ---------------^^^^^^^^^^^^^-
1919
| |
20-
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:10:16
20+
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:11:16
2121
|
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2424
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2525

2626
error: any use of this value will cause an error
27-
--> $DIR/const_panic.rs:14:15
27+
--> $DIR/const_panic.rs:15:15
2828
|
2929
LL | const Y: () = std::unreachable!();
3030
| --------------^^^^^^^^^^^^^^^^^^^-
3131
| |
32-
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:14:15
32+
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:15:15
3333
|
3434
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3535
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
3636
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3737

3838
error: any use of this value will cause an error
39-
--> $DIR/const_panic.rs:18:15
39+
--> $DIR/const_panic.rs:19:15
4040
|
4141
LL | const X: () = std::unimplemented!();
4242
| --------------^^^^^^^^^^^^^^^^^^^^^-
4343
| |
44-
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:18:15
44+
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:19:15
4545
|
4646
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4747
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
4848
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
4949

5050
error: any use of this value will cause an error
51-
--> $DIR/const_panic.rs:22:15
51+
--> $DIR/const_panic.rs:23:15
5252
|
5353
LL | const W: () = std::panic!(MSG);
5454
| --------------^^^^^^^^^^^^^^^^-
5555
| |
56-
| the evaluated program panicked at 'hello', $DIR/const_panic.rs:22:15
56+
| the evaluated program panicked at 'hello', $DIR/const_panic.rs:23:15
5757
|
5858
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5959
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
6060
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6161

6262
error: any use of this value will cause an error
63-
--> $DIR/const_panic.rs:26:20
63+
--> $DIR/const_panic.rs:27:20
6464
|
6565
LL | const Z_CORE: () = core::panic!("cheese");
6666
| -------------------^^^^^^^^^^^^^^^^^^^^^^-
6767
| |
68-
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:26:20
68+
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:27:20
6969
|
7070
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7171
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
7272
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
7373

7474
error: any use of this value will cause an error
75-
--> $DIR/const_panic.rs:30:21
75+
--> $DIR/const_panic.rs:31:21
7676
|
7777
LL | const Z2_CORE: () = core::panic!();
7878
| --------------------^^^^^^^^^^^^^^-
7979
| |
80-
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:30:21
80+
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:31:21
8181
|
8282
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8383
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
8484
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8585

8686
error: any use of this value will cause an error
87-
--> $DIR/const_panic.rs:34:20
87+
--> $DIR/const_panic.rs:35:20
8888
|
8989
LL | const Y_CORE: () = core::unreachable!();
9090
| -------------------^^^^^^^^^^^^^^^^^^^^-
9191
| |
92-
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:34:20
92+
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:35:20
9393
|
9494
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9595
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
9696
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
9797

9898
error: any use of this value will cause an error
99-
--> $DIR/const_panic.rs:38:20
99+
--> $DIR/const_panic.rs:39:20
100100
|
101101
LL | const X_CORE: () = core::unimplemented!();
102102
| -------------------^^^^^^^^^^^^^^^^^^^^^^-
103103
| |
104-
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:38:20
104+
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:39:20
105105
|
106106
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
107107
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
108108
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
109109

110110
error: any use of this value will cause an error
111-
--> $DIR/const_panic.rs:42:20
111+
--> $DIR/const_panic.rs:43:20
112112
|
113113
LL | const W_CORE: () = core::panic!(MSG);
114114
| -------------------^^^^^^^^^^^^^^^^^-
115115
| |
116-
| the evaluated program panicked at 'hello', $DIR/const_panic.rs:42:20
116+
| the evaluated program panicked at 'hello', $DIR/const_panic.rs:43:20
117117
|
118118
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
119119
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

‎src/test/ui/drop/dynamic-drop-async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Allocator {
8282
self.cur_ops.set(self.cur_ops.get() + 1);
8383

8484
if self.cur_ops.get() == self.failing_op {
85-
panic!(InjectedFailure);
85+
panic::panic_any(InjectedFailure);
8686
}
8787
}
8888
}

‎src/test/ui/drop/dynamic-drop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Allocator {
4646
self.cur_ops.set(self.cur_ops.get() + 1);
4747

4848
if self.cur_ops.get() == self.failing_op {
49-
panic!(InjectedFailure);
49+
panic::panic_any(InjectedFailure);
5050
}
5151

5252
let mut data = self.data.borrow_mut();
@@ -67,7 +67,7 @@ impl<'a> Drop for Ptr<'a> {
6767
self.1.cur_ops.set(self.1.cur_ops.get() + 1);
6868

6969
if self.1.cur_ops.get() == self.1.failing_op {
70-
panic!(InjectedFailure);
70+
panic::panic_any(InjectedFailure);
7171
}
7272
}
7373
}

‎src/test/ui/fmt/format-args-capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn panic_with_single_argument_does_not_get_formatted() {
3131
// RFC #2795 suggests that this may need to change so that captured arguments are formatted.
3232
// For stability reasons this will need to part of an edition change.
3333

34-
#[allow(panic_fmt)]
34+
#[allow(non_fmt_panic)]
3535
let msg = std::panic::catch_unwind(|| {
3636
panic!("{foo}");
3737
}).unwrap_err();

‎src/test/ui/macros/assert-macro-owned.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// error-pattern:panicked at 'test-assert-owned'
33
// ignore-emscripten no processes
44

5+
#![allow(non_fmt_panic)]
6+
57
fn main() {
68
assert!(false, "test-assert-owned".to_string());
79
}

‎src/test/ui/macros/macro-comma-behavior-rpass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn writeln_1arg() {
5757
//
5858
// (Example: Issue #48042)
5959
#[test]
60-
#[allow(panic_fmt)]
60+
#[allow(non_fmt_panic)]
6161
fn to_format_or_not_to_format() {
6262
// ("{}" is the easiest string to test because if this gets
6363
// sent to format_args!, it'll simply fail to compile.

‎src/test/ui/mir/mir_drop_order.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
assert_eq!(get(), vec![0, 2, 3, 1]);
3939

4040
let _ = std::panic::catch_unwind(|| {
41-
(d(4), &d(5), d(6), &d(7), panic!(InjectedFailure));
41+
(d(4), &d(5), d(6), &d(7), panic::panic_any(InjectedFailure));
4242
});
4343

4444
// here, the temporaries (5/7) live until the end of the

‎src/test/ui/panic-brace.rs renamed to ‎src/test/ui/non-fmt-panic.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@ fn main() {
1313
core::panic!("Hello {}"); //~ WARN panic message contains an unused formatting placeholder
1414
assert!(false, "{:03x} {test} bla");
1515
//~^ WARN panic message contains unused formatting placeholders
16+
assert!(false, S);
17+
//~^ WARN panic message is not a string literal
1618
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
17-
panic!(C); // No warning (yet)
18-
panic!(S); // No warning (yet)
19+
panic!(C); //~ WARN panic message is not a string literal
20+
panic!(S); //~ WARN panic message is not a string literal
21+
std::panic!(123); //~ WARN panic message is not a string literal
22+
core::panic!(&*"abc"); //~ WARN panic message is not a string literal
1923
panic!(concat!("{", "}")); //~ WARN panic message contains an unused formatting placeholder
2024
panic!(concat!("{", "{")); //~ WARN panic message contains braces
2125

2226
fancy_panic::fancy_panic!("test {} 123");
2327
//~^ WARN panic message contains an unused formatting placeholder
2428

29+
fancy_panic::fancy_panic!(S);
30+
//~^ WARN panic message is not a string literal
31+
2532
// Check that the lint only triggers for std::panic and core::panic,
2633
// not any panic macro:
2734
macro_rules! panic {
2835
($e:expr) => ();
2936
}
3037
panic!("{}"); // OK
38+
panic!(S); // OK
3139
}
Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
warning: panic message contains a brace
2-
--> $DIR/panic-brace.rs:11:29
2+
--> $DIR/non-fmt-panic.rs:11:29
33
|
44
LL | panic!("here's a brace: {");
55
| ^
66
|
7-
= note: `#[warn(panic_fmt)]` on by default
8-
= note: this message is not used as a format string, but will be in a future Rust edition
7+
= note: `#[warn(non_fmt_panic)]` on by default
8+
= note: this message is not used as a format string, but will be in Rust 2021
99
help: add a "{}" format string to use the message literally
1010
|
1111
LL | panic!("{}", "here's a brace: {");
1212
| ^^^^^
1313

1414
warning: panic message contains a brace
15-
--> $DIR/panic-brace.rs:12:31
15+
--> $DIR/non-fmt-panic.rs:12:31
1616
|
1717
LL | std::panic!("another one: }");
1818
| ^
1919
|
20-
= note: this message is not used as a format string, but will be in a future Rust edition
20+
= note: this message is not used as a format string, but will be in Rust 2021
2121
help: add a "{}" format string to use the message literally
2222
|
2323
LL | std::panic!("{}", "another one: }");
2424
| ^^^^^
2525

2626
warning: panic message contains an unused formatting placeholder
27-
--> $DIR/panic-brace.rs:13:25
27+
--> $DIR/non-fmt-panic.rs:13:25
2828
|
2929
LL | core::panic!("Hello {}");
3030
| ^^
3131
|
32-
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
32+
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
3333
help: add the missing argument
3434
|
3535
LL | core::panic!("Hello {}", ...);
@@ -40,12 +40,12 @@ LL | core::panic!("{}", "Hello {}");
4040
| ^^^^^
4141

4242
warning: panic message contains unused formatting placeholders
43-
--> $DIR/panic-brace.rs:14:21
43+
--> $DIR/non-fmt-panic.rs:14:21
4444
|
4545
LL | assert!(false, "{:03x} {test} bla");
4646
| ^^^^^^ ^^^^^^
4747
|
48-
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
48+
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
4949
help: add the missing arguments
5050
|
5151
LL | assert!(false, "{:03x} {test} bla", ...);
@@ -55,25 +55,97 @@ help: or add a "{}" format string to use the message literally
5555
LL | assert!(false, "{}", "{:03x} {test} bla");
5656
| ^^^^^
5757

58+
warning: panic message is not a string literal
59+
--> $DIR/non-fmt-panic.rs:16:20
60+
|
61+
LL | assert!(false, S);
62+
| ^
63+
|
64+
= note: this is no longer accepted in Rust 2021
65+
help: add a "{}" format string to Display the message
66+
|
67+
LL | assert!(false, "{}", S);
68+
| ^^^^^
69+
5870
warning: panic message contains braces
59-
--> $DIR/panic-brace.rs:16:27
71+
--> $DIR/non-fmt-panic.rs:18:27
6072
|
6173
LL | debug_assert!(false, "{{}} bla");
6274
| ^^^^
6375
|
64-
= note: this message is not used as a format string, but will be in a future Rust edition
76+
= note: this message is not used as a format string, but will be in Rust 2021
6577
help: add a "{}" format string to use the message literally
6678
|
6779
LL | debug_assert!(false, "{}", "{{}} bla");
6880
| ^^^^^
6981

82+
warning: panic message is not a string literal
83+
--> $DIR/non-fmt-panic.rs:19:12
84+
|
85+
LL | panic!(C);
86+
| ^
87+
|
88+
= note: this is no longer accepted in Rust 2021
89+
help: add a "{}" format string to Display the message
90+
|
91+
LL | panic!("{}", C);
92+
| ^^^^^
93+
help: or use std::panic::panic_any instead
94+
|
95+
LL | std::panic::panic_any(C);
96+
| ^^^^^^^^^^^^^^^^^^^^^^
97+
98+
warning: panic message is not a string literal
99+
--> $DIR/non-fmt-panic.rs:20:12
100+
|
101+
LL | panic!(S);
102+
| ^
103+
|
104+
= note: this is no longer accepted in Rust 2021
105+
help: add a "{}" format string to Display the message
106+
|
107+
LL | panic!("{}", S);
108+
| ^^^^^
109+
help: or use std::panic::panic_any instead
110+
|
111+
LL | std::panic::panic_any(S);
112+
| ^^^^^^^^^^^^^^^^^^^^^^
113+
114+
warning: panic message is not a string literal
115+
--> $DIR/non-fmt-panic.rs:21:17
116+
|
117+
LL | std::panic!(123);
118+
| ^^^
119+
|
120+
= note: this is no longer accepted in Rust 2021
121+
help: add a "{}" format string to Display the message
122+
|
123+
LL | std::panic!("{}", 123);
124+
| ^^^^^
125+
help: or use std::panic::panic_any instead
126+
|
127+
LL | std::panic::panic_any(123);
128+
| ^^^^^^^^^^^^^^^^^^^^^^
129+
130+
warning: panic message is not a string literal
131+
--> $DIR/non-fmt-panic.rs:22:18
132+
|
133+
LL | core::panic!(&*"abc");
134+
| ^^^^^^^
135+
|
136+
= note: this is no longer accepted in Rust 2021
137+
help: add a "{}" format string to Display the message
138+
|
139+
LL | core::panic!("{}", &*"abc");
140+
| ^^^^^
141+
70142
warning: panic message contains an unused formatting placeholder
71-
--> $DIR/panic-brace.rs:19:12
143+
--> $DIR/non-fmt-panic.rs:23:12
72144
|
73145
LL | panic!(concat!("{", "}"));
74146
| ^^^^^^^^^^^^^^^^^
75147
|
76-
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
148+
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
77149
help: add the missing argument
78150
|
79151
LL | panic!(concat!("{", "}"), ...);
@@ -84,24 +156,32 @@ LL | panic!("{}", concat!("{", "}"));
84156
| ^^^^^
85157

86158
warning: panic message contains braces
87-
--> $DIR/panic-brace.rs:20:5
159+
--> $DIR/non-fmt-panic.rs:24:5
88160
|
89161
LL | panic!(concat!("{", "{"));
90162
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
91163
|
92-
= note: this message is not used as a format string, but will be in a future Rust edition
164+
= note: this message is not used as a format string, but will be in Rust 2021
93165
help: add a "{}" format string to use the message literally
94166
|
95167
LL | panic!("{}", concat!("{", "{"));
96168
| ^^^^^
97169

98170
warning: panic message contains an unused formatting placeholder
99-
--> $DIR/panic-brace.rs:22:37
171+
--> $DIR/non-fmt-panic.rs:26:37
100172
|
101173
LL | fancy_panic::fancy_panic!("test {} 123");
102174
| ^^
103175
|
104-
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
176+
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
177+
178+
warning: panic message is not a string literal
179+
--> $DIR/non-fmt-panic.rs:29:31
180+
|
181+
LL | fancy_panic::fancy_panic!(S);
182+
| ^
183+
|
184+
= note: this is no longer accepted in Rust 2021
105185

106-
warning: 8 warnings emitted
186+
warning: 14 warnings emitted
107187

‎src/test/ui/panics/explicit-panic-msg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(unused_assignments)]
22
#![allow(unused_variables)]
3+
#![allow(non_fmt_panic)]
34

45
// run-fail
56
// error-pattern:wooooo

‎src/test/ui/panics/panic-macro-any-wrapped.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// error-pattern:panicked at 'Box<Any>'
33
// ignore-emscripten no processes
44

5+
#![allow(non_fmt_panic)]
6+
57
fn main() {
68
panic!(Box::new(612_i64));
79
}

‎src/test/ui/panics/panic-macro-any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ignore-emscripten no processes
44

55
#![feature(box_syntax)]
6+
#![allow(non_fmt_panic)]
67

78
fn main() {
89
panic!(box 413 as Box<dyn std::any::Any + Send>);

‎src/test/ui/panics/while-panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// ignore-emscripten no processes
66

77
fn main() {
8-
panic!({
8+
panic!("{}", {
99
while true {
1010
panic!("giraffe")
1111
}

‎src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ fn lint_expect_fun_call(
21832183
span_replace_word,
21842184
&format!("use of `{}` followed by a function call", name),
21852185
"try this",
2186-
format!("unwrap_or_else({} {{ panic!({}) }})", closure_args, arg_root_snippet),
2186+
format!("unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})", closure_args, arg_root_snippet),
21872187
applicability,
21882188
);
21892189
}

‎src/tools/clippy/tests/missing-test-files.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ fn test_missing_tests() {
99
if !missing_files.is_empty() {
1010
assert!(
1111
false,
12-
format!(
13-
"Didn't see a test file for the following files:\n\n{}\n",
14-
missing_files
15-
.iter()
16-
.map(|s| format!("\t{}", s))
17-
.collect::<Vec<_>>()
18-
.join("\n")
19-
)
12+
"Didn't see a test file for the following files:\n\n{}\n",
13+
missing_files
14+
.iter()
15+
.map(|s| format!("\t{}", s))
16+
.collect::<Vec<_>>()
17+
.join("\n")
2018
);
2119
}
2220
}

‎src/tools/clippy/tests/ui/assertions_on_constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_fmt_panic)]
2+
13
macro_rules! assert_const {
24
($len:expr) => {
35
assert!($len > 0);

‎src/tools/clippy/tests/ui/assertions_on_constants.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `assert!(true)` will be optimized out by the compiler
2-
--> $DIR/assertions_on_constants.rs:9:5
2+
--> $DIR/assertions_on_constants.rs:11:5
33
|
44
LL | assert!(true);
55
| ^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | assert!(true);
99
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1010

1111
error: `assert!(false)` should probably be replaced
12-
--> $DIR/assertions_on_constants.rs:10:5
12+
--> $DIR/assertions_on_constants.rs:12:5
1313
|
1414
LL | assert!(false);
1515
| ^^^^^^^^^^^^^^^
@@ -18,7 +18,7 @@ LL | assert!(false);
1818
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error: `assert!(true)` will be optimized out by the compiler
21-
--> $DIR/assertions_on_constants.rs:11:5
21+
--> $DIR/assertions_on_constants.rs:13:5
2222
|
2323
LL | assert!(true, "true message");
2424
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | assert!(true, "true message");
2727
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2828

2929
error: `assert!(false, "false message")` should probably be replaced
30-
--> $DIR/assertions_on_constants.rs:12:5
30+
--> $DIR/assertions_on_constants.rs:14:5
3131
|
3232
LL | assert!(false, "false message");
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | assert!(false, "false message");
3636
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3737

3838
error: `assert!(false, msg.to_uppercase())` should probably be replaced
39-
--> $DIR/assertions_on_constants.rs:15:5
39+
--> $DIR/assertions_on_constants.rs:17:5
4040
|
4141
LL | assert!(false, msg.to_uppercase());
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -45,7 +45,7 @@ LL | assert!(false, msg.to_uppercase());
4545
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
4646

4747
error: `assert!(true)` will be optimized out by the compiler
48-
--> $DIR/assertions_on_constants.rs:18:5
48+
--> $DIR/assertions_on_constants.rs:20:5
4949
|
5050
LL | assert!(B);
5151
| ^^^^^^^^^^^
@@ -54,7 +54,7 @@ LL | assert!(B);
5454
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5555

5656
error: `assert!(false)` should probably be replaced
57-
--> $DIR/assertions_on_constants.rs:21:5
57+
--> $DIR/assertions_on_constants.rs:23:5
5858
|
5959
LL | assert!(C);
6060
| ^^^^^^^^^^^
@@ -63,7 +63,7 @@ LL | assert!(C);
6363
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6464

6565
error: `assert!(false, "C message")` should probably be replaced
66-
--> $DIR/assertions_on_constants.rs:22:5
66+
--> $DIR/assertions_on_constants.rs:24:5
6767
|
6868
LL | assert!(C, "C message");
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | assert!(C, "C message");
7272
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
7373

7474
error: `debug_assert!(true)` will be optimized out by the compiler
75-
--> $DIR/assertions_on_constants.rs:24:5
75+
--> $DIR/assertions_on_constants.rs:26:5
7676
|
7777
LL | debug_assert!(true);
7878
| ^^^^^^^^^^^^^^^^^^^^

‎src/tools/clippy/tests/ui/expect_fun_call.fixed

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ fn main() {
7474
"foo"
7575
}
7676

77-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
78-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
79-
Some("foo").unwrap_or_else(|| { panic!(get_string()) });
77+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
78+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
79+
Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
8080

81-
Some("foo").unwrap_or_else(|| { panic!(get_static_str()) });
82-
Some("foo").unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) });
81+
Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
82+
Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
8383
}
8484

8585
//Issue #3839

‎src/tools/clippy/tests/ui/expect_fun_call.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@ error: use of `expect` followed by a function call
3434
--> $DIR/expect_fun_call.rs:77:21
3535
|
3636
LL | Some("foo").expect(&get_string());
37-
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
37+
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
3838

3939
error: use of `expect` followed by a function call
4040
--> $DIR/expect_fun_call.rs:78:21
4141
|
4242
LL | Some("foo").expect(get_string().as_ref());
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
4444

4545
error: use of `expect` followed by a function call
4646
--> $DIR/expect_fun_call.rs:79:21
4747
|
4848
LL | Some("foo").expect(get_string().as_str());
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_string()) })`
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
5050

5151
error: use of `expect` followed by a function call
5252
--> $DIR/expect_fun_call.rs:81:21
5353
|
5454
LL | Some("foo").expect(get_static_str());
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_static_str()) })`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
5656

5757
error: use of `expect` followed by a function call
5858
--> $DIR/expect_fun_call.rs:82:21
5959
|
6060
LL | Some("foo").expect(get_non_static_str(&0));
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!(get_non_static_str(&0).to_string()) })`
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
6262

6363
error: use of `expect` followed by a function call
6464
--> $DIR/expect_fun_call.rs:86:16

‎src/tools/clippy/tests/ui/fallible_impl_from.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl From<Option<String>> for Invalid {
3636
fn from(s: Option<String>) -> Invalid {
3737
let s = s.unwrap();
3838
if !s.is_empty() {
39-
panic!(42);
39+
panic!("42");
4040
} else if s.parse::<u32>().unwrap() != 42 {
4141
panic!("{:?}", s);
4242
}

‎src/tools/clippy/tests/ui/fallible_impl_from.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ note: potential failure(s)
5959
LL | let s = s.unwrap();
6060
| ^^^^^^^^^^
6161
LL | if !s.is_empty() {
62-
LL | panic!(42);
63-
| ^^^^^^^^^^^
62+
LL | panic!("42");
63+
| ^^^^^^^^^^^^^
6464
LL | } else if s.parse::<u32>().unwrap() != 42 {
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6666
LL | panic!("{:?}", s);

0 commit comments

Comments
 (0)
Please sign in to comment.