From 03e8b26f35c737138f75ebd33b44784ea0a8dc9c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 18 Feb 2017 05:23:25 -0500 Subject: [PATCH] rewrite `borrowck_fn` to only use the body-id --- src/librustc_borrowck/borrowck/fragments.rs | 5 ++-- src/librustc_borrowck/borrowck/mod.rs | 31 +++++++++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/librustc_borrowck/borrowck/fragments.rs b/src/librustc_borrowck/borrowck/fragments.rs index dbab3bca52b..c0f681680a9 100644 --- a/src/librustc_borrowck/borrowck/fragments.rs +++ b/src/librustc_borrowck/borrowck/fragments.rs @@ -27,7 +27,7 @@ use rustc::middle::mem_categorization as mc; use std::mem; use std::rc::Rc; use syntax::ast; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::DUMMY_SP; #[derive(PartialEq, Eq, PartialOrd, Ord)] enum Fragment { @@ -200,7 +200,6 @@ impl FragmentSets { pub fn instrument_move_fragments<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>, - sp: Span, id: ast::NodeId) { let span_err = tcx.hir.attrs(id).iter() .any(|a| a.check_name("rustc_move_fragments")); @@ -208,6 +207,8 @@ pub fn instrument_move_fragments<'a, 'tcx>(this: &MoveData<'tcx>, if !span_err && !print { return; } + let sp = tcx.hir.span(id); + let instrument_all_paths = |kind, vec_rc: &Vec| { for (i, mpi) in vec_rc.iter().enumerate() { let lp = || this.path_loan_path(*mpi); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 06133de0757..07e654c3880 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -70,11 +70,13 @@ impl<'a, 'tcx> Visitor<'tcx> for BorrowckCtxt<'a, 'tcx> { match fk { FnKind::ItemFn(..) | FnKind::Method(..) => { - borrowck_fn(self, fk, fd, b, s, id, fk.attrs()) + borrowck_fn(self, b); + intravisit::walk_fn(self, fk, fd, b, s, id); } FnKind::Closure(..) => { - borrowck_fn(self, fk, fd, b, s, id, fk.attrs()); + borrowck_fn(self, b); + intravisit::walk_fn(self, fk, fd, b, s, id); } } } @@ -154,24 +156,20 @@ pub struct AnalysisData<'a, 'tcx: 'a> { pub move_data: move_data::FlowedMoveData<'a, 'tcx>, } -fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, - fk: FnKind<'tcx>, - decl: &'tcx hir::FnDecl, - body_id: hir::BodyId, - sp: Span, - id: ast::NodeId, - attributes: &[ast::Attribute]) { - debug!("borrowck_fn(id={})", id); +fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, body_id: hir::BodyId) { + debug!("borrowck_fn(body_id={:?})", body_id); assert!(this.tables.is_none()); - let owner_def_id = this.tcx.hir.local_def_id(this.tcx.hir.body_owner(body_id)); + let owner_id = this.tcx.hir.body_owner(body_id); + let owner_def_id = this.tcx.hir.local_def_id(owner_id); + let attributes = this.tcx.get_attrs(owner_def_id); let tables = this.tcx.item_tables(owner_def_id); this.tables = Some(tables); let body = this.tcx.hir.body(body_id); - if attributes.iter().any(|item| item.check_name("rustc_mir_borrowck")) { - mir::borrowck_mir(this, id, attributes); + if this.tcx.has_attr(owner_def_id, "rustc_mir_borrowck") { + mir::borrowck_mir(this, owner_id, &attributes); } let cfg = cfg::CFG::new(this.tcx, &body.value); @@ -182,17 +180,14 @@ fn borrowck_fn<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, move_data::fragments::instrument_move_fragments(&flowed_moves.move_data, this.tcx, - sp, - id); + owner_id); move_data::fragments::build_unfragmented_map(this, &flowed_moves.move_data, - id); + owner_id); check_loans::check_loans(this, &loan_dfcx, &flowed_moves, &all_loans[..], body); this.tables = None; - - intravisit::walk_fn(this, fk, decl, body_id, sp, id); } fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,