Skip to content

Commit b347a23

Browse files
committed
make borrowck_fn and friends create bccx
1 parent 5f5946a commit b347a23

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,15 @@ impl<'a, 'tcx> Visitor<'tcx> for StaticInitializerCtxt<'a, 'tcx> {
547547
}
548548
}
549549

550-
pub fn gather_loans_in_static_initializer(bccx: &mut BorrowckCtxt, body: hir::BodyId) {
550+
pub fn gather_loans_in_static_initializer<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
551+
body: hir::BodyId) {
551552
debug!("gather_loans_in_static_initializer(expr={:?})", body);
552553

554+
let bccx = &BorrowckCtxt {
555+
tcx: tcx,
556+
tables: None
557+
};
558+
553559
let mut sicx = StaticInitializerCtxt {
554560
bccx: bccx,
555561
body_id: body

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,43 @@ impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
7070
match fk {
7171
FnKind::ItemFn(..) |
7272
FnKind::Method(..) => {
73-
borrowck_fn(self, b);
73+
borrowck_fn(self.tcx, b);
7474
intravisit::walk_fn(self, fk, fd, b, s, id);
7575
}
7676

7777
FnKind::Closure(..) => {
78-
borrowck_fn(self, b);
78+
borrowck_fn(self.tcx, b);
7979
intravisit::walk_fn(self, fk, fd, b, s, id);
8080
}
8181
}
8282
}
8383

8484
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);
8698
}
8799

88100
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
89101
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);
91103
}
92104
intravisit::walk_trait_item(self, ti);
93105
}
94106

95107
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
96108
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);
98110
}
99111
intravisit::walk_impl_item(self, ii);
100112
}
@@ -109,61 +121,46 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
109121
tcx.visit_all_item_likes_in_krate(DepNode::BorrowCheck, &mut bccx.as_deep_visitor());
110122
}
111123

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-
128124
/// Collection of conclusions determined via borrow checker analyses.
129125
pub struct AnalysisData<'a, 'tcx: 'a> {
130126
pub all_loans: Vec<Loan<'tcx>>,
131127
pub loans: DataFlowContext<'a, 'tcx, LoanDataFlowOperator>,
132128
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
133129
}
134130

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) {
136132
debug!("borrowck_fn(body_id={:?})", body_id);
137133

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+
};
144143

145-
let body = this.tcx.hir.body(body_id);
144+
let body = bccx.tcx.hir.body(body_id);
146145

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);
149148
}
150149

151-
let cfg = cfg::CFG::new(this.tcx, &body.value);
150+
let cfg = cfg::CFG::new(bccx.tcx, &body.value);
152151
let AnalysisData { all_loans,
153152
loans: loan_dfcx,
154153
move_data: flowed_moves } =
155-
build_borrowck_dataflow_data(this, &cfg, body_id);
154+
build_borrowck_dataflow_data(bccx, &cfg, body_id);
156155

157156
move_data::fragments::instrument_move_fragments(&flowed_moves.move_data,
158-
this.tcx,
157+
bccx.tcx,
159158
owner_id);
160-
move_data::fragments::build_unfragmented_map(this,
159+
move_data::fragments::build_unfragmented_map(bccx,
161160
&flowed_moves.move_data,
162161
owner_id);
163162

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);
167164
}
168165

169166
fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,

0 commit comments

Comments
 (0)