@@ -1376,6 +1376,7 @@ fn lint_or_fun_call<'a, 'tcx>(
1376
1376
1377
1377
let mut finder = FunCallFinder { cx: & cx, found: false } ;
1378
1378
if { finder. visit_expr( & arg) ; finder. found } ;
1379
+ if !contains_return( & arg) ;
1379
1380
1380
1381
let self_ty = cx. tables. expr_ty( self_expr) ;
1381
1382
@@ -2189,28 +2190,6 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &
2189
2190
const LINT_MSG : & str = "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`" ;
2190
2191
const NO_OP_MSG : & str = "using `Option.and_then(Some)`, which is a no-op" ;
2191
2192
2192
- // Searches an return expressions in `y` in `_.and_then(|x| Some(y))`, which we don't lint
2193
- struct RetCallFinder {
2194
- found : bool ,
2195
- }
2196
-
2197
- impl < ' tcx > intravisit:: Visitor < ' tcx > for RetCallFinder {
2198
- fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr ) {
2199
- if self . found {
2200
- return ;
2201
- }
2202
- if let hir:: ExprKind :: Ret ( ..) = & expr. node {
2203
- self . found = true ;
2204
- } else {
2205
- intravisit:: walk_expr ( self , expr) ;
2206
- }
2207
- }
2208
-
2209
- fn nested_visit_map < ' this > ( & ' this mut self ) -> intravisit:: NestedVisitorMap < ' this , ' tcx > {
2210
- intravisit:: NestedVisitorMap :: None
2211
- }
2212
- }
2213
-
2214
2193
let ty = cx. tables . expr_ty ( & args[ 0 ] ) ;
2215
2194
if !match_type ( cx, ty, & paths:: OPTION ) {
2216
2195
return ;
@@ -2228,9 +2207,7 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &
2228
2207
then {
2229
2208
let inner_expr = & some_args[ 0 ] ;
2230
2209
2231
- let mut finder = RetCallFinder { found: false } ;
2232
- finder. visit_expr( inner_expr) ;
2233
- if finder. found {
2210
+ if contains_return( inner_expr) {
2234
2211
return ;
2235
2212
}
2236
2213
@@ -2987,3 +2964,31 @@ fn is_bool(ty: &hir::Ty) -> bool {
2987
2964
false
2988
2965
}
2989
2966
}
2967
+
2968
+ // Returns `true` if `expr` contains a return expression
2969
+ fn contains_return ( expr : & hir:: Expr ) -> bool {
2970
+ struct RetCallFinder {
2971
+ found : bool ,
2972
+ }
2973
+
2974
+ impl < ' tcx > intravisit:: Visitor < ' tcx > for RetCallFinder {
2975
+ fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr ) {
2976
+ if self . found {
2977
+ return ;
2978
+ }
2979
+ if let hir:: ExprKind :: Ret ( ..) = & expr. node {
2980
+ self . found = true ;
2981
+ } else {
2982
+ intravisit:: walk_expr ( self , expr) ;
2983
+ }
2984
+ }
2985
+
2986
+ fn nested_visit_map < ' this > ( & ' this mut self ) -> intravisit:: NestedVisitorMap < ' this , ' tcx > {
2987
+ intravisit:: NestedVisitorMap :: None
2988
+ }
2989
+ }
2990
+
2991
+ let mut visitor = RetCallFinder { found : false } ;
2992
+ visitor. visit_expr ( expr) ;
2993
+ visitor. found
2994
+ }
0 commit comments