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