mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
non_fmt_panic: machine app. suggestion for assert with string msg.
This commit is contained in:
parent
04c9901a08
commit
b4f448a7ea
@ -120,13 +120,26 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let ty = cx.typeck_results().expr_ty(arg);
|
||||
// If this is a &str or String, we can confidently give the `"{}", ` suggestion.
|
||||
let is_str = matches!(
|
||||
ty.kind(),
|
||||
ty::Ref(_, r, _) if *r.kind() == ty::Str
|
||||
) || matches!(
|
||||
(ty.ty_adt_def(), cx.tcx.get_diagnostic_item(sym::string_type)),
|
||||
(Some(ty_def), Some(string_type)) if ty_def.did == string_type
|
||||
);
|
||||
l.span_suggestion_verbose(
|
||||
arg_span.shrink_to_lo(),
|
||||
"add a \"{}\" format string to Display the message",
|
||||
"\"{}\", ".into(),
|
||||
Applicability::MaybeIncorrect,
|
||||
if is_str {
|
||||
Applicability::MachineApplicable
|
||||
} else {
|
||||
Applicability::MaybeIncorrect
|
||||
},
|
||||
);
|
||||
if panic == sym::std_panic_macro {
|
||||
if !is_str && panic == sym::std_panic_macro {
|
||||
if let Some((open, close, del)) = find_delimiters(cx, span) {
|
||||
l.multipart_suggestion(
|
||||
"or use std::panic::panic_any instead",
|
||||
|
Loading…
Reference in New Issue
Block a user