From 70d0123082913e244739d64692eec7063b9c79c5 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 23 Mar 2016 04:59:44 -0400 Subject: [PATCH] Address nit: Remove `ScopedDataVec` newtype --- src/librustc/mir/repr.rs | 21 +++++---------------- src/librustc_mir/build/mod.rs | 6 +++--- src/librustc_mir/build/scope.rs | 6 +++--- src/librustc_mir/pretty.rs | 2 +- src/librustc_trans/trans/mir/block.rs | 1 - 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 2931af2936f5..4022d762aec3 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -34,7 +34,7 @@ pub struct Mir<'tcx> { /// List of lexical scopes; these are referenced by statements and /// used (eventually) for debuginfo. Indexed by a `ScopeId`. - pub scopes: ScopeDataVec, + pub scopes: Vec, /// Return type of the function. pub return_ty: FnOutput<'tcx>, @@ -651,30 +651,19 @@ impl<'tcx> Debug for Lvalue<'tcx> { /////////////////////////////////////////////////////////////////////////// // Scopes -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] -pub struct ScopeDataVec { - pub vec: Vec -} - -impl ScopeDataVec { - pub fn new() -> Self { - ScopeDataVec { vec: Vec::new() } - } -} - -impl Index for ScopeDataVec { +impl Index for Vec { type Output = ScopeData; #[inline] fn index(&self, index: ScopeId) -> &ScopeData { - &self.vec[index.index()] + &self[index.index()] } } -impl IndexMut for ScopeDataVec { +impl IndexMut for Vec { #[inline] fn index_mut(&mut self, index: ScopeId) -> &mut ScopeData { - &mut self.vec[index.index()] + &mut self[index.index()] } } diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 58b2b92b7960..056d74ffe1f1 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -41,7 +41,7 @@ pub struct Builder<'a, 'tcx: 'a> { // the vector of all scopes that we have created thus far; // we track this for debuginfo later - scope_data_vec: ScopeDataVec, + scope_datas: Vec, var_decls: Vec>, var_indices: FnvHashMap, @@ -151,7 +151,7 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>, cfg: cfg, fn_span: span, scopes: vec![], - scope_data_vec: ScopeDataVec::new(), + scope_datas: vec![], scope_auxiliary: vec![], loop_scopes: vec![], temp_decls: vec![], @@ -191,7 +191,7 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>, MirAndScopeAuxiliary { mir: Mir { basic_blocks: builder.cfg.basic_blocks, - scopes: builder.scope_data_vec, + scopes: builder.scope_datas, var_decls: builder.var_decls, arg_decls: arg_decls, temp_decls: builder.temp_decls, diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index baacc8ca9a9a..54830e6c2257 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -98,7 +98,7 @@ use rustc::middle::const_eval::ConstVal; use rustc_const_eval::ConstInt; pub struct Scope<'tcx> { - /// the scope-id within the scope_data_vec + /// the scope-id within the scope_datas id: ScopeId, extent: CodeExtent, drops: Vec>, @@ -246,8 +246,8 @@ impl<'a,'tcx> Builder<'a,'tcx> { pub fn push_scope(&mut self, extent: CodeExtent, entry: BasicBlock) -> ScopeId { debug!("push_scope({:?})", extent); let parent_id = self.scopes.last().map(|s| s.id); - let id = ScopeId::new(self.scope_data_vec.vec.len()); - self.scope_data_vec.vec.push(ScopeData { + let id = ScopeId::new(self.scope_datas.len()); + self.scope_datas.push(ScopeData { parent_scope: parent_id, }); self.scopes.push(Scope { diff --git a/src/librustc_mir/pretty.rs b/src/librustc_mir/pretty.rs index d8cfd8a88cf9..05fe255c6414 100644 --- a/src/librustc_mir/pretty.rs +++ b/src/librustc_mir/pretty.rs @@ -118,7 +118,7 @@ pub fn write_mir_fn<'tcx>(tcx: &TyCtxt<'tcx>, // construct a scope tree and write it out let mut scope_tree: FnvHashMap, Vec> = FnvHashMap(); - for (index, scope_data) in mir.scopes.vec.iter().enumerate() { + for (index, scope_data) in mir.scopes.iter().enumerate() { scope_tree.entry(scope_data.parent_scope) .or_insert(vec![]) .push(ScopeId::new(index)); diff --git a/src/librustc_trans/trans/mir/block.rs b/src/librustc_trans/trans/mir/block.rs index 0fb4975453a2..7abaeb44c1c2 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -569,4 +569,3 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { self.blocks[bb.index()].llbb } } -