@@ -70,11 +70,11 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
70
70
// HACK(eddyb) Avoid having RustCall on closures,
71
71
// as it adds unnecessary (and wrong) auto-tupling.
72
72
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 ) )
74
74
}
75
75
ty:: TyGenerator ( ..) => {
76
76
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 ) )
78
78
}
79
79
_ => None ,
80
80
} ;
@@ -91,7 +91,23 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
91
91
. iter ( )
92
92
. enumerate ( )
93
93
. 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)
95
111
} ) ;
96
112
97
113
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>,
433
449
///////////////////////////////////////////////////////////////////////////
434
450
/// the main entry point for building MIR for a function
435
451
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 > ) ;
437
458
438
459
fn construct_fn < ' a , ' gcx , ' tcx , A > ( hir : Cx < ' a , ' gcx , ' tcx > ,
439
460
fn_id : ast:: NodeId ,
@@ -650,7 +671,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
650
671
-> BlockAnd < ( ) >
651
672
{
652
673
// Allocate locals for the function arguments
653
- for & ArgInfo ( ty, pattern) in arguments. iter ( ) {
674
+ for & ArgInfo ( ty, _ , pattern, _ ) in arguments. iter ( ) {
654
675
// If this is a simple binding pattern, give the local a nice name for debuginfo.
655
676
let mut name = None ;
656
677
if let Some ( pat) = pattern {
@@ -676,10 +697,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
676
697
677
698
let mut scope = None ;
678
699
// Bind the argument patterns
679
- for ( index, & ArgInfo ( ty , pattern ) ) in arguments. iter ( ) . enumerate ( ) {
700
+ for ( index, arg_info ) in arguments. iter ( ) . enumerate ( ) {
680
701
// Function arguments always get the first Local indices after the return place
681
702
let local = Local :: new ( index + 1 ) ;
682
703
let place = Place :: Local ( local) ;
704
+ let & ArgInfo ( ty, opt_ty_info, pattern, ref self_binding) = arg_info;
683
705
684
706
if let Some ( pattern) = pattern {
685
707
let pattern = self . hir . pattern_from_hir ( pattern) ;
@@ -688,6 +710,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
688
710
// Don't introduce extra copies for simple bindings
689
711
PatternKind :: Binding { mutability, var, mode : BindingMode :: ByValue , .. } => {
690
712
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
+ } ;
691
721
self . var_indices . insert ( var, LocalsForNode :: One ( local) ) ;
692
722
}
693
723
_ => {
0 commit comments