@@ -40,31 +40,24 @@ pub(super) fn check<'tcx>(
40
40
} ;
41
41
42
42
let closure_arg = fn_decl. inputs [ 0 ] ;
43
- let closure_body = cx. tcx . hir ( ) . body ( body) ;
44
- let closure_expr = peel_blocks ( closure_body. value ) ;
43
+ let closure_expr = peel_blocks ( cx. tcx . hir ( ) . body ( body) . value ) ;
45
44
46
- let msg = "use the question mark operator instead of an `and_then` call" ;
47
45
let mut applicability = Applicability :: MachineApplicable ;
46
+ let arg_snip = snippet_with_applicability ( cx, closure_arg. span , "_" , & mut applicability) ;
47
+ let recv_snip = snippet_with_applicability ( cx, recv. span , ".." , & mut applicability) ;
48
48
let body_snip = snippet_with_applicability ( cx, closure_expr. span , ".." , & mut applicability) ;
49
49
let inner = match body_snip. strip_prefix ( '{' ) . and_then ( |s| s. strip_suffix ( '}' ) ) {
50
50
Some ( s) => s. trim_start_matches ( '\n' ) . trim_end ( ) ,
51
51
None => & body_snip,
52
52
} ;
53
53
54
+ let msg = "use the question mark operator instead of an `and_then` call" ;
54
55
let sugg = format ! (
55
56
"let {} = {}?;\n {}" ,
56
- snippet_with_applicability ( cx , closure_arg . span , "_" , & mut applicability ) ,
57
- snippet_with_applicability ( cx , recv . span , ".." , & mut applicability ) ,
57
+ arg_snip ,
58
+ recv_snip ,
58
59
reindent_multiline( inner. into( ) , false , indent_of( cx, expr. span) )
59
60
) ;
60
61
61
- span_lint_and_sugg (
62
- cx,
63
- RETURN_AND_THEN ,
64
- expr. span ,
65
- msg,
66
- "try" ,
67
- sugg,
68
- Applicability :: MachineApplicable ,
69
- ) ;
62
+ span_lint_and_sugg ( cx, RETURN_AND_THEN , expr. span , msg, "try" , sugg, applicability) ;
70
63
}
0 commit comments