@@ -15,22 +15,23 @@ const MAP_UNWRAP_OR_MSRV: RustcVersion = RustcVersion::new(1, 41, 0);
15
15
pub ( super ) fn check < ' tcx > (
16
16
cx : & LateContext < ' tcx > ,
17
17
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 < ' _ > ,
20
21
msrv : Option < & RustcVersion > ,
21
22
) -> bool {
22
23
if !meets_msrv ( msrv, & MAP_UNWRAP_OR_MSRV ) {
23
24
return false ;
24
25
}
25
26
// 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) ;
28
29
29
30
if is_option || is_result {
30
31
// Don't make a suggestion that may fail to compile due to mutably borrowing
31
32
// 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) ;
34
35
if let ( Some ( map_mutated_vars) , Some ( unwrap_mutated_vars) ) = ( map_mutated_vars, unwrap_mutated_vars) {
35
36
if map_mutated_vars. intersection ( & unwrap_mutated_vars) . next ( ) . is_some ( ) {
36
37
return false ;
@@ -48,14 +49,14 @@ pub(super) fn check<'tcx>(
48
49
`.map_or_else(<g>, <f>)` instead"
49
50
} ;
50
51
// 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 , ".." ) ;
53
54
// lint, with note if neither arg is > 1 line and both map() and
54
55
// unwrap_or_else() have the same span
55
56
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 ( ) ;
57
58
if same_span && !multiline {
58
- let var_snippet = snippet ( cx, map_args [ 0 ] . span , ".." ) ;
59
+ let var_snippet = snippet ( cx, recv . span , ".." ) ;
59
60
span_lint_and_sugg (
60
61
cx,
61
62
MAP_UNWRAP_OR ,
0 commit comments