fix reviewer comments
This commit is contained in:
parent
fb6bf1ebf6
commit
342ce3da05
@ -183,12 +183,9 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option<bool> {
|
||||
|
||||
fn is_some(path_kind: PatKind<'_>) -> bool {
|
||||
match path_kind {
|
||||
PatKind::TupleStruct(QPath::Resolved(_, path), patterns, _) if is_wild(&patterns[0]) => {
|
||||
PatKind::TupleStruct(QPath::Resolved(_, path), [first, ..], _) if is_wild(first) => {
|
||||
let name = path.segments[0].ident;
|
||||
if name.name == rustc_span::sym::Some {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
name.name == rustc_span::sym::Some
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
|
@ -188,9 +188,8 @@ fn find_sugg_for_if_let<'tcx>(
|
||||
pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
if arms.len() == 2 {
|
||||
let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind);
|
||||
let found_good_method = found_good_method(cx, arms, node_pair);
|
||||
|
||||
if let Some(good_method) = found_good_method {
|
||||
if let Some(good_method) = found_good_method(cx, arms, node_pair) {
|
||||
let span = expr.span.to(op.span);
|
||||
let result_expr = match &op.kind {
|
||||
ExprKind::AddrOf(_, _, borrowed) => borrowed,
|
||||
@ -310,6 +309,9 @@ fn get_good_method<'a>(cx: &LateContext<'_>, arms: &[Arm<'_>], path_left: &QPath
|
||||
"Ok" => {
|
||||
find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultOk), "is_ok()", "is_err()")
|
||||
},
|
||||
"Err" => {
|
||||
find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultErr), "is_err()", "is_ok()")
|
||||
},
|
||||
"Some" => find_good_method_for_matches_macro(
|
||||
cx,
|
||||
arms,
|
||||
|
@ -95,15 +95,12 @@ fn issue10726() {
|
||||
|
||||
Some(42).is_none();
|
||||
|
||||
Some(42).is_none();
|
||||
|
||||
Some(42).is_some();
|
||||
|
||||
None::<()>.is_none();
|
||||
|
||||
None::<()>.is_none();
|
||||
|
||||
None::<()>.is_none();
|
||||
|
||||
None::<()>.is_some();
|
||||
|
||||
None::<()>.is_none();
|
||||
|
||||
match Some(42) {
|
||||
Some(21) => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
@ -111,29 +111,14 @@ fn issue10726() {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match Some(42) {
|
||||
Some(_) => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
match Some(42) {
|
||||
None => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match Some(42) {
|
||||
None => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
match None::<()> {
|
||||
Some(_) => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
match None::<()> {
|
||||
Some(_) => false,
|
||||
_ => true,
|
||||
Some(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match None::<()> {
|
||||
@ -141,8 +126,8 @@ fn issue10726() {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match None::<()> {
|
||||
None => false,
|
||||
_ => true,
|
||||
match Some(42) {
|
||||
Some(21) => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
@ -161,64 +161,28 @@ error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:114:5
|
||||
|
|
||||
LL | / match Some(42) {
|
||||
LL | | Some(_) => false,
|
||||
LL | | _ => true,
|
||||
LL | | None => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Some(42).is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:119:5
|
||||
|
|
||||
LL | / match Some(42) {
|
||||
LL | | None => true,
|
||||
LL | / match None::<()> {
|
||||
LL | | Some(_) => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Some(42).is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:124:5
|
||||
|
|
||||
LL | / match Some(42) {
|
||||
LL | | None => false,
|
||||
LL | | _ => true,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:129:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | Some(_) => false,
|
||||
LL | | _ => true,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:134:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | Some(_) => false,
|
||||
LL | | _ => true,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:139:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | None => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:144:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | None => false,
|
||||
LL | | _ => true,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `None::<()>.is_some()`
|
||||
|
||||
error: aborting due to 30 previous errors
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:124:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | None => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `None::<()>.is_none()`
|
||||
|
||||
error: aborting due to 26 previous errors
|
||||
|
||||
|
@ -114,7 +114,12 @@ fn issue10726() {
|
||||
|
||||
Ok::<i32, i32>(42).is_err();
|
||||
|
||||
Err::<i32, i32>(42).is_ok();
|
||||
|
||||
Err::<i32, i32>(42).is_err();
|
||||
|
||||
Err::<i32, i32>(42).is_ok();
|
||||
match Ok::<i32, i32>(42) {
|
||||
Ok(21) => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
@ -134,17 +134,22 @@ fn issue10726() {
|
||||
};
|
||||
|
||||
match Ok::<i32, i32>(42) {
|
||||
Ok(_) => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
match Err::<i32, i32>(42) {
|
||||
Ok(_) => false,
|
||||
_ => true,
|
||||
Err(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match Err::<i32, i32>(42) {
|
||||
Ok(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match Err::<i32, i32>(42) {
|
||||
Err(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match Ok::<i32, i32>(42) {
|
||||
Ok(21) => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
@ -163,22 +163,13 @@ error: redundant pattern matching, consider using `is_err()`
|
||||
--> $DIR/redundant_pattern_matching_result.rs:136:5
|
||||
|
|
||||
LL | / match Ok::<i32, i32>(42) {
|
||||
LL | | Ok(_) => false,
|
||||
LL | | _ => true,
|
||||
LL | | Err(_) => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_err()`
|
||||
--> $DIR/redundant_pattern_matching_result.rs:141:5
|
||||
|
|
||||
LL | / match Err::<i32, i32>(42) {
|
||||
LL | | Ok(_) => false,
|
||||
LL | | _ => true,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_ok()`
|
||||
--> $DIR/redundant_pattern_matching_result.rs:146:5
|
||||
--> $DIR/redundant_pattern_matching_result.rs:141:5
|
||||
|
|
||||
LL | / match Err::<i32, i32>(42) {
|
||||
LL | | Ok(_) => true,
|
||||
@ -186,5 +177,14 @@ LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_err()`
|
||||
--> $DIR/redundant_pattern_matching_result.rs:146:5
|
||||
|
|
||||
LL | / match Err::<i32, i32>(42) {
|
||||
LL | | Err(_) => true,
|
||||
LL | | _ => false,
|
||||
LL | | };
|
||||
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
|
||||
|
||||
error: aborting due to 26 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user