Rustup to rust-lang/rust#64856
This commit is contained in:
parent
d43c424145
commit
d2d62de841
3 changed files with 26 additions and 27 deletions
|
|
@ -1610,30 +1610,35 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
let mut applicability = Applicability::MachineApplicable;
|
||||
|
||||
//Special handling for `format!` as arg_root
|
||||
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind {
|
||||
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1 {
|
||||
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind {
|
||||
let fmt_spec = &format_args[0];
|
||||
let fmt_args = &format_args[1];
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Block(block, None) = &arg_root.kind;
|
||||
if block.stmts.len() == 1;
|
||||
if let hir::StmtKind::Local(local) = &block.stmts[0].kind;
|
||||
if let Some(arg_root) = &local.init;
|
||||
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind;
|
||||
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1;
|
||||
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind;
|
||||
then {
|
||||
let fmt_spec = &format_args[0];
|
||||
let fmt_args = &format_args[1];
|
||||
|
||||
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
|
||||
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
|
||||
|
||||
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
|
||||
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
|
||||
|
||||
let sugg = args.join(", ");
|
||||
let sugg = args.join(", ");
|
||||
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
EXPECT_FUN_CALL,
|
||||
span_replace_word,
|
||||
&format!("use of `{}` followed by a function call", name),
|
||||
"try this",
|
||||
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
|
||||
applicability,
|
||||
);
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
EXPECT_FUN_CALL,
|
||||
span_replace_word,
|
||||
&format!("use of `{}` followed by a function call", name),
|
||||
"try this",
|
||||
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
|
||||
applicability,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue