Add s to non_fmt_panic
This commit is contained in:
parent
4e5b78fdcf
commit
a902e25f58
15 changed files with 40 additions and 32 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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>) {
|
||||
|
@ -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>");
|
||||
|
@ -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",
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![feature(const_panic)]
|
||||
#![allow(non_fmt_panic)]
|
||||
#![allow(non_fmt_panics)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
const MSG: &str = "hello";
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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}"))
|
||||
}
|
||||
|
@ -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()))
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(unused_assignments)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(non_fmt_panic)]
|
||||
#![allow(non_fmt_panics)]
|
||||
|
||||
// run-fail
|
||||
// error-pattern:wooooo
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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>);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(non_fmt_panic)]
|
||||
#![allow(non_fmt_panics)]
|
||||
|
||||
macro_rules! assert_const {
|
||||
($len:expr) => {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue