@@ -25,10 +25,10 @@ use syntax::ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
2525use crate :: consts:: { constant, Constant } ;
2626use crate :: utils:: paths;
2727use crate :: utils:: {
28- clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits , last_path_segment , match_def_path ,
29- match_path, method_chain_args, multispan_sugg, qpath_res, same_tys, sext, snippet, snippet_opt ,
30- snippet_with_applicability , snippet_with_macro_callsite , span_lint , span_lint_and_help , span_lint_and_sugg ,
31- span_lint_and_then, unsext,
28+ clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of , int_bits , last_path_segment ,
29+ match_def_path , match_path, method_chain_args, multispan_sugg, qpath_res, same_tys, sext, snippet,
30+ snippet_block_with_applicability , snippet_opt , snippet_with_applicability , snippet_with_macro_callsite , span_lint ,
31+ span_lint_and_help , span_lint_and_sugg , span_lint_and_then, unsext,
3232} ;
3333
3434declare_clippy_lint ! {
@@ -675,32 +675,43 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
675675 if !args_to_recover. is_empty ( ) {
676676 let mut applicability = Applicability :: MachineApplicable ;
677677 span_lint_and_then ( cx, UNIT_ARG , expr. span , "passing a unit value to a function" , |db| {
678+ let sugg = args_to_recover
679+ . iter ( )
680+ . enumerate ( )
681+ . map ( |( i, arg) | {
682+ let indent = if i == 0 {
683+ 0
684+ } else {
685+ indent_of ( cx, expr. span ) . unwrap_or ( 0 )
686+ } ;
687+ format ! (
688+ "{}{};" ,
689+ " " . repeat( indent) ,
690+ snippet_block_with_applicability(
691+ cx,
692+ arg. span,
693+ ".." ,
694+ Some ( expr. span) ,
695+ & mut applicability
696+ )
697+ )
698+ } )
699+ . collect :: < Vec < String > > ( )
700+ . join ( "\n " ) ;
678701 db. span_suggestion (
679702 expr. span . with_hi ( expr. span . lo ( ) ) ,
680- "move the expressions in front of the call..." ,
681- format ! (
682- "{} " ,
683- args_to_recover
684- . iter( )
685- . map( |arg| {
686- format!(
687- "{};" ,
688- snippet_with_applicability( cx, arg. span, ".." , & mut applicability)
689- )
690- } )
691- . collect:: <Vec <String >>( )
692- . join( " " )
693- ) ,
703+ & format ! ( "{}move the expressions in front of the call..." , or) ,
704+ format ! ( "{}\n " , sugg) ,
705+ applicability,
706+ ) ;
707+ db. multipart_suggestion (
708+ "...and use unit literals instead" ,
709+ args_to_recover
710+ . iter ( )
711+ . map ( |arg| ( arg. span , "()" . to_string ( ) ) )
712+ . collect :: < Vec < _ > > ( ) ,
694713 applicability,
695714 ) ;
696- for arg in args_to_recover {
697- db. span_suggestion (
698- arg. span ,
699- "...and use unit literals instead" ,
700- "()" . to_string ( ) ,
701- applicability,
702- ) ;
703- }
704715 } ) ;
705716 }
706717 } ,
0 commit comments