@@ -747,7 +747,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
747
747
ty:: TyTuple ( ref tys, _) => tys. iter ( )
748
748
. map ( |t| match t. sty {
749
749
ty:: TypeVariants :: TyTuple ( ref tys, _) => ArgKind :: Tuple (
750
- span,
750
+ Some ( span) ,
751
751
tys. iter ( )
752
752
. map ( |ty| ( "_" . to_owned ( ) , format ! ( "{}" , ty. sty) ) )
753
753
. collect :: < Vec < _ > > ( )
@@ -815,7 +815,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
815
815
}
816
816
}
817
817
818
- fn get_fn_like_arguments ( & self , node : hir:: map:: Node ) -> ( Span , Vec < ArgKind > ) {
818
+ /// Given some node representing a fn-like thing in the HIR map,
819
+ /// returns a span and `ArgKind` information that describes the
820
+ /// arguments it expects. This can be supplied to
821
+ /// `report_arg_count_mismatch`.
822
+ pub fn get_fn_like_arguments ( & self , node : hir:: map:: Node ) -> ( Span , Vec < ArgKind > ) {
819
823
match node {
820
824
hir:: map:: NodeExpr ( & hir:: Expr {
821
825
node : hir:: ExprClosure ( _, ref _decl, id, span, _) ,
@@ -829,7 +833,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
829
833
..
830
834
} = arg. pat . clone ( ) . into_inner ( ) {
831
835
ArgKind :: Tuple (
832
- span,
836
+ Some ( span) ,
833
837
args. iter ( ) . map ( |pat| {
834
838
let snippet = self . tcx . sess . codemap ( )
835
839
. span_to_snippet ( pat. span ) . unwrap ( ) ;
@@ -862,7 +866,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
862
866
( self . tcx . sess . codemap ( ) . def_span ( span) , decl. inputs . iter ( )
863
867
. map ( |arg| match arg. clone ( ) . into_inner ( ) . node {
864
868
hir:: TyTup ( ref tys) => ArgKind :: Tuple (
865
- arg. span ,
869
+ Some ( arg. span ) ,
866
870
tys. iter ( )
867
871
. map ( |_| ( "_" . to_owned ( ) , "_" . to_owned ( ) ) )
868
872
. collect :: < Vec < _ > > ( ) ,
@@ -874,7 +878,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
874
878
}
875
879
}
876
880
877
- fn report_arg_count_mismatch (
881
+ /// Reports an error when the number of arguments needed by a
882
+ /// trait match doesn't match the number that the expression
883
+ /// provides.
884
+ pub fn report_arg_count_mismatch (
878
885
& self ,
879
886
span : Span ,
880
887
found_span : Option < Span > ,
@@ -1385,13 +1392,34 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1385
1392
}
1386
1393
}
1387
1394
1388
- enum ArgKind {
1395
+ /// Summarizes information
1396
+ pub enum ArgKind {
1397
+ /// An argument of non-tuple type. Parameters are (name, ty)
1389
1398
Arg ( String , String ) ,
1390
- Tuple ( Span , Vec < ( String , String ) > ) ,
1399
+
1400
+ /// An argument of tuple type. For a "found" argument, the span is
1401
+ /// the locationo in the source of the pattern. For a "expected"
1402
+ /// argument, it will be None. The vector is a list of (name, ty)
1403
+ /// strings for the components of the tuple.
1404
+ Tuple ( Option < Span > , Vec < ( String , String ) > ) ,
1391
1405
}
1392
1406
1393
1407
impl ArgKind {
1394
1408
fn empty ( ) -> ArgKind {
1395
1409
ArgKind :: Arg ( "_" . to_owned ( ) , "_" . to_owned ( ) )
1396
1410
}
1411
+
1412
+ /// Creates an `ArgKind` from the expected type of an
1413
+ /// argument. This has no name (`_`) and no source spans..
1414
+ pub fn from_expected_ty ( t : Ty < ' _ > ) -> ArgKind {
1415
+ match t. sty {
1416
+ ty:: TyTuple ( ref tys, _) => ArgKind :: Tuple (
1417
+ None ,
1418
+ tys. iter ( )
1419
+ . map ( |ty| ( "_" . to_owned ( ) , format ! ( "{}" , ty. sty) ) )
1420
+ . collect :: < Vec < _ > > ( )
1421
+ ) ,
1422
+ _ => ArgKind :: Arg ( "_" . to_owned ( ) , format ! ( "{}" , t. sty) ) ,
1423
+ }
1424
+ }
1397
1425
}
0 commit comments