Make panic_fmt lint work properly for assert!(expr, msg) too.
This commit is contained in:
parent
da66a501f6
commit
f228efc3f5
@ -53,6 +53,18 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
||||
if cx.tcx.is_diagnostic_item(sym::std_panic_macro, id)
|
||||
|| cx.tcx.is_diagnostic_item(sym::core_panic_macro, id)
|
||||
{
|
||||
let expn = {
|
||||
// Unwrap another level of macro expansion if this
|
||||
// panic!() was expanded from assert!().
|
||||
let parent = expn.call_site.ctxt().outer_expn_data();
|
||||
if parent.macro_def_id.map_or(false, |id| {
|
||||
cx.tcx.is_diagnostic_item(sym::assert_macro, id)
|
||||
}) {
|
||||
parent
|
||||
} else {
|
||||
expn
|
||||
}
|
||||
};
|
||||
cx.struct_span_lint(PANIC_FMT, expn.call_site, |lint| {
|
||||
let mut l = lint.build("Panic message contains a brace");
|
||||
l.note("This message is not used as a format string, but will be in a future Rust version");
|
||||
|
@ -267,6 +267,7 @@ symbols! {
|
||||
asm,
|
||||
assert,
|
||||
assert_inhabited,
|
||||
assert_macro,
|
||||
assert_receiver_is_total_eq,
|
||||
assert_uninit_valid,
|
||||
assert_zero_valid,
|
||||
|
@ -1216,6 +1216,7 @@ pub(crate) mod builtin {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_builtin_macro]
|
||||
#[macro_export]
|
||||
#[rustc_diagnostic_item = "assert_macro"]
|
||||
macro_rules! assert {
|
||||
($cond:expr $(,)?) => {{ /* compiler built-in */ }};
|
||||
($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
|
||||
|
Loading…
Reference in New Issue
Block a user