@@ -21,7 +21,7 @@ fn reduce_unit_expression<'a>(
21
21
match block. expr {
22
22
Some ( inner_expr) => {
23
23
// If block only contains an expression,
24
- // reduce `{ X }` to `X `
24
+ // reduce `|x| { x + 1 }` to `|x| x + 1 `
25
25
reduce_unit_expression ( cx, inner_expr)
26
26
} ,
27
27
_ => None ,
@@ -51,7 +51,6 @@ pub(super) fn check<'tcx>(
51
51
return ;
52
52
}
53
53
54
- // let (lint_name, msg, instead, hint) = {
55
54
let default_arg_is_none = if let hir:: ExprKind :: Path ( ref qpath) = def_arg. kind {
56
55
is_lang_ctor ( cx, qpath, OptionNone )
57
56
} else {
@@ -71,7 +70,8 @@ pub(super) fn check<'tcx>(
71
70
72
71
if is_option {
73
72
let self_snippet = snippet ( cx, recv. span , ".." ) ;
74
- if let hir:: ExprKind :: Closure ( _, _, id, _, _) = map_arg. kind {
73
+ if let hir:: ExprKind :: Closure ( _, _, id, span, _) = map_arg. kind {
74
+ let arg_snippet = snippet ( cx, span, ".." ) ;
75
75
if_chain ! {
76
76
let body = cx. tcx. hir( ) . body( id) ;
77
77
if let Some ( ( func, arg_char) ) = reduce_unit_expression( cx, & body. value) ;
@@ -89,7 +89,7 @@ pub(super) fn check<'tcx>(
89
89
expr. span,
90
90
msg,
91
91
"try using `map` instead" ,
92
- format!( "{0}.map({1})" , self_snippet, func_snippet) ,
92
+ format!( "{0}.map({1} {2} )" , self_snippet, arg_snippet , func_snippet) ,
93
93
Applicability :: MachineApplicable ,
94
94
) ;
95
95
}
@@ -99,30 +99,27 @@ pub(super) fn check<'tcx>(
99
99
let func_snippet = snippet ( cx, map_arg. span , ".." ) ;
100
100
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
101
101
`and_then(..)` instead";
102
- span_lint_and_sugg (
102
+ return span_lint_and_sugg (
103
103
cx,
104
104
OPTION_MAP_OR_NONE ,
105
105
expr. span ,
106
106
msg,
107
107
"try using `and_then` instead" ,
108
108
format ! ( "{0}.and_then({1})" , self_snippet, func_snippet) ,
109
109
Applicability :: MachineApplicable ,
110
- )
110
+ ) ;
111
111
} else if f_arg_is_some {
112
112
let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
113
113
`ok()` instead";
114
114
let self_snippet = snippet ( cx, recv. span , ".." ) ;
115
- span_lint_and_sugg (
115
+ return span_lint_and_sugg (
116
116
cx,
117
117
RESULT_MAP_OR_INTO_OPTION ,
118
118
expr. span ,
119
119
msg,
120
120
"try using `ok` instead" ,
121
121
format ! ( "{0}.ok()" , self_snippet) ,
122
122
Applicability :: MachineApplicable ,
123
- )
124
- } else {
125
- // nothing to lint!
126
- return ;
123
+ ) ;
127
124
}
128
125
}
0 commit comments