Skip to content

Commit 934e605

Browse files
committed
Turn non_fmt_panic into a future_incompatible edition lint.
1 parent 7f4e343 commit 934e605

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

compiler/rustc_lint/src/non_fmt_panic.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use rustc_errors::{pluralize, Applicability};
44
use rustc_hir as hir;
55
use rustc_middle::ty;
66
use rustc_parse_format::{ParseMode, Parser, Piece};
7+
use rustc_session::lint::FutureIncompatibilityReason;
8+
use rustc_span::edition::Edition;
79
use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol};
810

911
declare_lint! {
@@ -30,6 +32,10 @@ declare_lint! {
3032
NON_FMT_PANIC,
3133
Warn,
3234
"detect single-argument panic!() invocations in which the argument is not a format string",
35+
@future_incompatible = FutureIncompatibleInfo {
36+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
37+
explain_reason: false,
38+
};
3339
report_in_external_macro
3440
}
3541

@@ -87,7 +93,8 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
8793

8894
cx.struct_span_lint(NON_FMT_PANIC, arg_span, |lint| {
8995
let mut l = lint.build("panic message is not a string literal");
90-
l.note("this is no longer accepted in Rust 2021");
96+
l.note("this usage of panic!() is deprecated; it will be a hard error in Rust 2021");
97+
l.note("for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>");
9198
if !span.contains(arg_span) {
9299
// No clue where this argument is coming from.
93100
l.emit();

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

+24-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ warning: panic message is not a string literal
6161
LL | assert!(false, S);
6262
| ^
6363
|
64-
= note: this is no longer accepted in Rust 2021
64+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
65+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
6566
help: add a "{}" format string to Display the message
6667
|
6768
LL | assert!(false, "{}", S);
@@ -85,7 +86,8 @@ warning: panic message is not a string literal
8586
LL | panic!(C);
8687
| ^
8788
|
88-
= note: this is no longer accepted in Rust 2021
89+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
90+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
8991
help: add a "{}" format string to Display the message
9092
|
9193
LL | panic!("{}", C);
@@ -101,7 +103,8 @@ warning: panic message is not a string literal
101103
LL | panic!(S);
102104
| ^
103105
|
104-
= note: this is no longer accepted in Rust 2021
106+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
107+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
105108
help: add a "{}" format string to Display the message
106109
|
107110
LL | panic!("{}", S);
@@ -117,7 +120,8 @@ warning: panic message is not a string literal
117120
LL | std::panic!(123);
118121
| ^^^
119122
|
120-
= note: this is no longer accepted in Rust 2021
123+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
124+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
121125
help: add a "{}" format string to Display the message
122126
|
123127
LL | std::panic!("{}", 123);
@@ -133,7 +137,8 @@ warning: panic message is not a string literal
133137
LL | core::panic!(&*"abc");
134138
| ^^^^^^^
135139
|
136-
= note: this is no longer accepted in Rust 2021
140+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
141+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
137142
help: add a "{}" format string to Display the message
138143
|
139144
LL | core::panic!("{}", &*"abc");
@@ -181,15 +186,17 @@ warning: panic message is not a string literal
181186
LL | fancy_panic::fancy_panic!(S);
182187
| ^
183188
|
184-
= note: this is no longer accepted in Rust 2021
189+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
190+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
185191

186192
warning: panic message is not a string literal
187193
--> $DIR/non-fmt-panic.rs:36:12
188194
|
189195
LL | panic!(a!());
190196
| ^^^^
191197
|
192-
= note: this is no longer accepted in Rust 2021
198+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
199+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
193200
help: add a "{}" format string to Display the message
194201
|
195202
LL | panic!("{}", a!());
@@ -205,7 +212,8 @@ warning: panic message is not a string literal
205212
LL | panic!(format!("{}", 1));
206213
| ^^^^^^^^^^^^^^^^
207214
|
208-
= note: this is no longer accepted in Rust 2021
215+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
216+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
209217
= note: the panic!() macro supports formatting, so there's no need for the format!() macro here
210218
help: remove the `format!(..)` macro call
211219
|
@@ -218,7 +226,8 @@ warning: panic message is not a string literal
218226
LL | assert!(false, format!("{}", 1));
219227
| ^^^^^^^^^^^^^^^^
220228
|
221-
= note: this is no longer accepted in Rust 2021
229+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
230+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
222231
= note: the assert!() macro supports formatting, so there's no need for the format!() macro here
223232
help: remove the `format!(..)` macro call
224233
|
@@ -231,7 +240,8 @@ warning: panic message is not a string literal
231240
LL | debug_assert!(false, format!("{}", 1));
232241
| ^^^^^^^^^^^^^^^^
233242
|
234-
= note: this is no longer accepted in Rust 2021
243+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
244+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
235245
= note: the debug_assert!() macro supports formatting, so there's no need for the format!() macro here
236246
help: remove the `format!(..)` macro call
237247
|
@@ -244,7 +254,8 @@ warning: panic message is not a string literal
244254
LL | panic![123];
245255
| ^^^
246256
|
247-
= note: this is no longer accepted in Rust 2021
257+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
258+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
248259
help: add a "{}" format string to Display the message
249260
|
250261
LL | panic!["{}", 123];
@@ -260,7 +271,8 @@ warning: panic message is not a string literal
260271
LL | panic!{123};
261272
| ^^^
262273
|
263-
= note: this is no longer accepted in Rust 2021
274+
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
275+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
264276
help: add a "{}" format string to Display the message
265277
|
266278
LL | panic!{"{}", 123};

0 commit comments

Comments
 (0)