Skip to content

Commit

Permalink
Add s to non_fmt_panic
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Jul 6, 2021
1 parent 4e5b78f commit a902e25
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Expand Up @@ -327,6 +327,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
store.register_renamed("safe_packed_borrows", "unaligned_references");
store.register_renamed("disjoint_capture_migration", "rust_2021_incompatible_closure_captures");
store.register_renamed("or_patterns_back_compat", "rust_2021_incompatible_or_patterns");
store.register_renamed("non_fmt_panic", "non_fmt_panics");

// These were moved to tool lints, but rustc still sees them when compiling normally, before
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_lint/src/non_fmt_panic.rs
Expand Up @@ -9,7 +9,7 @@ use rustc_span::edition::Edition;
use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol};

declare_lint! {
/// The `non_fmt_panic` lint detects `panic!(..)` invocations where the first
/// The `non_fmt_panics` lint detects `panic!(..)` invocations where the first
/// argument is not a formatting string.
///
/// ### Example
Expand All @@ -29,7 +29,7 @@ declare_lint! {
/// an `i32` as message.
///
/// Rust 2021 always interprets the first argument as format string.
NON_FMT_PANIC,
NON_FMT_PANICS,
Warn,
"detect single-argument panic!() invocations in which the argument is not a format string",
@future_incompatible = FutureIncompatibleInfo {
Expand All @@ -39,7 +39,7 @@ declare_lint! {
report_in_external_macro
}

declare_lint_pass!(NonPanicFmt => [NON_FMT_PANIC]);
declare_lint_pass!(NonPanicFmt => [NON_FMT_PANICS]);

impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
Expand Down Expand Up @@ -91,7 +91,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
arg_span = expn.call_site;
}

cx.struct_span_lint(NON_FMT_PANIC, arg_span, |lint| {
cx.struct_span_lint(NON_FMT_PANICS, arg_span, |lint| {
let mut l = lint.build("panic message is not a string literal");
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>");
Expand Down Expand Up @@ -174,7 +174,7 @@ fn check_panic_str<'tcx>(
[] => vec![fmt_span],
v => v.iter().map(|span| fmt_span.from_inner(*span)).collect(),
};
cx.struct_span_lint(NON_FMT_PANIC, arg_spans, |lint| {
cx.struct_span_lint(NON_FMT_PANICS, 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 @@ -208,7 +208,7 @@ fn check_panic_str<'tcx>(
Some(v) if v.len() == 1 => "panic message contains a brace",
_ => "panic message contains braces",
};
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or_else(|| vec![span]), |lint| {
cx.struct_span_lint(NON_FMT_PANICS, brace_spans.unwrap_or_else(|| vec![span]), |lint| {
let mut l = lint.build(msg);
l.note("this message is not used as a format string, but will be in Rust 2021");
if span.contains(arg.span) {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/lib.rs
Expand Up @@ -164,8 +164,8 @@
#![feature(no_niche)] // rust-lang/rust#68303
#![feature(no_coverage)] // rust-lang/rust#84605
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(renamed_and_removed_lints)]
#![deny(or_patterns_back_compat)]
#![cfg_attr(bootstrap, deny(or_patterns_back_compat))]
#![cfg_attr(not(bootstrap), deny(rust_2021_incompatible_or_patterns))]

// allow using `core::` in intra-doc links
#[allow(unused_extern_crates)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/const_panic.rs
@@ -1,5 +1,5 @@
#![feature(const_panic)]
#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]
#![crate_type = "lib"]

const MSG: &str = "hello";
Expand Down
16 changes: 9 additions & 7 deletions src/test/ui/fmt/format-args-capture.rs
Expand Up @@ -16,13 +16,13 @@ fn main() {

fn named_argument_takes_precedence_to_captured() {
let foo = "captured";
let s = format!("{foo}", foo="named");
let s = format!("{foo}", foo = "named");
assert_eq!(&s, "named");

let s = format!("{foo}-{foo}-{foo}", foo="named");
let s = format!("{foo}-{foo}-{foo}", foo = "named");
assert_eq!(&s, "named-named-named");

let s = format!("{}-{bar}-{foo}", "positional", bar="named");
let s = format!("{}-{bar}-{foo}", "positional", bar = "named");
assert_eq!(&s, "positional-named-captured");
}

Expand All @@ -42,10 +42,11 @@ 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(non_fmt_panic)]
#[allow(non_fmt_panics)]
let msg = std::panic::catch_unwind(|| {
panic!("{foo}");
}).unwrap_err();
})
.unwrap_err();

assert_eq!(msg.downcast_ref::<&str>(), Some(&"{foo}"))
}
Expand All @@ -55,8 +56,9 @@ fn panic_with_multiple_arguments_is_formatted() {
let foo = "captured";

let msg = std::panic::catch_unwind(|| {
panic!("{}-{bar}-{foo}", "positional", bar="named");
}).unwrap_err();
panic!("{}-{bar}-{foo}", "positional", bar = "named");
})
.unwrap_err();

assert_eq!(msg.downcast_ref::<String>(), Some(&"positional-named-captured".to_string()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/assert-macro-owned.rs
Expand Up @@ -2,7 +2,7 @@
// error-pattern:panicked at 'test-assert-owned'
// ignore-emscripten no processes

#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

fn main() {
assert!(false, "test-assert-owned".to_string());
Expand Down
17 changes: 11 additions & 6 deletions src/test/ui/macros/macro-comma-behavior-rpass.rs
Expand Up @@ -14,11 +14,12 @@
// revisions: std core

// ignore-wasm32-bare compiled with panic=abort by default

#![cfg_attr(core, no_std)]

#[cfg(std)] use std::fmt;
#[cfg(core)] use core::fmt;
#[cfg(core)]
use core::fmt;
#[cfg(std)]
use std::fmt;

// an easy mistake in the implementation of 'assert!'
// would cause this to say "explicit panic"
Expand Down Expand Up @@ -57,7 +58,7 @@ fn writeln_1arg() {
//
// (Example: Issue #48042)
#[test]
#[allow(non_fmt_panic)]
#[allow(non_fmt_panics)]
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 All @@ -80,13 +81,17 @@ fn to_format_or_not_to_format() {
// format!("{}",); // see check-fail
// format_args!("{}",); // see check-fail

if falsum() { panic!("{}",); }
if falsum() {
panic!("{}",);
}

// print!("{}",); // see check-fail
// println!("{}",); // see check-fail
// unimplemented!("{}",); // see check-fail

if falsum() { unreachable!("{}",); }
if falsum() {
unreachable!("{}",);
}

// write!(&mut stdout, "{}",); // see check-fail
// writeln!(&mut stdout, "{}",); // see check-fail
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/non-fmt-panic.stderr
Expand Up @@ -4,7 +4,7 @@ warning: panic message contains a brace
LL | panic!("here's a brace: {");
| ^
|
= note: `#[warn(non_fmt_panic)]` on by default
= note: `#[warn(non_fmt_panics)]` on by default
= note: this message is not used as a format string, but will be in Rust 2021
help: add a "{}" format string to use the message literally
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panics/explicit-panic-msg.rs
@@ -1,6 +1,6 @@
#![allow(unused_assignments)]
#![allow(unused_variables)]
#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

// run-fail
// error-pattern:wooooo
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panics/panic-macro-any-wrapped.rs
Expand Up @@ -2,7 +2,7 @@
// error-pattern:panicked at 'Box<dyn Any>'
// ignore-emscripten no processes

#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

fn main() {
panic!(Box::new(612_i64));
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/panics/panic-macro-any.rs
Expand Up @@ -3,7 +3,7 @@
// ignore-emscripten no processes

#![feature(box_syntax)]
#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

fn main() {
panic!(box 413 as Box<dyn std::any::Any + Send>);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/CHANGELOG.md
Expand Up @@ -592,7 +592,7 @@ Released 2021-02-11

* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated
as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333)
* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panic`
* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panics`
[#6351](https://github.com/rust-lang/rust-clippy/pull/6351)
* Move [`map_err_ignore`] to `restriction`
[#6416](https://github.com/rust-lang/rust-clippy/pull/6416)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/lib.rs
Expand Up @@ -2171,7 +2171,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
ls.register_renamed("clippy::unused_label", "unused_labels");
ls.register_renamed("clippy::drop_bounds", "drop_bounds");
ls.register_renamed("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr");
ls.register_renamed("clippy::panic_params", "non_fmt_panic");
ls.register_renamed("clippy::panic_params", "non_fmt_panics");
ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints");
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/assertions_on_constants.rs
@@ -1,4 +1,4 @@
#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

macro_rules! assert_const {
($len:expr) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/tests/ui/deprecated.stderr
Expand Up @@ -60,11 +60,11 @@ error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cs
LL | #[warn(clippy::temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`

error: lint `clippy::panic_params` has been renamed to `non_fmt_panic`
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
--> $DIR/deprecated.rs:11:8
|
LL | #[warn(clippy::panic_params)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panic`
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`

error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
--> $DIR/deprecated.rs:12:8
Expand Down

0 comments on commit a902e25

Please sign in to comment.