@@ -632,6 +632,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
632
632
633
633
match expr. kind {
634
634
ExprKind :: Call ( _, ref args) | ExprKind :: MethodCall ( _, _, ref args) => {
635
+ let mut args_to_recover = vec ! [ ] ;
635
636
for arg in args {
636
637
if is_unit ( cx. tables . expr_ty ( arg) ) && !is_unit_literal ( arg) {
637
638
if let ExprKind :: Match ( .., match_source) = & arg. kind {
@@ -640,17 +641,40 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
640
641
}
641
642
}
642
643
643
- span_lint_and_sugg (
644
- cx,
645
- UNIT_ARG ,
646
- arg. span ,
647
- "passing a unit value to a function" ,
648
- "if you intended to pass a unit value, use a unit literal instead" ,
649
- "()" . to_string ( ) ,
650
- Applicability :: MachineApplicable ,
651
- ) ;
644
+ args_to_recover. push ( arg) ;
652
645
}
653
646
}
647
+ if !args_to_recover. is_empty ( ) {
648
+ let mut applicability = Applicability :: MachineApplicable ;
649
+ span_lint_and_then ( cx, UNIT_ARG , expr. span , "passing a unit value to a function" , |db| {
650
+ db. span_suggestion (
651
+ expr. span . with_hi ( expr. span . lo ( ) ) ,
652
+ "move the expressions in front of the call..." ,
653
+ format ! (
654
+ "{} " ,
655
+ args_to_recover
656
+ . iter( )
657
+ . map( |arg| {
658
+ format!(
659
+ "{};" ,
660
+ snippet_with_applicability( cx, arg. span, ".." , & mut applicability)
661
+ )
662
+ } )
663
+ . collect:: <Vec <String >>( )
664
+ . join( " " )
665
+ ) ,
666
+ applicability,
667
+ ) ;
668
+ db. multipart_suggestion (
669
+ "...and use unit literals instead" ,
670
+ args_to_recover
671
+ . iter ( )
672
+ . map ( |arg| ( arg. span , "()" . to_string ( ) ) )
673
+ . collect :: < Vec < _ > > ( ) ,
674
+ applicability,
675
+ ) ;
676
+ } ) ;
677
+ }
654
678
} ,
655
679
_ => ( ) ,
656
680
}
0 commit comments