@@ -2573,42 +2573,48 @@ fn lint_map_or_none<'a, 'tcx>(
2573
2573
false
2574
2574
} ;
2575
2575
2576
- let mess = if is_option && default_arg_is_none {
2577
- let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2578
- let func_snippet = snippet ( cx, map_or_args[ 2 ] . span , ".." ) ;
2579
- let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \
2580
- `and_then(f)` instead";
2581
- Some ( (
2582
- OPTION_MAP_OR_NONE ,
2583
- msg,
2584
- "try using `and_then` instead" ,
2585
- format ! ( "{0}.and_then({1})" , self_snippet, func_snippet) ,
2586
- ) )
2587
- } else if is_result && f_arg_is_some {
2588
- let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
2589
- `ok()` instead";
2590
- let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2591
- Some ( (
2592
- RESULT_MAP_OR_INTO_OPTION ,
2593
- msg,
2594
- "try using `ok` instead" ,
2595
- format ! ( "{0}.ok()" , self_snippet) ,
2596
- ) )
2597
- } else {
2598
- None
2576
+ let ( lint, msg, instead, hint) = {
2577
+ if !default_arg_is_none {
2578
+ // nothing to lint!
2579
+ return ;
2580
+ }
2581
+
2582
+ if is_option {
2583
+ let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2584
+ let func_snippet = snippet ( cx, map_or_args[ 2 ] . span , ".." ) ;
2585
+ let msg = "called `map_or(None, f)` on an `Option` value. This can be done more directly by calling \
2586
+ `and_then(f)` instead";
2587
+ (
2588
+ OPTION_MAP_OR_NONE ,
2589
+ msg,
2590
+ "try using `and_then` instead" ,
2591
+ format ! ( "{0}.and_then({1})" , self_snippet, func_snippet) ,
2592
+ )
2593
+ } else if f_arg_is_some {
2594
+ let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
2595
+ `ok()` instead";
2596
+ let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2597
+ (
2598
+ RESULT_MAP_OR_INTO_OPTION ,
2599
+ msg,
2600
+ "try using `ok` instead" ,
2601
+ format ! ( "{0}.ok()" , self_snippet) ,
2602
+ )
2603
+ } else {
2604
+ // nothing to lint!
2605
+ return ;
2606
+ }
2599
2607
} ;
2600
2608
2601
- if let Some ( ( lint, msg, instead, hint) ) = mess {
2602
- span_lint_and_sugg (
2603
- cx,
2604
- lint,
2605
- expr. span ,
2606
- msg,
2607
- instead,
2608
- hint,
2609
- Applicability :: MachineApplicable ,
2610
- ) ;
2611
- }
2609
+ span_lint_and_sugg (
2610
+ cx,
2611
+ lint,
2612
+ expr. span ,
2613
+ msg,
2614
+ instead,
2615
+ hint,
2616
+ Applicability :: MachineApplicable ,
2617
+ ) ;
2612
2618
}
2613
2619
2614
2620
/// Lint use of `_.and_then(|x| Some(y))` for `Option`s
0 commit comments