Skip to content

Commit 9743f67

Browse files
m-ou-seestebank
andcommitted
Improve panic_fmt lint messages.
(From the PR feedback.) Co-authored-by: Esteban Küber <[email protected]>
1 parent 5cefc3c commit 9743f67

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

compiler/rustc_lint/src/panic_fmt.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{LateContext, LateLintPass, LintContext};
22
use rustc_ast as ast;
3-
use rustc_errors::Applicability;
3+
use rustc_errors::{pluralize, Applicability};
44
use rustc_hir as hir;
55
use rustc_middle::ty;
66
use rustc_parse_format::{ParseMode, Parser, Piece};
@@ -21,7 +21,7 @@ declare_lint! {
2121
///
2222
/// `panic!("{}")` panics with the message `"{}"`, as a `panic!()` invocation
2323
/// with a single argument does not use `format_args!()`.
24-
/// A future version of Rust will interpret this string as format string,
24+
/// A future edition of Rust will interpret this string as format string,
2525
/// which would break this.
2626
PANIC_FMT,
2727
Warn,
@@ -97,11 +97,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
9797
1 => "panic message contains an unused formatting placeholder",
9898
_ => "panic message contains unused formatting placeholders",
9999
});
100-
l.note("this message is not used as a format string when given without arguments, but will be in a future Rust version");
100+
l.note("this message is not used as a format string when given without arguments, but will be in a future Rust edition");
101101
if expn.call_site.contains(arg.span) {
102102
l.span_suggestion(
103103
arg.span.shrink_to_hi(),
104-
"add the missing argument(s)",
104+
&format!("add the missing argument{}", pluralize!(n_arguments)),
105105
", ...".into(),
106106
Applicability::HasPlaceholders,
107107
);
@@ -131,7 +131,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
131131
};
132132
cx.struct_span_lint(PANIC_FMT, brace_spans.unwrap_or(vec![expn.call_site]), |lint| {
133133
let mut l = lint.build(msg);
134-
l.note("this message is not used as a format string, but will be in a future Rust version");
134+
l.note("this message is not used as a format string, but will be in a future Rust edition");
135135
if expn.call_site.contains(arg.span) {
136136
l.span_suggestion(
137137
arg.span.shrink_to_lo(),

src/test/ui/panic-brace.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | panic!("here's a brace: {");
55
| ^
66
|
77
= 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 version
8+
= note: this message is not used as a format string, but will be in a future Rust edition
99
help: add a "{}" format string to use the message literally
1010
|
1111
LL | panic!("{}", "here's a brace: {");
@@ -17,7 +17,7 @@ warning: panic message contains a brace
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 version
20+
= note: this message is not used as a format string, but will be in a future Rust edition
2121
help: add a "{}" format string to use the message literally
2222
|
2323
LL | std::panic!("{}", "another one: }");
@@ -29,8 +29,8 @@ warning: panic message contains an unused formatting placeholder
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 version
33-
help: add the missing argument(s)
32+
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
33+
help: add the missing argument
3434
|
3535
LL | core::panic!("Hello {}", ...);
3636
| ^^^^^
@@ -45,8 +45,8 @@ warning: panic message contains unused formatting placeholders
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 version
49-
help: add the missing argument(s)
48+
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
49+
help: add the missing arguments
5050
|
5151
LL | assert!(false, "{:03x} {test} bla", ...);
5252
| ^^^^^
@@ -61,7 +61,7 @@ warning: panic message contains braces
6161
LL | debug_assert!(false, "{{}} bla");
6262
| ^^^^
6363
|
64-
= note: this message is not used as a format string, but will be in a future Rust version
64+
= note: this message is not used as a format string, but will be in a future Rust edition
6565
help: add a "{}" format string to use the message literally
6666
|
6767
LL | debug_assert!(false, "{}", "{{}} bla");
@@ -73,8 +73,8 @@ warning: panic message contains an unused formatting placeholder
7373
LL | panic!(concat!("{", "}"));
7474
| ^^^^^^^^^^^^^^^^^
7575
|
76-
= note: this message is not used as a format string when given without arguments, but will be in a future Rust version
77-
help: add the missing argument(s)
76+
= note: this message is not used as a format string when given without arguments, but will be in a future Rust edition
77+
help: add the missing argument
7878
|
7979
LL | panic!(concat!("{", "}"), ...);
8080
| ^^^^^
@@ -89,7 +89,7 @@ warning: panic message contains braces
8989
LL | panic!(concat!("{", "{"));
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
9191
|
92-
= note: this message is not used as a format string, but will be in a future Rust version
92+
= note: this message is not used as a format string, but will be in a future Rust edition
9393
help: add a "{}" format string to use the message literally
9494
|
9595
LL | panic!("{}", concat!("{", "{"));

0 commit comments

Comments
 (0)