Turn non_fmt_panic into a future_incompatible edition lint.

This commit is contained in:
Mara Bos 2021-06-27 14:47:26 +00:00
parent 7f4e343893
commit 934e6058eb
2 changed files with 32 additions and 13 deletions

View File

@ -4,6 +4,8 @@ use rustc_errors::{pluralize, Applicability};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_parse_format::{ParseMode, Parser, Piece}; use rustc_parse_format::{ParseMode, Parser, Piece};
use rustc_session::lint::FutureIncompatibilityReason;
use rustc_span::edition::Edition;
use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol}; use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol};
declare_lint! { declare_lint! {
@ -30,6 +32,10 @@ declare_lint! {
NON_FMT_PANIC, NON_FMT_PANIC,
Warn, Warn,
"detect single-argument panic!() invocations in which the argument is not a format string", "detect single-argument panic!() invocations in which the argument is not a format string",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
explain_reason: false,
};
report_in_external_macro report_in_external_macro
} }
@ -87,7 +93,8 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
cx.struct_span_lint(NON_FMT_PANIC, arg_span, |lint| { cx.struct_span_lint(NON_FMT_PANIC, arg_span, |lint| {
let mut l = lint.build("panic message is not a string literal"); let mut l = lint.build("panic message is not a string literal");
l.note("this is no longer accepted in Rust 2021"); l.note("this usage of panic!() is deprecated; it will be a hard error in Rust 2021");
l.note("for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>");
if !span.contains(arg_span) { if !span.contains(arg_span) {
// No clue where this argument is coming from. // No clue where this argument is coming from.
l.emit(); l.emit();

View File

@ -61,7 +61,8 @@ warning: panic message is not a string literal
LL | assert!(false, S); LL | assert!(false, S);
| ^ | ^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | assert!(false, "{}", S); LL | assert!(false, "{}", S);
@ -85,7 +86,8 @@ warning: panic message is not a string literal
LL | panic!(C); LL | panic!(C);
| ^ | ^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | panic!("{}", C); LL | panic!("{}", C);
@ -101,7 +103,8 @@ warning: panic message is not a string literal
LL | panic!(S); LL | panic!(S);
| ^ | ^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | panic!("{}", S); LL | panic!("{}", S);
@ -117,7 +120,8 @@ warning: panic message is not a string literal
LL | std::panic!(123); LL | std::panic!(123);
| ^^^ | ^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | std::panic!("{}", 123); LL | std::panic!("{}", 123);
@ -133,7 +137,8 @@ warning: panic message is not a string literal
LL | core::panic!(&*"abc"); LL | core::panic!(&*"abc");
| ^^^^^^^ | ^^^^^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | core::panic!("{}", &*"abc"); LL | core::panic!("{}", &*"abc");
@ -181,7 +186,8 @@ warning: panic message is not a string literal
LL | fancy_panic::fancy_panic!(S); LL | fancy_panic::fancy_panic!(S);
| ^ | ^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
warning: panic message is not a string literal warning: panic message is not a string literal
--> $DIR/non-fmt-panic.rs:36:12 --> $DIR/non-fmt-panic.rs:36:12
@ -189,7 +195,8 @@ warning: panic message is not a string literal
LL | panic!(a!()); LL | panic!(a!());
| ^^^^ | ^^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | panic!("{}", a!()); LL | panic!("{}", a!());
@ -205,7 +212,8 @@ warning: panic message is not a string literal
LL | panic!(format!("{}", 1)); LL | panic!(format!("{}", 1));
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
= note: the panic!() macro supports formatting, so there's no need for the format!() macro here = note: the panic!() macro supports formatting, so there's no need for the format!() macro here
help: remove the `format!(..)` macro call help: remove the `format!(..)` macro call
| |
@ -218,7 +226,8 @@ warning: panic message is not a string literal
LL | assert!(false, format!("{}", 1)); LL | assert!(false, format!("{}", 1));
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
= note: the assert!() macro supports formatting, so there's no need for the format!() macro here = note: the assert!() macro supports formatting, so there's no need for the format!() macro here
help: remove the `format!(..)` macro call help: remove the `format!(..)` macro call
| |
@ -231,7 +240,8 @@ warning: panic message is not a string literal
LL | debug_assert!(false, format!("{}", 1)); LL | debug_assert!(false, format!("{}", 1));
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
= note: the debug_assert!() macro supports formatting, so there's no need for the format!() macro here = note: the debug_assert!() macro supports formatting, so there's no need for the format!() macro here
help: remove the `format!(..)` macro call help: remove the `format!(..)` macro call
| |
@ -244,7 +254,8 @@ warning: panic message is not a string literal
LL | panic![123]; LL | panic![123];
| ^^^ | ^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | panic!["{}", 123]; LL | panic!["{}", 123];
@ -260,7 +271,8 @@ warning: panic message is not a string literal
LL | panic!{123}; LL | panic!{123};
| ^^^ | ^^^
| |
= note: this is no longer accepted in Rust 2021 = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
help: add a "{}" format string to Display the message help: add a "{}" format string to Display the message
| |
LL | panic!{"{}", 123}; LL | panic!{"{}", 123};