@@ -794,32 +794,43 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
794
794
if !args_to_recover. is_empty ( ) {
795
795
let mut applicability = Applicability :: MachineApplicable ;
796
796
span_lint_and_then ( cx, UNIT_ARG , expr. span , "passing a unit value to a function" , |db| {
797
+ let sugg = args_to_recover
798
+ . iter ( )
799
+ . enumerate ( )
800
+ . map ( |( i, arg) | {
801
+ let indent = if i == 0 {
802
+ 0
803
+ } else {
804
+ indent_of ( cx, expr. span ) . unwrap_or ( 0 )
805
+ } ;
806
+ format ! (
807
+ "{}{};" ,
808
+ " " . repeat( indent) ,
809
+ snippet_block_with_applicability(
810
+ cx,
811
+ arg. span,
812
+ ".." ,
813
+ Some ( expr. span) ,
814
+ & mut applicability
815
+ )
816
+ )
817
+ } )
818
+ . collect :: < Vec < String > > ( )
819
+ . join ( "\n " ) ;
797
820
db. span_suggestion (
798
821
expr. span . with_hi ( expr. span . lo ( ) ) ,
799
- "move the expressions in front of the call..." ,
800
- format ! (
801
- "{} " ,
802
- args_to_recover
803
- . iter( )
804
- . map( |arg| {
805
- format!(
806
- "{};" ,
807
- snippet_with_applicability( cx, arg. span, ".." , & mut applicability)
808
- )
809
- } )
810
- . collect:: <Vec <String >>( )
811
- . join( " " )
812
- ) ,
822
+ & format ! ( "{}move the expressions in front of the call..." , or) ,
823
+ format ! ( "{}\n " , sugg) ,
824
+ applicability,
825
+ ) ;
826
+ db. multipart_suggestion (
827
+ "...and use unit literals instead" ,
828
+ args_to_recover
829
+ . iter ( )
830
+ . map ( |arg| ( arg. span , "()" . to_string ( ) ) )
831
+ . collect :: < Vec < _ > > ( ) ,
813
832
applicability,
814
833
) ;
815
- for arg in args_to_recover {
816
- db. span_suggestion (
817
- arg. span ,
818
- "...and use unit literals instead" ,
819
- "()" . to_string ( ) ,
820
- applicability,
821
- ) ;
822
- }
823
834
} ) ;
824
835
}
825
836
} ,
0 commit comments