@@ -30,6 +30,7 @@ mod map_collect_result_unit;
30
30
mod map_flatten;
31
31
mod ok_expect;
32
32
mod option_as_ref_deref;
33
+ mod option_map_or_none;
33
34
mod option_map_unwrap_or;
34
35
mod search_is_some;
35
36
mod single_char_insert_string;
@@ -1692,7 +1693,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1692
1693
unnecessary_lazy_eval:: check ( cx, expr, arg_lists[ 0 ] , "unwrap_or" ) ;
1693
1694
}
1694
1695
} ,
1695
- [ "map_or" , ..] => lint_map_or_none ( cx, expr, arg_lists[ 0 ] ) ,
1696
+ [ "map_or" , ..] => option_map_or_none :: check ( cx, expr, arg_lists[ 0 ] ) ,
1696
1697
[ "and_then" , ..] => {
1697
1698
let biom_option_linted = bind_instead_of_map:: OptionAndThenSome :: check ( cx, expr, arg_lists[ 0 ] ) ;
1698
1699
let biom_result_linted = bind_instead_of_map:: ResultAndThenOk :: check ( cx, expr, arg_lists[ 0 ] ) ;
@@ -2431,76 +2432,6 @@ fn lint_map_unwrap_or_else<'tcx>(
2431
2432
false
2432
2433
}
2433
2434
2434
- /// lint use of `_.map_or(None, _)` for `Option`s and `Result`s
2435
- fn lint_map_or_none < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > , map_or_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
2436
- let is_option = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_or_args[ 0 ] ) , sym:: option_type) ;
2437
- let is_result = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_or_args[ 0 ] ) , sym:: result_type) ;
2438
-
2439
- // There are two variants of this `map_or` lint:
2440
- // (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
2441
- // (2) using `map_or` as a combinator instead of `and_then`
2442
- //
2443
- // (For this lint) we don't care if any other type calls `map_or`
2444
- if !is_option && !is_result {
2445
- return ;
2446
- }
2447
-
2448
- let ( lint_name, msg, instead, hint) = {
2449
- let default_arg_is_none = if let hir:: ExprKind :: Path ( ref qpath) = map_or_args[ 1 ] . kind {
2450
- match_qpath ( qpath, & paths:: OPTION_NONE )
2451
- } else {
2452
- return ;
2453
- } ;
2454
-
2455
- if !default_arg_is_none {
2456
- // nothing to lint!
2457
- return ;
2458
- }
2459
-
2460
- let f_arg_is_some = if let hir:: ExprKind :: Path ( ref qpath) = map_or_args[ 2 ] . kind {
2461
- match_qpath ( qpath, & paths:: OPTION_SOME )
2462
- } else {
2463
- false
2464
- } ;
2465
-
2466
- if is_option {
2467
- let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2468
- let func_snippet = snippet ( cx, map_or_args[ 2 ] . span , ".." ) ;
2469
- let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
2470
- `and_then(..)` instead";
2471
- (
2472
- OPTION_MAP_OR_NONE ,
2473
- msg,
2474
- "try using `and_then` instead" ,
2475
- format ! ( "{0}.and_then({1})" , self_snippet, func_snippet) ,
2476
- )
2477
- } else if f_arg_is_some {
2478
- let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
2479
- `ok()` instead";
2480
- let self_snippet = snippet ( cx, map_or_args[ 0 ] . span , ".." ) ;
2481
- (
2482
- RESULT_MAP_OR_INTO_OPTION ,
2483
- msg,
2484
- "try using `ok` instead" ,
2485
- format ! ( "{0}.ok()" , self_snippet) ,
2486
- )
2487
- } else {
2488
- // nothing to lint!
2489
- return ;
2490
- }
2491
- } ;
2492
-
2493
- span_lint_and_sugg (
2494
- cx,
2495
- lint_name,
2496
- expr. span ,
2497
- msg,
2498
- instead,
2499
- hint,
2500
- Applicability :: MachineApplicable ,
2501
- ) ;
2502
- }
2503
-
2504
2435
/// Used for `lint_binary_expr_with_method_call`.
2505
2436
#[ derive( Copy , Clone ) ]
2506
2437
struct BinaryExprInfo < ' a > {
0 commit comments