@@ -70,11 +70,11 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
7070 // HACK(eddyb) Avoid having RustCall on closures,
7171 // as it adds unnecessary (and wrong) auto-tupling.
7272 abi = Abi :: Rust ;
73- Some ( ArgInfo ( liberated_closure_env_ty ( tcx, id, body_id) , None ) )
73+ Some ( ArgInfo ( liberated_closure_env_ty ( tcx, id, body_id) , None , None , None ) )
7474 }
7575 ty:: TyGenerator ( ..) => {
7676 let gen_ty = tcx. body_tables ( body_id) . node_id_to_type ( fn_hir_id) ;
77- Some ( ArgInfo ( gen_ty, None ) )
77+ Some ( ArgInfo ( gen_ty, None , None , None ) )
7878 }
7979 _ => None ,
8080 } ;
@@ -91,7 +91,23 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
9191 . iter ( )
9292 . enumerate ( )
9393 . map ( |( index, arg) | {
94- ArgInfo ( fn_sig. inputs ( ) [ index] , Some ( & * arg. pat ) )
94+ let owner_id = tcx. hir . body_owner ( body_id) ;
95+ let opt_ty_info;
96+ let self_arg;
97+ if let Some ( ref fn_decl) = tcx. hir . fn_decl ( owner_id) {
98+ let ty_hir_id = fn_decl. inputs [ index] . hir_id ;
99+ let ty_span = tcx. hir . span ( tcx. hir . hir_to_node_id ( ty_hir_id) ) ;
100+ opt_ty_info = Some ( ty_span) ;
101+ self_arg = if index == 0 && fn_decl. has_implicit_self {
102+ Some ( ImplicitSelfBinding )
103+ } else {
104+ None
105+ } ;
106+ } else {
107+ opt_ty_info = None ;
108+ self_arg = None ;
109+ }
110+ ArgInfo ( fn_sig. inputs ( ) [ index] , opt_ty_info, Some ( & * arg. pat ) , self_arg)
95111 } ) ;
96112
97113 let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
@@ -433,7 +449,12 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
433449///////////////////////////////////////////////////////////////////////////
434450/// the main entry point for building MIR for a function
435451
436- struct ArgInfo < ' gcx > ( Ty < ' gcx > , Option < & ' gcx hir:: Pat > ) ;
452+ struct ImplicitSelfBinding ;
453+
454+ struct ArgInfo < ' gcx > ( Ty < ' gcx > ,
455+ Option < Span > ,
456+ Option < & ' gcx hir:: Pat > ,
457+ Option < ImplicitSelfBinding > ) ;
437458
438459fn construct_fn < ' a , ' gcx , ' tcx , A > ( hir : Cx < ' a , ' gcx , ' tcx > ,
439460 fn_id : ast:: NodeId ,
@@ -650,7 +671,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
650671 -> BlockAnd < ( ) >
651672 {
652673 // Allocate locals for the function arguments
653- for & ArgInfo ( ty, pattern) in arguments. iter ( ) {
674+ for & ArgInfo ( ty, _ , pattern, _ ) in arguments. iter ( ) {
654675 // If this is a simple binding pattern, give the local a nice name for debuginfo.
655676 let mut name = None ;
656677 if let Some ( pat) = pattern {
@@ -676,10 +697,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
676697
677698 let mut scope = None ;
678699 // Bind the argument patterns
679- for ( index, & ArgInfo ( ty , pattern ) ) in arguments. iter ( ) . enumerate ( ) {
700+ for ( index, arg_info ) in arguments. iter ( ) . enumerate ( ) {
680701 // Function arguments always get the first Local indices after the return place
681702 let local = Local :: new ( index + 1 ) ;
682703 let place = Place :: Local ( local) ;
704+ let & ArgInfo ( ty, opt_ty_info, pattern, ref self_binding) = arg_info;
683705
684706 if let Some ( pattern) = pattern {
685707 let pattern = self . hir . pattern_from_hir ( pattern) ;
@@ -688,6 +710,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
688710 // Don't introduce extra copies for simple bindings
689711 PatternKind :: Binding { mutability, var, mode : BindingMode :: ByValue , .. } => {
690712 self . local_decls [ local] . mutability = mutability;
713+ self . local_decls [ local] . is_user_variable =
714+ if let Some ( ImplicitSelfBinding ) = self_binding {
715+ Some ( ClearCrossCrate :: Set ( BindingForm :: ImplicitSelf ) )
716+ } else {
717+ let binding_mode = ty:: BindingMode :: BindByValue ( mutability. into ( ) ) ;
718+ Some ( ClearCrossCrate :: Set ( BindingForm :: Var ( VarBindingForm {
719+ binding_mode, opt_ty_info } ) ) )
720+ } ;
691721 self . var_indices . insert ( var, LocalsForNode :: One ( local) ) ;
692722 }
693723 _ => {
0 commit comments