@@ -72,44 +72,31 @@ impl Pass {
72
72
if Self :: is_option( cx, subject) ;
73
73
74
74
then {
75
+ let receiver_str = & Sugg :: hir( cx, subject, ".." ) ;
76
+ let mut replacement_str = String :: new( ) ;
75
77
if let Some ( else_) = else_ {
76
78
if_chain! {
77
79
if let ExprKind :: Block ( block, None ) = & else_. node;
78
80
if block. stmts. len( ) == 0 ;
79
81
if let Some ( block_expr) = & block. expr;
80
82
if SpanlessEq :: new( cx) . ignore_fn( ) . eq_expr( subject, block_expr) ;
81
83
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) ;
96
85
}
97
86
}
98
- return ;
87
+ } else {
88
+ replacement_str = format!( "{}?;" , receiver_str) ;
99
89
}
100
-
101
90
span_lint_and_then(
102
91
cx,
103
92
QUESTION_MARK ,
104
93
expr. span,
105
94
"this block may be rewritten with the `?` operator" ,
106
95
|db| {
107
- let receiver_str = & Sugg :: hir( cx, subject, ".." ) ;
108
-
109
96
db. span_suggestion_with_applicability(
110
97
expr. span,
111
98
"replace_it_with" ,
112
- format! ( "{}?;" , receiver_str ) ,
99
+ replacement_str ,
113
100
Applicability :: MaybeIncorrect , // snippet
114
101
) ;
115
102
}
@@ -132,15 +119,15 @@ impl Pass {
132
119
}
133
120
134
121
false
135
- } ,
122
+ }
136
123
ExprKind :: Ret ( Some ( ref expr) ) => Self :: expression_returns_none ( cx, expr) ,
137
124
ExprKind :: Path ( ref qp) => {
138
125
if let Def :: VariantCtor ( def_id, _) = cx. tables . qpath_def ( qp, expression. hir_id ) {
139
126
return match_def_path ( cx. tcx , def_id, & OPTION_NONE ) ;
140
127
}
141
128
142
129
false
143
- } ,
130
+ }
144
131
_ => false ,
145
132
}
146
133
}
0 commit comments