@@ -30,6 +30,7 @@ mod map_collect_result_unit;
3030mod map_flatten;
3131mod ok_expect;
3232mod option_as_ref_deref;
33+ mod option_map_or_none;
3334mod option_map_unwrap_or;
3435mod search_is_some;
3536mod single_char_insert_string;
@@ -1692,7 +1693,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16921693 unnecessary_lazy_eval:: check ( cx, expr, arg_lists[ 0 ] , "unwrap_or" ) ;
16931694 }
16941695 } ,
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 ] ) ,
16961697 [ "and_then" , ..] => {
16971698 let biom_option_linted = bind_instead_of_map:: OptionAndThenSome :: check ( cx, expr, arg_lists[ 0 ] ) ;
16981699 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>(
24312432 false
24322433}
24332434
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-
25042435/// Used for `lint_binary_expr_with_method_call`.
25052436#[ derive( Copy , Clone ) ]
25062437struct BinaryExprInfo < ' a > {
0 commit comments