@@ -683,6 +683,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
683683 let num_trait_generics_except_self =
684684 trait_generics. count ( ) - if trait_generics. has_self { 1 } else { 0 } ;
685685
686+ let msg = format ! (
687+ "consider moving {these} generic argument{s} to the `{name}` trait, which takes up to {num} argument{s}" ,
688+ these = pluralize!( "this" , num_assoc_fn_excess_args) ,
689+ s = pluralize!( num_assoc_fn_excess_args) ,
690+ name = self . tcx. item_name( trait_) ,
691+ num = num_trait_generics_except_self,
692+ ) ;
693+
686694 if let Some ( hir_id) = self . path_segment . hir_id
687695 && let Some ( parent_node) = self . tcx . hir ( ) . find_parent_node ( hir_id)
688696 && let Some ( parent_node) = self . tcx . hir ( ) . find ( parent_node)
@@ -691,14 +699,22 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
691699 hir:: ExprKind :: Path ( ref qpath) => {
692700 self . suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path (
693701 err,
694- trait_,
695702 qpath,
703+ msg,
704+ num_assoc_fn_excess_args,
705+ num_trait_generics_except_self
706+ )
707+ } ,
708+ hir:: ExprKind :: MethodCall ( ..) => {
709+ self . suggest_moving_args_from_assoc_fn_to_trait_for_method_call (
710+ err,
711+ trait_,
712+ expr,
713+ msg,
696714 num_assoc_fn_excess_args,
697715 num_trait_generics_except_self
698716 )
699717 } ,
700- // FIXME(hkmatsumoto): Emit similar suggestion for "x.<assoc fn>()"
701- hir:: ExprKind :: MethodCall ( ..) => return ,
702718 _ => return ,
703719 }
704720 }
@@ -707,8 +723,8 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
707723 fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path (
708724 & self ,
709725 err : & mut Diagnostic ,
710- trait_ : DefId ,
711726 qpath : & ' tcx hir:: QPath < ' tcx > ,
727+ msg : String ,
712728 num_assoc_fn_excess_args : usize ,
713729 num_trait_generics_except_self : usize ,
714730 ) {
@@ -719,13 +735,6 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
719735 if num_assoc_fn_excess_args == num_trait_generics_except_self - num_generic_args_supplied_to_trait {
720736 if let Some ( span) = self . gen_args . span_ext ( )
721737 && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
722- let msg = format ! (
723- "consider moving {these} generic argument{s} to the `{name}` trait, which takes up to {num} argument{s}" ,
724- these = pluralize!( "this" , num_assoc_fn_excess_args) ,
725- s = pluralize!( num_assoc_fn_excess_args) ,
726- name = self . tcx. item_name( trait_) ,
727- num = num_trait_generics_except_self,
728- ) ;
729738 let sugg = vec ! [
730739 ( self . path_segment. ident. span, format!( "{}::{}" , snippet, self . path_segment. ident) ) ,
731740 ( span. with_lo( self . path_segment. ident. span. hi( ) ) , "" . to_owned( ) )
@@ -741,6 +750,28 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
741750 }
742751 }
743752
753+ fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call (
754+ & self ,
755+ err : & mut Diagnostic ,
756+ trait_ : DefId ,
757+ expr : & ' tcx hir:: Expr < ' tcx > ,
758+ msg : String ,
759+ num_assoc_fn_excess_args : usize ,
760+ num_trait_generics_except_self : usize ,
761+ ) {
762+ if let hir:: ExprKind :: MethodCall ( _, args, _) = expr. kind {
763+ assert_eq ! ( args. len( ) , 1 ) ;
764+ if num_assoc_fn_excess_args == num_trait_generics_except_self {
765+ if let Some ( gen_args) = self . gen_args . span_ext ( )
766+ && let Ok ( gen_args) = self . tcx . sess . source_map ( ) . span_to_snippet ( gen_args)
767+ && let Ok ( args) = self . tcx . sess . source_map ( ) . span_to_snippet ( args[ 0 ] . span ) {
768+ let sugg = format ! ( "{}::{}::{}({})" , self . tcx. item_name( trait_) , gen_args, self . tcx. item_name( self . def_id) , args) ;
769+ err. span_suggestion ( expr. span , msg, sugg, Applicability :: MaybeIncorrect ) ;
770+ }
771+ }
772+ }
773+ }
774+
744775 /// Suggests to remove redundant argument(s):
745776 ///
746777 /// ```text
0 commit comments