then {
let reindented_or_body =
utils::reindent_multiline(or_body_snippet.into(), true, Some(indent));
- let wrap_in_parens = !matches!(scrutinee, Expr { kind: ExprKind::Call(..), .. });
+ let wrap_in_parens = !matches!(scrutinee, Expr {
+ kind: ExprKind::Call(..) | ExprKind::Path(_), ..
+ });
let l_paren = if wrap_in_parens { "(" } else { "" };
let r_paren = if wrap_in_parens { ")" } else { "" };
utils::span_lint_and_sugg(
// int case
Ok::<i32, &str>(1).unwrap_or(42);
+ // int case, scrutinee is a binding
+ let a = Ok::<i32, &str>(1);
+ a.unwrap_or(42);
+
// int case, suggestion must surround with parenthesis
(Ok(1) as Result<i32, &str>).unwrap_or(42);
| |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:92:5
+ --> $DIR/manual_unwrap_or.rs:93:5
+ |
+LL | / match a {
+LL | | Ok(i) => i,
+LL | | Err(_) => 42,
+LL | | };
+ | |_____^ help: replace with: `a.unwrap_or(42)`
+
+error: this pattern reimplements `Result::unwrap_or`
+ --> $DIR/manual_unwrap_or.rs:99:5
|
LL | / match Ok(1) as Result<i32, &str> {
LL | | Ok(i) => i,
| |_____^ help: replace with: `(Ok(1) as Result<i32, &str>).unwrap_or(42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:98:5
+ --> $DIR/manual_unwrap_or.rs:105:5
|
LL | / match Ok::<i32, &str>(1) {
LL | | Err(_) => 42,
| |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:104:5
+ --> $DIR/manual_unwrap_or.rs:111:5
|
LL | / match Ok::<i32, &str>(1) {
LL | | Ok(i) => i,
| |_____^ help: replace with: `Ok::<i32, &str>(1).unwrap_or(1 + 42)`
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:111:5
+ --> $DIR/manual_unwrap_or.rs:118:5
|
LL | / match Ok::<i32, &str>(1) {
LL | | Ok(i) => i,
|
error: this pattern reimplements `Result::unwrap_or`
- --> $DIR/manual_unwrap_or.rs:121:5
+ --> $DIR/manual_unwrap_or.rs:128:5
|
LL | / match Ok::<&str, &str>("Bob") {
LL | | Ok(i) => i,
LL | | };
| |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")`
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors