@@ -65,7 +65,7 @@ pub trait InferCtxtExt<'tcx> {
6565 /// returns a span and `ArgKind` information that describes the
6666 /// arguments it expects. This can be supplied to
6767 /// `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 > ) > ;
6969
7070 /// Reports an error when the number of arguments needed by a
7171 /// trait match doesn't match the number that the expression
@@ -611,10 +611,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
611611 )
612612 } else {
613613 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) )
618618 } )
619619 . unwrap_or ( ( found_span, found) ) ;
620620
@@ -672,43 +672,38 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
672672 /// returns a span and `ArgKind` information that describes the
673673 /// arguments it expects. This can be supplied to
674674 /// `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 {
677679 Node :: Expr ( & hir:: Expr {
678680 kind : hir:: ExprKind :: Closure ( _, ref _decl, id, span, _) ,
679681 ..
680682 } ) => (
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)
685685 . params
686686 . iter ( )
687687 . map ( |arg| {
688688 if let hir:: Pat { kind : hir:: PatKind :: Tuple ( ref args, _) , span, .. } =
689689 * arg. pat
690690 {
691- ArgKind :: Tuple (
691+ Some ( ArgKind :: Tuple (
692692 Some ( span) ,
693693 args. iter ( )
694694 . 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 ( ) ) )
702698 } )
703- . collect :: < Vec < _ > > ( ) ,
704- )
699+ . collect :: < Option < Vec < _ > > > ( ) ? ,
700+ ) )
705701 } 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 ( ) ) )
709704 }
710705 } )
711- . collect :: < Vec < ArgKind > > ( ) ,
706+ . collect :: < Option < Vec < ArgKind > > > ( ) ? ,
712707 ) ,
713708 Node :: Item ( & hir:: Item { span, kind : hir:: ItemKind :: Fn ( ref sig, ..) , .. } )
714709 | Node :: ImplItem ( & hir:: ImplItem {
@@ -721,7 +716,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
721716 kind : hir:: TraitItemKind :: Fn ( ref sig, _) ,
722717 ..
723718 } ) => (
724- self . tcx . sess . source_map ( ) . guess_head_span ( span) ,
719+ sm . guess_head_span ( span) ,
725720 sig. decl
726721 . inputs
727722 . iter ( )
@@ -735,16 +730,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
735730 . collect :: < Vec < ArgKind > > ( ) ,
736731 ) ,
737732 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) ;
744735 ( span, vec ! [ ArgKind :: empty( ) ; variant_data. fields( ) . len( ) ] )
745736 }
746737 _ => panic ! ( "non-FnLike node found: {:?}" , node) ,
747- }
738+ } )
748739 }
749740
750741 /// Reports an error when the number of arguments needed by a
0 commit comments