Skip to content

Commit 8c8257a

Browse files
committed
rustc_borrowck: fix compilation
1 parent 8f6bb85 commit 8c8257a

File tree

1 file changed

+31
-23
lines changed
  • src/librustc_borrowck/borrowck

1 file changed

+31
-23
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax_pos::{MultiSpan, Span};
4747
use errors::DiagnosticBuilder;
4848

4949
use rustc::hir;
50-
use rustc::hir::intravisit::{self, Visitor, FnKind};
50+
use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitMode};
5151

5252
pub mod check_loans;
5353

@@ -62,9 +62,13 @@ pub struct LoanDataFlowOperator;
6262

6363
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
6464

65-
impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {
66-
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v hir::FnDecl,
67-
b: &'v hir::Expr, s: Span, id: ast::NodeId) {
65+
impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
66+
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
67+
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
68+
}
69+
70+
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
71+
b: hir::ExprId, s: Span, id: ast::NodeId) {
6872
match fk {
6973
FnKind::ItemFn(..) |
7074
FnKind::Method(..) => {
@@ -79,18 +83,18 @@ impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {
7983
}
8084
}
8185

82-
fn visit_item(&mut self, item: &hir::Item) {
86+
fn visit_item(&mut self, item: &'tcx hir::Item) {
8387
borrowck_item(self, item);
8488
}
8589

86-
fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
90+
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
8791
if let hir::ConstTraitItem(_, Some(ref expr)) = ti.node {
8892
gather_loans::gather_loans_in_static_initializer(self, ti.id, &expr);
8993
}
9094
intravisit::walk_trait_item(self, ti);
9195
}
9296

93-
fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
97+
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
9498
if let hir::ImplItemKind::Const(_, ref expr) = ii.node {
9599
gather_loans::gather_loans_in_static_initializer(self, ii.id, &expr);
96100
}
@@ -131,7 +135,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
131135
}
132136
}
133137

134-
fn borrowck_item(this: &mut BorrowckCtxt, item: &hir::Item) {
138+
fn borrowck_item<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, item: &'tcx hir::Item) {
135139
// Gather loans for items. Note that we don't need
136140
// to check loans for single expressions. The check
137141
// loan step is intended for things that have a data
@@ -154,15 +158,17 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
154158
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
155159
}
156160

157-
fn borrowck_fn(this: &mut BorrowckCtxt,
158-
fk: FnKind,
159-
decl: &hir::FnDecl,
160-
body: &hir::Expr,
161-
sp: Span,
162-
id: ast::NodeId,
163-
attributes: &[ast::Attribute]) {
161+
fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
162+
fk: FnKind<'tcx>,
163+
decl: &'tcx hir::FnDecl,
164+
body_id: hir::ExprId,
165+
sp: Span,
166+
id: ast::NodeId,
167+
attributes: &[ast::Attribute]) {
164168
debug!("borrowck_fn(id={})", id);
165169

170+
let body = this.tcx.map.expr(body_id);
171+
166172
if attributes.iter().any(|item| item.check_name("rustc_mir_borrowck")) {
167173
this.with_temp_region_map(id, |this| {
168174
mir::borrowck_mir(this, fk, decl, body, sp, id, attributes)
@@ -191,14 +197,14 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
191197
decl,
192198
body);
193199

194-
intravisit::walk_fn(this, fk, decl, body, sp, id);
200+
intravisit::walk_fn(this, fk, decl, body_id, sp, id);
195201
}
196202

197203
fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
198-
fk: FnKind,
199-
decl: &hir::FnDecl,
204+
fk: FnKind<'tcx>,
205+
decl: &'tcx hir::FnDecl,
200206
cfg: &cfg::CFG,
201-
body: &hir::Expr,
207+
body: &'tcx hir::Expr,
202208
sp: Span,
203209
id: ast::NodeId)
204210
-> AnalysisData<'a, 'tcx>
@@ -241,7 +247,7 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
241247
/// the `BorrowckCtxt` itself , e.g. the flowgraph visualizer.
242248
pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
243249
tcx: TyCtxt<'a, 'tcx, 'tcx>,
244-
fn_parts: FnParts<'a>,
250+
fn_parts: FnParts<'tcx>,
245251
cfg: &cfg::CFG)
246252
-> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'a, 'tcx>)
247253
{
@@ -257,11 +263,13 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
257263
}
258264
};
259265

266+
let body = tcx.map.expr(fn_parts.body);
267+
260268
let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
261269
fn_parts.kind,
262270
&fn_parts.decl,
263271
cfg,
264-
&fn_parts.body,
272+
body,
265273
fn_parts.span,
266274
fn_parts.id);
267275

@@ -407,8 +415,8 @@ pub fn closure_to_block(closure_id: ast::NodeId,
407415
tcx: TyCtxt) -> ast::NodeId {
408416
match tcx.map.get(closure_id) {
409417
hir_map::NodeExpr(expr) => match expr.node {
410-
hir::ExprClosure(.., ref block, _) => {
411-
block.id
418+
hir::ExprClosure(.., body_id, _) => {
419+
body_id.node_id()
412420
}
413421
_ => {
414422
bug!("encountered non-closure id: {}", closure_id)

0 commit comments

Comments
 (0)