@@ -21,7 +21,7 @@ fn reduce_unit_expression<'a>(
2121 match block. expr {
2222 Some ( inner_expr) => {
2323 // If block only contains an expression,
24- // reduce `{ X }` to `X `
24+ // reduce `|x| { x + 1 }` to `|x| x + 1 `
2525 reduce_unit_expression ( cx, inner_expr)
2626 } ,
2727 _ => None ,
@@ -51,7 +51,6 @@ pub(super) fn check<'tcx>(
5151 return ;
5252 }
5353
54- // let (lint_name, msg, instead, hint) = {
5554 let default_arg_is_none = if let hir:: ExprKind :: Path ( ref qpath) = def_arg. kind {
5655 is_lang_ctor ( cx, qpath, OptionNone )
5756 } else {
@@ -71,7 +70,8 @@ pub(super) fn check<'tcx>(
7170
7271 if is_option {
7372 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, ".." ) ;
7575 if_chain ! {
7676 let body = cx. tcx. hir( ) . body( id) ;
7777 if let Some ( ( func, arg_char) ) = reduce_unit_expression( cx, & body. value) ;
@@ -89,7 +89,7 @@ pub(super) fn check<'tcx>(
8989 expr. span,
9090 msg,
9191 "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) ,
9393 Applicability :: MachineApplicable ,
9494 ) ;
9595 }
@@ -99,30 +99,27 @@ pub(super) fn check<'tcx>(
9999 let func_snippet = snippet ( cx, map_arg. span , ".." ) ;
100100 let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
101101 `and_then(..)` instead";
102- span_lint_and_sugg (
102+ return span_lint_and_sugg (
103103 cx,
104104 OPTION_MAP_OR_NONE ,
105105 expr. span ,
106106 msg,
107107 "try using `and_then` instead" ,
108108 format ! ( "{0}.and_then({1})" , self_snippet, func_snippet) ,
109109 Applicability :: MachineApplicable ,
110- )
110+ ) ;
111111 } else if f_arg_is_some {
112112 let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
113113 `ok()` instead";
114114 let self_snippet = snippet ( cx, recv. span , ".." ) ;
115- span_lint_and_sugg (
115+ return span_lint_and_sugg (
116116 cx,
117117 RESULT_MAP_OR_INTO_OPTION ,
118118 expr. span ,
119119 msg,
120120 "try using `ok` instead" ,
121121 format ! ( "{0}.ok()" , self_snippet) ,
122122 Applicability :: MachineApplicable ,
123- )
124- } else {
125- // nothing to lint!
126- return ;
123+ ) ;
127124 }
128125}
0 commit comments