@@ -598,6 +598,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
598
598
599
599
match expr. node {
600
600
ExprKind :: Call ( _, ref args) | ExprKind :: MethodCall ( _, _, ref args) => {
601
+ let mut args_to_recover = vec ! [ ] ;
601
602
for arg in args {
602
603
if is_unit ( cx. tables . expr_ty ( arg) ) && !is_unit_literal ( arg) {
603
604
if let ExprKind :: Match ( .., match_source) = & arg. node {
@@ -606,17 +607,40 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
606
607
}
607
608
}
608
609
609
- span_lint_and_sugg (
610
- cx,
611
- UNIT_ARG ,
612
- arg. span ,
613
- "passing a unit value to a function" ,
614
- "if you intended to pass a unit value, use a unit literal instead" ,
615
- "()" . to_string ( ) ,
616
- Applicability :: MachineApplicable ,
617
- ) ;
610
+ args_to_recover. push ( arg) ;
618
611
}
619
612
}
613
+ if !args_to_recover. is_empty ( ) {
614
+ let mut applicability = Applicability :: MachineApplicable ;
615
+ span_lint_and_then ( cx, UNIT_ARG , expr. span , "passing a unit value to a function" , |db| {
616
+ db. span_suggestion (
617
+ expr. span . with_hi ( expr. span . lo ( ) ) ,
618
+ "move the expressions in front of the call..." ,
619
+ format ! (
620
+ "{} " ,
621
+ args_to_recover
622
+ . iter( )
623
+ . map( |arg| {
624
+ format!(
625
+ "{};" ,
626
+ snippet_with_applicability( cx, arg. span, ".." , & mut applicability)
627
+ )
628
+ } )
629
+ . collect:: <Vec <String >>( )
630
+ . join( " " )
631
+ ) ,
632
+ applicability,
633
+ ) ;
634
+ db. multipart_suggestion (
635
+ "...and use unit literals instead" ,
636
+ args_to_recover
637
+ . iter ( )
638
+ . map ( |arg| ( arg. span , "()" . to_string ( ) ) )
639
+ . collect :: < Vec < _ > > ( ) ,
640
+ applicability,
641
+ ) ;
642
+ } ) ;
643
+ }
620
644
} ,
621
645
_ => ( ) ,
622
646
}
0 commit comments