@@ -31,7 +31,7 @@ fn get_some(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option<HirId> {
3131 }
3232}
3333
34- fn get_none < ' tcx > ( cx : & LateContext < ' _ > , arm : & Arm < ' tcx > ) -> Option < & ' tcx Expr < ' tcx > > {
34+ fn get_none < ' tcx > ( cx : & LateContext < ' _ > , arm : & Arm < ' tcx > , allow_wildcard : bool ) -> Option < & ' tcx Expr < ' tcx > > {
3535 if let PatKind :: Expr ( PatExpr { kind : PatExprKind :: Path ( QPath :: Resolved ( _, path) ) , .. } ) = arm. pat . kind
3636 && let Some ( def_id) = path. res . opt_def_id ( )
3737 // Since it comes from a pattern binding, we need to get the parent to actually match
@@ -48,7 +48,9 @@ fn get_none<'tcx>(cx: &LateContext<'_>, arm: &Arm<'tcx>) -> Option<&'tcx Expr<'t
4848 && cx. tcx . lang_items ( ) . get ( LangItem :: ResultErr ) == Some ( def_id)
4949 {
5050 Some ( arm. body )
51- } else if let PatKind :: Wild = arm. pat . kind {
51+ } else if let PatKind :: Wild = arm. pat . kind
52+ && allow_wildcard
53+ {
5254 // We consider that the `Some` check will filter it out if it's not right.
5355 Some ( arm. body )
5456 } else {
@@ -62,11 +64,11 @@ fn get_some_and_none_bodies<'tcx>(
6264 arm2 : & ' tcx Arm < ' tcx > ,
6365) -> Option < ( ( & ' tcx Expr < ' tcx > , HirId ) , & ' tcx Expr < ' tcx > ) > {
6466 if let Some ( binding_id) = get_some ( cx, arm1. pat )
65- && let Some ( body_none) = get_none ( cx, arm2)
67+ && let Some ( body_none) = get_none ( cx, arm2, true )
6668 {
6769 Some ( ( ( arm1. body , binding_id) , body_none) )
68- } else if let Some ( binding_id ) = get_some ( cx, arm2 . pat )
69- && let Some ( body_none ) = get_none ( cx, arm1 )
70+ } else if let Some ( body_none ) = get_none ( cx, arm1 , false )
71+ && let Some ( binding_id ) = get_some ( cx, arm2 . pat )
7072 {
7173 Some ( ( ( arm2. body , binding_id) , body_none) )
7274 } else {
0 commit comments