Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beta] Rename panic_fmt lint to non_fmt_panic #81729

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/rustc_lint/src/panic_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use rustc_parse_format::{ParseMode, Parser, Piece};
use rustc_span::{sym, InnerSpan};

declare_lint! {
/// The `panic_fmt` lint detects `panic!("..")` with `{` or `}` in the string literal.
/// The `non_fmt_panic` lint detects `panic!("..")` with `{` or `}` in the string literal
/// when it is not used as a format string.
///
/// ### Example
///
Expand All @@ -23,13 +24,13 @@ declare_lint! {
/// with a single argument does not use `format_args!()`.
/// A future edition of Rust will interpret this string as format string,
/// which would break this.
PANIC_FMT,
NON_FMT_PANIC,
Warn,
"detect braces in single-argument panic!() invocations",
report_in_external_macro
}

declare_lint_pass!(PanicFmt => [PANIC_FMT]);
declare_lint_pass!(PanicFmt => [NON_FMT_PANIC]);

impl<'tcx> LateLintPass<'tcx> for PanicFmt {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
Expand Down Expand Up @@ -92,7 +93,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
[] => vec![fmt_span],
v => v.iter().map(|span| fmt_span.from_inner(*span)).collect(),
};
cx.struct_span_lint(PANIC_FMT, arg_spans, |lint| {
cx.struct_span_lint(NON_FMT_PANIC, arg_spans, |lint| {
let mut l = lint.build(match n_arguments {
1 => "panic message contains an unused formatting placeholder",
_ => "panic message contains unused formatting placeholders",
Expand Down Expand Up @@ -129,7 +130,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
Some(v) if v.len() == 1 => "panic message contains a brace",
_ => "panic message contains braces",
};
cx.struct_span_lint(PANIC_FMT, brace_spans.unwrap_or(vec![expn.call_site]), |lint| {
cx.struct_span_lint(NON_FMT_PANIC, 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 edition");
if expn.call_site.contains(arg.span) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/fmt/format-args-capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn panic_with_single_argument_does_not_get_formatted() {
// RFC #2795 suggests that this may need to change so that captured arguments are formatted.
// For stability reasons this will need to part of an edition change.

#[allow(panic_fmt)]
#[allow(non_fmt_panic)]
let msg = std::panic::catch_unwind(|| {
panic!("{foo}");
}).unwrap_err();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-comma-behavior-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn writeln_1arg() {
//
// (Example: Issue #48042)
#[test]
#[allow(panic_fmt)]
#[allow(non_fmt_panic)]
fn to_format_or_not_to_format() {
// ("{}" is the easiest string to test because if this gets
// sent to format_args!, it'll simply fail to compile.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panic-brace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: panic message contains a brace
LL | panic!("here's a brace: {");
| ^
|
= note: `#[warn(panic_fmt)]` on by default
= note: `#[warn(non_fmt_panic)]` on by default
= 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
|
Expand Down