Skip to content

Commit cde3c15

Browse files
committed
use visit_all_bodies_in_krate for borrowck instead of item-likes
1 parent 9334c39 commit cde3c15

File tree

2 files changed

+10
-59
lines changed

2 files changed

+10
-59
lines changed

src/librustc/dep_graph/dep_node.rs

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub enum DepNode<D: Clone + Debug> {
9090
// things read/modify that MIR.
9191
Mir(D),
9292

93+
BorrowCheckKrate,
9394
BorrowCheck(D),
9495
RvalueCheck(D),
9596
Reachability,
@@ -176,6 +177,7 @@ impl<D: Clone + Debug> DepNode<D> {
176177

177178
match *self {
178179
Krate => Some(Krate),
180+
BorrowCheckKrate => Some(BorrowCheckKrate),
179181
CollectLanguageItems => Some(CollectLanguageItems),
180182
CheckStaticRecursion => Some(CheckStaticRecursion),
181183
ResolveLifetimes => Some(ResolveLifetimes),

src/librustc_borrowck/borrowck/mod.rs

+8-59
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use syntax_pos::{MultiSpan, Span};
4545
use errors::DiagnosticBuilder;
4646

4747
use rustc::hir;
48-
use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
48+
use rustc::hir::intravisit::{self, Visitor};
4949

5050
pub mod check_loans;
5151

@@ -60,65 +60,14 @@ pub struct LoanDataFlowOperator;
6060

6161
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
6262

63-
impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> {
64-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
65-
NestedVisitorMap::OnlyBodies(&self.tcx.hir)
66-
}
67-
68-
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
69-
b: hir::BodyId, s: Span, id: ast::NodeId) {
70-
match fk {
71-
FnKind::ItemFn(..) |
72-
FnKind::Method(..) => {
73-
borrowck_fn(self.tcx, b);
74-
intravisit::walk_fn(self, fk, fd, b, s, id);
75-
}
76-
77-
FnKind::Closure(..) => {
78-
borrowck_fn(self.tcx, b);
79-
intravisit::walk_fn(self, fk, fd, b, s, id);
80-
}
81-
}
82-
}
83-
84-
fn visit_item(&mut self, item: &'tcx hir::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-
borrowck_fn(self.tcx, ex);
93-
}
94-
_ => { }
95-
}
96-
97-
intravisit::walk_item(self, item);
98-
}
99-
100-
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
101-
if let hir::TraitItemKind::Const(_, Some(expr)) = ti.node {
102-
borrowck_fn(self.tcx, expr);
103-
}
104-
intravisit::walk_trait_item(self, ti);
105-
}
106-
107-
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
108-
if let hir::ImplItemKind::Const(_, expr) = ii.node {
109-
borrowck_fn(self.tcx, expr);
110-
}
111-
intravisit::walk_impl_item(self, ii);
112-
}
113-
}
114-
11563
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
116-
let mut bccx = BorrowckCtxt {
117-
tcx: tcx,
118-
tables: None,
119-
};
120-
121-
tcx.visit_all_item_likes_in_krate(DepNode::BorrowCheck, &mut bccx.as_deep_visitor());
64+
tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, || {
65+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| {
66+
tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id), || {
67+
borrowck_fn(tcx, body_id);
68+
});
69+
});
70+
});
12271
}
12372

12473
/// Collection of conclusions determined via borrow checker analyses.

0 commit comments

Comments
 (0)