@@ -70,7 +70,7 @@ declare_clippy_lint! {
70
70
"using a return statement like `return expr;` where an expression would suffice"
71
71
}
72
72
73
- #[ derive( PartialEq , Eq , Clone ) ]
73
+ #[ derive( PartialEq , Eq ) ]
74
74
enum RetReplacement < ' tcx > {
75
75
Empty ,
76
76
Block ,
@@ -80,18 +80,19 @@ enum RetReplacement<'tcx> {
80
80
}
81
81
82
82
impl < ' tcx > RetReplacement < ' tcx > {
83
- fn sugg_help ( self ) -> & ' static str {
83
+ fn sugg_help ( & self ) -> & ' static str {
84
84
match self {
85
85
Self :: Empty | Self :: Expr ( ..) => "remove `return`" ,
86
86
Self :: Block => "replace `return` with an empty block" ,
87
87
Self :: Unit => "replace `return` with a unit value" ,
88
88
Self :: IfSequence ( ..) => "remove `return` and wrap the sequence with parentheses" ,
89
89
}
90
90
}
91
- fn applicability ( & self ) -> Option < Applicability > {
91
+
92
+ fn applicability ( & self ) -> Applicability {
92
93
match self {
93
- Self :: Expr ( _, ap) | Self :: IfSequence ( _, ap) => Some ( * ap) ,
94
- _ => None ,
94
+ Self :: Expr ( _, ap) | Self :: IfSequence ( _, ap) => * ap,
95
+ _ => Applicability :: MachineApplicable ,
95
96
}
96
97
}
97
98
}
@@ -271,7 +272,7 @@ fn check_final_expr<'tcx>(
271
272
return ;
272
273
}
273
274
274
- emit_return_lint ( cx, ret_span, semi_spans, replacement) ;
275
+ emit_return_lint ( cx, ret_span, semi_spans, & replacement) ;
275
276
} ,
276
277
ExprKind :: If ( _, then, else_clause_opt) => {
277
278
check_block_return ( cx, & then. kind , peeled_drop_expr. span , semi_spans. clone ( ) ) ;
@@ -306,20 +307,17 @@ fn expr_contains_conjunctive_ifs<'tcx>(expr: &'tcx Expr<'tcx>) -> bool {
306
307
contains_if ( expr, false )
307
308
}
308
309
309
- fn emit_return_lint ( cx : & LateContext < ' _ > , ret_span : Span , semi_spans : Vec < Span > , replacement : RetReplacement < ' _ > ) {
310
+ fn emit_return_lint ( cx : & LateContext < ' _ > , ret_span : Span , semi_spans : Vec < Span > , replacement : & RetReplacement < ' _ > ) {
310
311
if ret_span. from_expansion ( ) {
311
312
return ;
312
313
}
313
314
314
- let applicability = replacement. applicability ( ) . unwrap_or ( Applicability :: MachineApplicable ) ;
315
- let return_replacement = replacement. to_string ( ) ;
316
- let sugg_help = replacement. sugg_help ( ) ;
317
315
span_lint_and_then ( cx, NEEDLESS_RETURN , ret_span, "unneeded `return` statement" , |diag| {
318
- diag . span_suggestion_hidden ( ret_span, sugg_help , return_replacement , applicability ) ;
319
- // for each parent statement, we need to remove the semicolon
320
- for semi_stmt_span in semi_spans {
321
- diag . tool_only_span_suggestion ( semi_stmt_span , "remove this semicolon" , "" , applicability ) ;
322
- }
316
+ let suggestions = std :: iter :: once ( ( ret_span, replacement . to_string ( ) ) )
317
+ . chain ( semi_spans . into_iter ( ) . map ( |span| ( span , String :: new ( ) ) ) )
318
+ . collect ( ) ;
319
+
320
+ diag . multipart_suggestion_verbose ( replacement . sugg_help ( ) , suggestions , replacement . applicability ( ) ) ;
323
321
} ) ;
324
322
}
325
323
0 commit comments