@@ -84,11 +84,23 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
8484 // HACK(eddyb) Avoid having RustCall on closures,
8585 // as it adds unnecessary (and wrong) auto-tupling.
8686 abi = Abi :: Rust ;
87- Some ( ArgInfo ( liberated_closure_env_ty ( tcx, id, body_id) , None , None , None ) )
87+ Some ( ArgInfo {
88+ ty : liberated_closure_env_ty ( tcx, id, body_id) ,
89+ span : None ,
90+ pattern : None ,
91+ user_pattern : None ,
92+ self_kind : None ,
93+ } )
8894 }
8995 ty:: Generator ( ..) => {
9096 let gen_ty = tcx. body_tables ( body_id) . node_type ( id) ;
91- Some ( ArgInfo ( gen_ty, None , None , None ) )
97+ Some ( ArgInfo {
98+ ty : gen_ty,
99+ span : None ,
100+ pattern : None ,
101+ user_pattern : None ,
102+ self_kind : None ,
103+ } )
92104 }
93105 _ => None ,
94106 } ;
@@ -126,7 +138,15 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
126138 opt_ty_info = None ;
127139 self_arg = None ;
128140 }
129- ArgInfo ( fn_sig. inputs ( ) [ index] , opt_ty_info, Some ( & * arg. pat ) , self_arg)
141+
142+ let original_pat = tcx. hir ( ) . original_pat_of_argument ( arg) ;
143+ ArgInfo {
144+ ty : fn_sig. inputs ( ) [ index] ,
145+ span : opt_ty_info,
146+ pattern : Some ( & * arg. pat ) ,
147+ user_pattern : Some ( & original_pat) ,
148+ self_kind : self_arg,
149+ }
130150 } ) ;
131151
132152 let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
@@ -614,10 +634,13 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
614634///////////////////////////////////////////////////////////////////////////
615635/// the main entry point for building MIR for a function
616636
617- struct ArgInfo < ' gcx > ( Ty < ' gcx > ,
618- Option < Span > ,
619- Option < & ' gcx hir:: Pat > ,
620- Option < ImplicitSelfKind > ) ;
637+ struct ArgInfo < ' gcx > {
638+ ty : Ty < ' gcx > ,
639+ span : Option < Span > ,
640+ pattern : Option < & ' gcx hir:: Pat > ,
641+ user_pattern : Option < & ' gcx hir:: Pat > ,
642+ self_kind : Option < ImplicitSelfKind > ,
643+ }
621644
622645fn construct_fn < ' a , ' gcx , ' tcx , A > ( hir : Cx < ' a , ' gcx , ' tcx > ,
623646 fn_id : hir:: HirId ,
@@ -878,26 +901,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
878901 -> BlockAnd < ( ) >
879902 {
880903 // Allocate locals for the function arguments
881- for & ArgInfo ( ty, _, pattern, _ ) in arguments. iter ( ) {
904+ for & ArgInfo { ty, span : _, pattern, user_pattern , self_kind : _ } in arguments. iter ( ) {
882905 // If this is a simple binding pattern, give the local a name for
883906 // debuginfo and so that error reporting knows that this is a user
884907 // variable. For any other pattern the pattern introduces new
885908 // variables which will be named instead.
886- let mut name = None ;
887- if let Some ( pat) = pattern {
909+ let ( name, span) = if let Some ( pat) = user_pattern {
888910 match pat. node {
889911 hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Unannotated , _, ident, _)
890- | hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Mutable , _, ident, _) => {
891- name = Some ( ident. name ) ;
892- }
893- _ => ( ) ,
912+ | hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Mutable , _, ident, _) =>
913+ ( Some ( ident. name ) , pat. span ) ,
914+ _ => ( None , pattern. map_or ( self . fn_span , |pat| pat. span ) )
894915 }
895- }
896-
897- let source_info = SourceInfo {
898- scope : OUTERMOST_SOURCE_SCOPE ,
899- span : pattern. map_or ( self . fn_span , |pat| pat. span )
916+ } else {
917+ ( None , self . fn_span )
900918 } ;
919+
920+ let source_info = SourceInfo { scope : OUTERMOST_SOURCE_SCOPE , span, } ;
901921 self . local_decls . push ( LocalDecl {
902922 mutability : Mutability :: Mut ,
903923 ty,
@@ -917,7 +937,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
917937 // Function arguments always get the first Local indices after the return place
918938 let local = Local :: new ( index + 1 ) ;
919939 let place = Place :: Base ( PlaceBase :: Local ( local) ) ;
920- let & ArgInfo ( ty, opt_ty_info, pattern, ref self_binding) = arg_info;
940+ let & ArgInfo {
941+ ty,
942+ span : opt_ty_info,
943+ pattern,
944+ user_pattern : _,
945+ self_kind : ref self_binding
946+ } = arg_info;
921947
922948 // Make sure we drop (parts of) the argument even when not matched on.
923949 self . schedule_drop (
0 commit comments