@@ -1487,7 +1487,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
14871487 [ "expect" , ..] => lint_expect ( cx, expr, arg_lists[ 0 ] ) ,
14881488 [ "unwrap_or" , "map" ] => option_map_unwrap_or:: lint ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] ) ,
14891489 [ "unwrap_or_else" , "map" ] => {
1490- if !lint_map_unwrap_or_else ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) {
1490+ if !lint_map_unwrap_or_else ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] , self . msrv . as_ref ( ) ) {
14911491 unnecessary_lazy_eval:: lint ( cx, expr, arg_lists[ 0 ] , "unwrap_or" ) ;
14921492 }
14931493 } ,
@@ -1509,7 +1509,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
15091509 [ "next" , "iter" ] => lint_iter_next ( cx, expr, arg_lists[ 1 ] ) ,
15101510 [ "map" , "filter" ] => lint_filter_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
15111511 [ "map" , "filter_map" ] => lint_filter_map_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1512- [ "next" , "filter_map" ] => lint_filter_map_next ( cx, expr, arg_lists[ 1 ] ) ,
1512+ [ "next" , "filter_map" ] => lint_filter_map_next ( cx, expr, arg_lists[ 1 ] , self . msrv . as_ref ( ) ) ,
15131513 [ "map" , "find" ] => lint_find_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
15141514 [ "flat_map" , "filter" ] => lint_filter_flat_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
15151515 [ "flat_map" , "filter_map" ] => lint_filter_map_flat_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
@@ -2733,14 +2733,20 @@ fn lint_map_flatten<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
27332733 }
27342734}
27352735
2736+ const MAP_UNWRAP_OR_MSRV : RustcVersion = RustcVersion :: new ( 1 , 41 , 0 ) ;
2737+
27362738/// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s
27372739/// Return true if lint triggered
27382740fn lint_map_unwrap_or_else < ' tcx > (
27392741 cx : & LateContext < ' tcx > ,
27402742 expr : & ' tcx hir:: Expr < ' _ > ,
27412743 map_args : & ' tcx [ hir:: Expr < ' _ > ] ,
27422744 unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2745+ msrv : Option < & RustcVersion > ,
27432746) -> bool {
2747+ if !meets_msrv ( msrv, & MAP_UNWRAP_OR_MSRV ) {
2748+ return false ;
2749+ }
27442750 // lint if the caller of `map()` is an `Option`
27452751 let is_option = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_args[ 0 ] ) , sym:: option_type) ;
27462752 let is_result = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_args[ 0 ] ) , sym:: result_type) ;
@@ -2923,9 +2929,20 @@ fn lint_filter_map<'tcx>(
29232929 }
29242930}
29252931
2932+ const FILTER_MAP_NEXT_MSRV : RustcVersion = RustcVersion :: new ( 1 , 30 , 0 ) ;
2933+
29262934/// lint use of `filter_map().next()` for `Iterators`
2927- fn lint_filter_map_next < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > , filter_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
2935+ fn lint_filter_map_next < ' tcx > (
2936+ cx : & LateContext < ' tcx > ,
2937+ expr : & ' tcx hir:: Expr < ' _ > ,
2938+ filter_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2939+ msrv : Option < & RustcVersion > ,
2940+ ) {
29282941 if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2942+ if !meets_msrv ( msrv, & FILTER_MAP_NEXT_MSRV ) {
2943+ return ;
2944+ }
2945+
29292946 let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
29302947 `.find_map(..)` instead.";
29312948 let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
0 commit comments