Skip to content

Commit

Permalink
Improve panic_fmt lint messages.
Browse files Browse the repository at this point in the history
(From the PR feedback.)

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
  • Loading branch information
m-ou-se and estebank committed Oct 29, 2020
1 parent 5cefc3c commit 9743f67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_lint/src/panic_fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{LateContext, LateLintPass, LintContext};
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_errors::{pluralize, Applicability};
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_parse_format::{ParseMode, Parser, Piece};
Expand All @@ -21,7 +21,7 @@ declare_lint! {
///
/// `panic!("{}")` panics with the message `"{}"`, as a `panic!()` invocation
/// with a single argument does not use `format_args!()`.
/// A future version of Rust will interpret this string as format string,
/// A future edition of Rust will interpret this string as format string,
/// which would break this.
PANIC_FMT,
Warn,
Expand Down Expand Up @@ -97,11 +97,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
1 => "panic message contains an unused formatting placeholder",
_ => "panic message contains unused formatting placeholders",
});
l.note("this message is not used as a format string when given without arguments, but will be in a future Rust version");
l.note("this message is not used as a format string when given without arguments, but will be in a future Rust edition");
if expn.call_site.contains(arg.span) {
l.span_suggestion(
arg.span.shrink_to_hi(),
"add the missing argument(s)",
&format!("add the missing argument{}", pluralize!(n_arguments)),
", ...".into(),
Applicability::HasPlaceholders,
);
Expand Down Expand Up @@ -131,7 +131,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
};
cx.struct_span_lint(PANIC_FMT, brace_spans.unwrap_or(vec![expn.call_site]), |lint| {
let mut l = lint.build(msg);
l.note("this message is not used as a format string, but will be in a future Rust version");
l.note("this message is not used as a format string, but will be in a future Rust edition");
if expn.call_site.contains(arg.span) {
l.span_suggestion(
arg.span.shrink_to_lo(),
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/panic-brace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | panic!("here's a brace: {");
| ^
|
= note: `#[warn(panic_fmt)]` on by default
= note: this message is not used as a format string, but will be in a future Rust version
= note: this message is not used as a format string, but will be in a future Rust edition
help: add a "{}" format string to use the message literally
|
LL | panic!("{}", "here's a brace: {");
Expand All @@ -17,7 +17,7 @@ warning: panic message contains a brace
LL | std::panic!("another one: }");
| ^
|
= note: this message is not used as a format string, but will be in a future Rust version
= note: this message is not used as a format string, but will be in a future Rust edition
help: add a "{}" format string to use the message literally
|
LL | std::panic!("{}", "another one: }");
Expand All @@ -29,8 +29,8 @@ warning: panic message contains an unused formatting placeholder
LL | core::panic!("Hello {}");
| ^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
help: add the missing argument(s)
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
help: add the missing argument
|
LL | core::panic!("Hello {}", ...);
| ^^^^^
Expand All @@ -45,8 +45,8 @@ warning: panic message contains unused formatting placeholders
LL | assert!(false, "{:03x} {test} bla");
| ^^^^^^ ^^^^^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
help: add the missing argument(s)
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
help: add the missing arguments
|
LL | assert!(false, "{:03x} {test} bla", ...);
| ^^^^^
Expand All @@ -61,7 +61,7 @@ warning: panic message contains braces
LL | debug_assert!(false, "{{}} bla");
| ^^^^
|
= note: this message is not used as a format string, but will be in a future Rust version
= note: this message is not used as a format string, but will be in a future Rust edition
help: add a "{}" format string to use the message literally
|
LL | debug_assert!(false, "{}", "{{}} bla");
Expand All @@ -73,8 +73,8 @@ warning: panic message contains an unused formatting placeholder
LL | panic!(concat!("{", "}"));
| ^^^^^^^^^^^^^^^^^
|
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
help: add the missing argument(s)
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
help: add the missing argument
|
LL | panic!(concat!("{", "}"), ...);
| ^^^^^
Expand All @@ -89,7 +89,7 @@ warning: panic message contains braces
LL | panic!(concat!("{", "{"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this message is not used as a format string, but will be in a future Rust version
= note: this message is not used as a format string, but will be in a future Rust edition
help: add a "{}" format string to use the message literally
|
LL | panic!("{}", concat!("{", "{"));
Expand Down

0 comments on commit 9743f67

Please sign in to comment.