@@ -70,31 +70,43 @@ impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
70
70
match fk {
71
71
FnKind :: ItemFn ( ..) |
72
72
FnKind :: Method ( ..) => {
73
- borrowck_fn ( self , b) ;
73
+ borrowck_fn ( self . tcx , b) ;
74
74
intravisit:: walk_fn ( self , fk, fd, b, s, id) ;
75
75
}
76
76
77
77
FnKind :: Closure ( ..) => {
78
- borrowck_fn ( self , b) ;
78
+ borrowck_fn ( self . tcx , b) ;
79
79
intravisit:: walk_fn ( self , fk, fd, b, s, id) ;
80
80
}
81
81
}
82
82
}
83
83
84
84
fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
85
- borrowck_item ( self , item) ;
85
+ // Gather loans for items. Note that we don't need
86
+ // to check loans for single expressions. The check
87
+ // loan step is intended for things that have a data
88
+ // flow dependent conditions.
89
+ match item. node {
90
+ hir:: ItemStatic ( .., ex) |
91
+ hir:: ItemConst ( _, ex) => {
92
+ gather_loans:: gather_loans_in_static_initializer ( self . tcx , ex) ;
93
+ }
94
+ _ => { }
95
+ }
96
+
97
+ intravisit:: walk_item ( self , item) ;
86
98
}
87
99
88
100
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem ) {
89
101
if let hir:: TraitItemKind :: Const ( _, Some ( expr) ) = ti. node {
90
- gather_loans:: gather_loans_in_static_initializer ( self , expr) ;
102
+ gather_loans:: gather_loans_in_static_initializer ( self . tcx , expr) ;
91
103
}
92
104
intravisit:: walk_trait_item ( self , ti) ;
93
105
}
94
106
95
107
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem ) {
96
108
if let hir:: ImplItemKind :: Const ( _, expr) = ii. node {
97
- gather_loans:: gather_loans_in_static_initializer ( self , expr) ;
109
+ gather_loans:: gather_loans_in_static_initializer ( self . tcx , expr) ;
98
110
}
99
111
intravisit:: walk_impl_item ( self , ii) ;
100
112
}
@@ -109,61 +121,46 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
109
121
tcx. visit_all_item_likes_in_krate ( DepNode :: BorrowCheck , & mut bccx. as_deep_visitor ( ) ) ;
110
122
}
111
123
112
- fn borrowck_item < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > , item : & ' tcx hir:: Item ) {
113
- // Gather loans for items. Note that we don't need
114
- // to check loans for single expressions. The check
115
- // loan step is intended for things that have a data
116
- // flow dependent conditions.
117
- match item. node {
118
- hir:: ItemStatic ( .., ex) |
119
- hir:: ItemConst ( _, ex) => {
120
- gather_loans:: gather_loans_in_static_initializer ( this, ex) ;
121
- }
122
- _ => { }
123
- }
124
-
125
- intravisit:: walk_item ( this, item) ;
126
- }
127
-
128
124
/// Collection of conclusions determined via borrow checker analyses.
129
125
pub struct AnalysisData < ' a , ' tcx : ' a > {
130
126
pub all_loans : Vec < Loan < ' tcx > > ,
131
127
pub loans : DataFlowContext < ' a , ' tcx , LoanDataFlowOperator > ,
132
128
pub move_data : move_data:: FlowedMoveData < ' a , ' tcx > ,
133
129
}
134
130
135
- fn borrowck_fn < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > , body_id : hir:: BodyId ) {
131
+ fn borrowck_fn < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , body_id : hir:: BodyId ) {
136
132
debug ! ( "borrowck_fn(body_id={:?})" , body_id) ;
137
133
138
- assert ! ( this. tables. is_none( ) ) ;
139
- let owner_id = this. tcx . hir . body_owner ( body_id) ;
140
- let owner_def_id = this. tcx . hir . local_def_id ( owner_id) ;
141
- let attributes = this. tcx . get_attrs ( owner_def_id) ;
142
- let tables = this. tcx . item_tables ( owner_def_id) ;
143
- this. tables = Some ( tables) ;
134
+ let owner_id = tcx. hir . body_owner ( body_id) ;
135
+ let owner_def_id = tcx. hir . local_def_id ( owner_id) ;
136
+ let attributes = tcx. get_attrs ( owner_def_id) ;
137
+ let tables = tcx. item_tables ( owner_def_id) ;
138
+
139
+ let mut bccx = & mut BorrowckCtxt {
140
+ tcx : tcx,
141
+ tables : Some ( tables) ,
142
+ } ;
144
143
145
- let body = this . tcx . hir . body ( body_id) ;
144
+ let body = bccx . tcx . hir . body ( body_id) ;
146
145
147
- if this . tcx . has_attr ( owner_def_id, "rustc_mir_borrowck" ) {
148
- mir:: borrowck_mir ( this , owner_id, & attributes) ;
146
+ if bccx . tcx . has_attr ( owner_def_id, "rustc_mir_borrowck" ) {
147
+ mir:: borrowck_mir ( bccx , owner_id, & attributes) ;
149
148
}
150
149
151
- let cfg = cfg:: CFG :: new ( this . tcx , & body. value ) ;
150
+ let cfg = cfg:: CFG :: new ( bccx . tcx , & body. value ) ;
152
151
let AnalysisData { all_loans,
153
152
loans : loan_dfcx,
154
153
move_data : flowed_moves } =
155
- build_borrowck_dataflow_data ( this , & cfg, body_id) ;
154
+ build_borrowck_dataflow_data ( bccx , & cfg, body_id) ;
156
155
157
156
move_data:: fragments:: instrument_move_fragments ( & flowed_moves. move_data ,
158
- this . tcx ,
157
+ bccx . tcx ,
159
158
owner_id) ;
160
- move_data:: fragments:: build_unfragmented_map ( this ,
159
+ move_data:: fragments:: build_unfragmented_map ( bccx ,
161
160
& flowed_moves. move_data ,
162
161
owner_id) ;
163
162
164
- check_loans:: check_loans ( this, & loan_dfcx, & flowed_moves, & all_loans[ ..] , body) ;
165
-
166
- this. tables = None ;
163
+ check_loans:: check_loans ( bccx, & loan_dfcx, & flowed_moves, & all_loans[ ..] , body) ;
167
164
}
168
165
169
166
fn build_borrowck_dataflow_data < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > ,
0 commit comments