diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-02-18 07:07:02 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-02-28 08:43:47 -0500 |
| commit | cc2e4cd7e33d195a8ba8ea334d4baa291a438a56 (patch) | |
| tree | d338d01d27ee7bbd9e359a121de902d9583f5815 /src | |
| parent | 085d71c3efe453863739c1fb68fd9bd1beff214f (diff) | |
| download | rust-cc2e4cd7e33d195a8ba8ea334d4baa291a438a56.tar.gz rust-cc2e4cd7e33d195a8ba8ea334d4baa291a438a56.zip | |
use `visit_all_bodies_in_krate` for borrowck instead of item-likes
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | src/librustc_borrowck/borrowck/mod.rs | 67 |
2 files changed, 10 insertions, 59 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index e0233d6f8b9..bb8f4b75282 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -91,6 +91,7 @@ pub enum DepNode<D: Clone + Debug> { // things read/modify that MIR. Mir(D), + BorrowCheckKrate, BorrowCheck(D), RvalueCheck(D), Reachability, @@ -209,6 +210,7 @@ impl<D: Clone + Debug> DepNode<D> { match *self { Krate => Some(Krate), + BorrowCheckKrate => Some(BorrowCheckKrate), CollectLanguageItems => Some(CollectLanguageItems), CheckStaticRecursion => Some(CheckStaticRecursion), ResolveLifetimes => Some(ResolveLifetimes), diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 613f28138a5..f0381dd1b70 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -45,7 +45,7 @@ use syntax_pos::{MultiSpan, Span}; use errors::DiagnosticBuilder; use rustc::hir; -use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap}; +use rustc::hir::intravisit::{self, Visitor}; pub mod check_loans; @@ -60,65 +60,14 @@ pub struct LoanDataFlowOperator; pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>; -impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { - NestedVisitorMap::OnlyBodies(&self.tcx.hir) - } - - fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl, - b: hir::BodyId, s: Span, id: ast::NodeId) { - match fk { - FnKind::ItemFn(..) | - FnKind::Method(..) => { - borrowck_fn(self.tcx, b); - intravisit::walk_fn(self, fk, fd, b, s, id); - } - - FnKind::Closure(..) => { - borrowck_fn(self.tcx, b); - intravisit::walk_fn(self, fk, fd, b, s, id); - } - } - } - - fn visit_item(&mut self, item: &'tcx hir::Item) { - // Gather loans for items. Note that we don't need - // to check loans for single expressions. The check - // loan step is intended for things that have a data - // flow dependent conditions. - match item.node { - hir::ItemStatic(.., ex) | - hir::ItemConst(_, ex) => { - borrowck_fn(self.tcx, ex); - } - _ => { } - } - - intravisit::walk_item(self, item); - } - - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { - if let hir::TraitItemKind::Const(_, Some(expr)) = ti.node { - borrowck_fn(self.tcx, expr); - } - intravisit::walk_trait_item(self, ti); - } - - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { - if let hir::ImplItemKind::Const(_, expr) = ii.node { - borrowck_fn(self.tcx, expr); - } - intravisit::walk_impl_item(self, ii); - } -} - pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - let mut bccx = BorrowckCtxt { - tcx: tcx, - tables: None, - }; - - tcx.visit_all_item_likes_in_krate(DepNode::BorrowCheck, &mut bccx.as_deep_visitor()); + tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, || { + tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| { + tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id), || { + borrowck_fn(tcx, body_id); + }); + }); + }); } /// Collection of conclusions determined via borrow checker analyses. |
