@@ -764,8 +764,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
764
764
} else {
765
765
let ( closure_span, found) = found_did
766
766
. and_then ( |did| self . tcx . hir . get_if_local ( did) )
767
- . map ( |node| self . get_fn_like_arguments ( node) )
768
- . unwrap_or ( ( found_span. unwrap ( ) , found) ) ;
767
+ . map ( |node| {
768
+ let ( found_span, found) = self . get_fn_like_arguments ( node) ;
769
+ ( Some ( found_span) , found)
770
+ } ) . unwrap_or ( ( found_span, found) ) ;
769
771
770
772
self . report_arg_count_mismatch ( span,
771
773
closure_span,
@@ -875,7 +877,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
875
877
fn report_arg_count_mismatch (
876
878
& self ,
877
879
span : Span ,
878
- found_span : Span ,
880
+ found_span : Option < Span > ,
879
881
expected_args : Vec < ArgKind > ,
880
882
found_args : Vec < ArgKind > ,
881
883
is_closure : bool ,
@@ -913,48 +915,51 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
913
915
) ;
914
916
915
917
err. span_label ( span, format ! ( "expected {} that takes {}" , kind, expected_str) ) ;
916
- err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
917
-
918
- if let & [ ArgKind :: Tuple ( _, ref fields) ] = & found_args[ ..] {
919
- if fields. len ( ) == expected_args. len ( ) {
920
- let sugg = fields. iter ( )
921
- . map ( |( name, _) | name. to_owned ( ) )
922
- . collect :: < Vec < String > > ( ) . join ( ", " ) ;
923
- err. span_suggestion ( found_span,
924
- "change the closure to take multiple arguments instead of \
925
- a single tuple",
926
- format ! ( "|{}|" , sugg) ) ;
918
+
919
+ if let Some ( found_span) = found_span {
920
+ err. span_label ( found_span, format ! ( "takes {}" , found_str) ) ;
921
+
922
+ if let & [ ArgKind :: Tuple ( _, ref fields) ] = & found_args[ ..] {
923
+ if fields. len ( ) == expected_args. len ( ) {
924
+ let sugg = fields. iter ( )
925
+ . map ( |( name, _) | name. to_owned ( ) )
926
+ . collect :: < Vec < String > > ( ) . join ( ", " ) ;
927
+ err. span_suggestion ( found_span,
928
+ "change the closure to take multiple arguments instead of \
929
+ a single tuple",
930
+ format ! ( "|{}|" , sugg) ) ;
931
+ }
927
932
}
928
- }
929
- if let & [ ArgKind :: Tuple ( _ , ref fields) ] = & expected_args [ .. ] {
930
- if fields . len ( ) == found_args . len ( ) && is_closure {
931
- let sugg = format ! (
932
- "|({}){}|" ,
933
- found_args . iter ( )
934
- . map ( |arg| match arg {
935
- ArgKind :: Arg ( name , _ ) => name . to_owned( ) ,
936
- _ => "_" . to_owned ( ) ,
937
- } )
938
- . collect :: < Vec < String >> ( )
939
- . join ( ", " ) ,
940
- // add type annotations if available
941
- if found_args . iter ( ) . any ( |arg| match arg {
942
- ArgKind :: Arg ( _ , ty ) => ty != "_" ,
943
- _ => false ,
944
- } ) {
945
- format! ( ": ({})" ,
946
- fields . iter ( )
947
- . map ( | ( _ , ty ) | ty . to_owned ( ) )
948
- . collect :: < Vec < String >> ( )
949
- . join ( ", " ) )
950
- } else {
951
- "" . to_owned ( )
952
- } ,
953
- ) ;
954
- err . span_suggestion ( found_span ,
955
- "change the closure to accept a tuple instead of individual \
956
- arguments" ,
957
- sugg ) ;
933
+ if let & [ ArgKind :: Tuple ( _ , ref fields ) ] = & expected_args [ .. ] {
934
+ if fields. len ( ) == found_args . len ( ) && is_closure {
935
+ let sugg = format ! (
936
+ "|({}){}|" ,
937
+ found_args . iter ( )
938
+ . map ( |arg| match arg {
939
+ ArgKind :: Arg ( name , _ ) => name . to_owned ( ) ,
940
+ _ => "_" . to_owned( ) ,
941
+ } )
942
+ . collect :: < Vec < String >> ( )
943
+ . join ( ", " ) ,
944
+ // add type annotations if available
945
+ if found_args . iter ( ) . any ( |arg| match arg {
946
+ ArgKind :: Arg ( _ , ty ) => ty != "_" ,
947
+ _ => false ,
948
+ } ) {
949
+ format! ( ": ({})" ,
950
+ fields . iter ( )
951
+ . map ( | ( _ , ty ) | ty . to_owned ( ) )
952
+ . collect :: < Vec < String >> ( )
953
+ . join ( ", " ) )
954
+ } else {
955
+ "" . to_owned ( )
956
+ } ,
957
+ ) ;
958
+ err . span_suggestion ( found_span ,
959
+ "change the closure to accept a tuple instead of \
960
+ individual arguments" ,
961
+ sugg ) ;
962
+ }
958
963
}
959
964
}
960
965
0 commit comments