@@ -72,44 +72,31 @@ impl Pass {
7272 if Self :: is_option( cx, subject) ;
7373
7474 then {
75+ let receiver_str = & Sugg :: hir( cx, subject, ".." ) ;
76+ let mut replacement_str = String :: new( ) ;
7577 if let Some ( else_) = else_ {
7678 if_chain! {
7779 if let ExprKind :: Block ( block, None ) = & else_. node;
7880 if block. stmts. len( ) == 0 ;
7981 if let Some ( block_expr) = & block. expr;
8082 if SpanlessEq :: new( cx) . ignore_fn( ) . eq_expr( subject, block_expr) ;
8183 then {
82- span_lint_and_then(
83- cx,
84- QUESTION_MARK ,
85- expr. span,
86- "this block may be rewritten with the `?` operator" ,
87- |db| {
88- db. span_suggestion_with_applicability(
89- expr. span,
90- "replace_it_with" ,
91- format!( "Some({}?)" , Sugg :: hir( cx, subject, ".." ) ) ,
92- Applicability :: MaybeIncorrect , // snippet
93- ) ;
94- }
95- )
84+ replacement_str = format!( "Some({}?)" , receiver_str) ;
9685 }
9786 }
98- return ;
87+ } else {
88+ replacement_str = format!( "{}?;" , receiver_str) ;
9989 }
100-
10190 span_lint_and_then(
10291 cx,
10392 QUESTION_MARK ,
10493 expr. span,
10594 "this block may be rewritten with the `?` operator" ,
10695 |db| {
107- let receiver_str = & Sugg :: hir( cx, subject, ".." ) ;
108-
10996 db. span_suggestion_with_applicability(
11097 expr. span,
11198 "replace_it_with" ,
112- format! ( "{}?;" , receiver_str ) ,
99+ replacement_str ,
113100 Applicability :: MaybeIncorrect , // snippet
114101 ) ;
115102 }
@@ -132,15 +119,15 @@ impl Pass {
132119 }
133120
134121 false
135- } ,
122+ }
136123 ExprKind :: Ret ( Some ( ref expr) ) => Self :: expression_returns_none ( cx, expr) ,
137124 ExprKind :: Path ( ref qp) => {
138125 if let Def :: VariantCtor ( def_id, _) = cx. tables . qpath_def ( qp, expression. hir_id ) {
139126 return match_def_path ( cx. tcx , def_id, & OPTION_NONE ) ;
140127 }
141128
142129 false
143- } ,
130+ }
144131 _ => false ,
145132 }
146133 }
0 commit comments