@@ -65,7 +65,7 @@ pub trait InferCtxtExt<'tcx> {
65
65
/// returns a span and `ArgKind` information that describes the
66
66
/// arguments it expects. This can be supplied to
67
67
/// `report_arg_count_mismatch`.
68
- fn get_fn_like_arguments ( & self , node : Node < ' _ > ) -> ( Span , Vec < ArgKind > ) ;
68
+ fn get_fn_like_arguments ( & self , node : Node < ' _ > ) -> Option < ( Span , Vec < ArgKind > ) > ;
69
69
70
70
/// Reports an error when the number of arguments needed by a
71
71
/// trait match doesn't match the number that the expression
@@ -611,10 +611,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
611
611
)
612
612
} else {
613
613
let ( closure_span, found) = found_did
614
- . and_then ( |did| self . tcx . hir ( ) . get_if_local ( did ) )
615
- . map ( | node| {
616
- let ( found_span, found) = self . get_fn_like_arguments ( node) ;
617
- ( Some ( found_span) , found)
614
+ . and_then ( |did| {
615
+ let node = self . tcx . hir ( ) . get_if_local ( did ) ? ;
616
+ let ( found_span, found) = self . get_fn_like_arguments ( node) ? ;
617
+ Some ( ( Some ( found_span) , found) )
618
618
} )
619
619
. unwrap_or ( ( found_span, found) ) ;
620
620
@@ -672,43 +672,38 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
672
672
/// returns a span and `ArgKind` information that describes the
673
673
/// arguments it expects. This can be supplied to
674
674
/// `report_arg_count_mismatch`.
675
- fn get_fn_like_arguments ( & self , node : Node < ' _ > ) -> ( Span , Vec < ArgKind > ) {
676
- match node {
675
+ fn get_fn_like_arguments ( & self , node : Node < ' _ > ) -> Option < ( Span , Vec < ArgKind > ) > {
676
+ let sm = self . tcx . sess . source_map ( ) ;
677
+ let hir = self . tcx . hir ( ) ;
678
+ Some ( match node {
677
679
Node :: Expr ( & hir:: Expr {
678
680
kind : hir:: ExprKind :: Closure ( _, ref _decl, id, span, _) ,
679
681
..
680
682
} ) => (
681
- self . tcx . sess . source_map ( ) . guess_head_span ( span) ,
682
- self . tcx
683
- . hir ( )
684
- . body ( id)
683
+ sm. guess_head_span ( span) ,
684
+ hir. body ( id)
685
685
. params
686
686
. iter ( )
687
687
. map ( |arg| {
688
688
if let hir:: Pat { kind : hir:: PatKind :: Tuple ( ref args, _) , span, .. } =
689
689
* arg. pat
690
690
{
691
- ArgKind :: Tuple (
691
+ Some ( ArgKind :: Tuple (
692
692
Some ( span) ,
693
693
args. iter ( )
694
694
. map ( |pat| {
695
- let snippet = self
696
- . tcx
697
- . sess
698
- . source_map ( )
699
- . span_to_snippet ( pat. span )
700
- . unwrap ( ) ;
701
- ( snippet, "_" . to_owned ( ) )
695
+ sm. span_to_snippet ( pat. span )
696
+ . ok ( )
697
+ . map ( |snippet| ( snippet, "_" . to_owned ( ) ) )
702
698
} )
703
- . collect :: < Vec < _ > > ( ) ,
704
- )
699
+ . collect :: < Option < Vec < _ > > > ( ) ? ,
700
+ ) )
705
701
} else {
706
- let name =
707
- self . tcx . sess . source_map ( ) . span_to_snippet ( arg. pat . span ) . unwrap ( ) ;
708
- ArgKind :: Arg ( name, "_" . to_owned ( ) )
702
+ let name = sm. span_to_snippet ( arg. pat . span ) . ok ( ) ?;
703
+ Some ( ArgKind :: Arg ( name, "_" . to_owned ( ) ) )
709
704
}
710
705
} )
711
- . collect :: < Vec < ArgKind > > ( ) ,
706
+ . collect :: < Option < Vec < ArgKind > > > ( ) ? ,
712
707
) ,
713
708
Node :: Item ( & hir:: Item { span, kind : hir:: ItemKind :: Fn ( ref sig, ..) , .. } )
714
709
| Node :: ImplItem ( & hir:: ImplItem {
@@ -721,7 +716,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
721
716
kind : hir:: TraitItemKind :: Fn ( ref sig, _) ,
722
717
..
723
718
} ) => (
724
- self . tcx . sess . source_map ( ) . guess_head_span ( span) ,
719
+ sm . guess_head_span ( span) ,
725
720
sig. decl
726
721
. inputs
727
722
. iter ( )
@@ -735,16 +730,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
735
730
. collect :: < Vec < ArgKind > > ( ) ,
736
731
) ,
737
732
Node :: Ctor ( ref variant_data) => {
738
- let span = variant_data
739
- . ctor_hir_id ( )
740
- . map ( |hir_id| self . tcx . hir ( ) . span ( hir_id) )
741
- . unwrap_or ( DUMMY_SP ) ;
742
- let span = self . tcx . sess . source_map ( ) . guess_head_span ( span) ;
743
-
733
+ let span = variant_data. ctor_hir_id ( ) . map ( |id| hir. span ( id) ) . unwrap_or ( DUMMY_SP ) ;
734
+ let span = sm. guess_head_span ( span) ;
744
735
( span, vec ! [ ArgKind :: empty( ) ; variant_data. fields( ) . len( ) ] )
745
736
}
746
737
_ => panic ! ( "non-FnLike node found: {:?}" , node) ,
747
- }
738
+ } )
748
739
}
749
740
750
741
/// Reports an error when the number of arguments needed by a
0 commit comments