@@ -1487,7 +1487,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1487
1487
[ "expect" , ..] => lint_expect ( cx, expr, arg_lists[ 0 ] ) ,
1488
1488
[ "unwrap_or" , "map" ] => option_map_unwrap_or:: lint ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] ) ,
1489
1489
[ "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 ( ) ) {
1491
1491
unnecessary_lazy_eval:: lint ( cx, expr, arg_lists[ 0 ] , "unwrap_or" ) ;
1492
1492
}
1493
1493
} ,
@@ -1509,7 +1509,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1509
1509
[ "next" , "iter" ] => lint_iter_next ( cx, expr, arg_lists[ 1 ] ) ,
1510
1510
[ "map" , "filter" ] => lint_filter_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1511
1511
[ "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 ( ) ) ,
1513
1513
[ "map" , "find" ] => lint_find_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1514
1514
[ "flat_map" , "filter" ] => lint_filter_flat_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1515
1515
[ "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
2733
2733
}
2734
2734
}
2735
2735
2736
+ const MAP_UNWRAP_OR_MSRV : RustcVersion = RustcVersion :: new ( 1 , 41 , 0 ) ;
2737
+
2736
2738
/// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s
2737
2739
/// Return true if lint triggered
2738
2740
fn lint_map_unwrap_or_else < ' tcx > (
2739
2741
cx : & LateContext < ' tcx > ,
2740
2742
expr : & ' tcx hir:: Expr < ' _ > ,
2741
2743
map_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2742
2744
unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2745
+ msrv : Option < & RustcVersion > ,
2743
2746
) -> bool {
2747
+ if !meets_msrv ( msrv, & MAP_UNWRAP_OR_MSRV ) {
2748
+ return false ;
2749
+ }
2744
2750
// lint if the caller of `map()` is an `Option`
2745
2751
let is_option = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_args[ 0 ] ) , sym:: option_type) ;
2746
2752
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>(
2923
2929
}
2924
2930
}
2925
2931
2932
+ const FILTER_MAP_NEXT_MSRV : RustcVersion = RustcVersion :: new ( 1 , 30 , 0 ) ;
2933
+
2926
2934
/// 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
+ ) {
2928
2941
if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2942
+ if !meets_msrv ( msrv, & FILTER_MAP_NEXT_MSRV ) {
2943
+ return ;
2944
+ }
2945
+
2929
2946
let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
2930
2947
`.find_map(..)` instead.";
2931
2948
let filter_snippet = snippet ( cx, filter_args[ 1 ] . span , ".." ) ;
0 commit comments