Skip to content

Commit d2d62de

Browse files
committed
Rustup to #64856
1 parent d43c424 commit d2d62de

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,30 +1610,35 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
16101610
let mut applicability = Applicability::MachineApplicable;
16111611

16121612
//Special handling for `format!` as arg_root
1613-
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind {
1614-
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1 {
1615-
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind {
1616-
let fmt_spec = &format_args[0];
1617-
let fmt_args = &format_args[1];
1613+
if_chain! {
1614+
if let hir::ExprKind::Block(block, None) = &arg_root.kind;
1615+
if block.stmts.len() == 1;
1616+
if let hir::StmtKind::Local(local) = &block.stmts[0].kind;
1617+
if let Some(arg_root) = &local.init;
1618+
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind;
1619+
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1;
1620+
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind;
1621+
then {
1622+
let fmt_spec = &format_args[0];
1623+
let fmt_args = &format_args[1];
16181624

1619-
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
1625+
let mut args = vec![snippet(cx, fmt_spec.span, "..").into_owned()];
16201626

1621-
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
1627+
args.extend(generate_format_arg_snippet(cx, fmt_args, &mut applicability));
16221628

1623-
let sugg = args.join(", ");
1629+
let sugg = args.join(", ");
16241630

1625-
span_lint_and_sugg(
1626-
cx,
1627-
EXPECT_FUN_CALL,
1628-
span_replace_word,
1629-
&format!("use of `{}` followed by a function call", name),
1630-
"try this",
1631-
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
1632-
applicability,
1633-
);
1631+
span_lint_and_sugg(
1632+
cx,
1633+
EXPECT_FUN_CALL,
1634+
span_replace_word,
1635+
&format!("use of `{}` followed by a function call", name),
1636+
"try this",
1637+
format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
1638+
applicability,
1639+
);
16341640

1635-
return;
1636-
}
1641+
return;
16371642
}
16381643
}
16391644

tests/ui/or_fun_call.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn or_fun_call() {
7171

7272
let opt = Some(1);
7373
let hello = "Hello";
74-
let _ = opt.ok_or_else(|| format!("{} world.", hello));
74+
let _ = opt.ok_or(format!("{} world.", hello));
7575
}
7676

7777
struct Foo(u8);

tests/ui/or_fun_call.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,11 @@ error: use of `unwrap_or` followed by a function call
7272
LL | let _ = stringy.unwrap_or("".to_owned());
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
7474

75-
error: use of `ok_or` followed by a function call
76-
--> $DIR/or_fun_call.rs:74:17
77-
|
78-
LL | let _ = opt.ok_or(format!("{} world.", hello));
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `ok_or_else(|| format!("{} world.", hello))`
80-
8175
error: use of `or` followed by a function call
8276
--> $DIR/or_fun_call.rs:95:35
8377
|
8478
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
8579
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
8680

87-
error: aborting due to 14 previous errors
81+
error: aborting due to 13 previous errors
8882

0 commit comments

Comments
 (0)