@@ -15,22 +15,23 @@ const MAP_UNWRAP_OR_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
1515pub ( super ) fn check < ' tcx > (
1616 cx : & LateContext < ' tcx > ,
1717 expr : & ' tcx hir:: Expr < ' _ > ,
18- map_args : & ' tcx [ hir:: Expr < ' _ > ] ,
19- unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
18+ recv : & ' tcx hir:: Expr < ' _ > ,
19+ map_arg : & ' tcx hir:: Expr < ' _ > ,
20+ unwrap_arg : & ' tcx hir:: Expr < ' _ > ,
2021 msrv : Option < & RustcVersion > ,
2122) -> bool {
2223 if !meets_msrv ( msrv, & MAP_UNWRAP_OR_MSRV ) {
2324 return false ;
2425 }
2526 // lint if the caller of `map()` is an `Option`
26- let is_option = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_args [ 0 ] ) , sym:: option_type) ;
27- let is_result = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( & map_args [ 0 ] ) , sym:: result_type) ;
27+ let is_option = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( recv ) , sym:: option_type) ;
28+ let is_result = is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty ( recv ) , sym:: result_type) ;
2829
2930 if is_option || is_result {
3031 // Don't make a suggestion that may fail to compile due to mutably borrowing
3132 // the same variable twice.
32- let map_mutated_vars = mutated_variables ( & map_args [ 0 ] , cx) ;
33- let unwrap_mutated_vars = mutated_variables ( & unwrap_args [ 1 ] , cx) ;
33+ let map_mutated_vars = mutated_variables ( recv , cx) ;
34+ let unwrap_mutated_vars = mutated_variables ( unwrap_arg , cx) ;
3435 if let ( Some ( map_mutated_vars) , Some ( unwrap_mutated_vars) ) = ( map_mutated_vars, unwrap_mutated_vars) {
3536 if map_mutated_vars. intersection ( & unwrap_mutated_vars) . next ( ) . is_some ( ) {
3637 return false ;
@@ -48,14 +49,14 @@ pub(super) fn check<'tcx>(
4849 `.map_or_else(<g>, <f>)` instead"
4950 } ;
5051 // get snippets for args to map() and unwrap_or_else()
51- let map_snippet = snippet ( cx, map_args [ 1 ] . span , ".." ) ;
52- let unwrap_snippet = snippet ( cx, unwrap_args [ 1 ] . span , ".." ) ;
52+ let map_snippet = snippet ( cx, map_arg . span , ".." ) ;
53+ let unwrap_snippet = snippet ( cx, unwrap_arg . span , ".." ) ;
5354 // lint, with note if neither arg is > 1 line and both map() and
5455 // unwrap_or_else() have the same span
5556 let multiline = map_snippet. lines ( ) . count ( ) > 1 || unwrap_snippet. lines ( ) . count ( ) > 1 ;
56- let same_span = map_args [ 1 ] . span . ctxt ( ) == unwrap_args [ 1 ] . span . ctxt ( ) ;
57+ let same_span = map_arg . span . ctxt ( ) == unwrap_arg . span . ctxt ( ) ;
5758 if same_span && !multiline {
58- let var_snippet = snippet ( cx, map_args [ 0 ] . span , ".." ) ;
59+ let var_snippet = snippet ( cx, recv . span , ".." ) ;
5960 span_lint_and_sugg (
6061 cx,
6162 MAP_UNWRAP_OR ,
0 commit comments