From: Niko Matsakis Date: Wed, 23 Mar 2016 08:59:44 +0000 (-0400) Subject: Address nit: Remove `ScopedDataVec` newtype X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=70d0123082913e244739d64692eec7063b9c79c5;p=rust.git Address nit: Remove `ScopedDataVec` newtype --- diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 2931af2936f..4022d762aec 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 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { /////////////////////////////////////////////////////////////////////////// // 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 58b2b92b796..056d74ffe1f 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 baacc8ca9a9..54830e6c225 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -98,7 +98,7 @@ 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 @@ pub fn in_scope(&mut self, extent: CodeExtent, mut block: BasicBlock, f: F 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 d8cfd8a88cf..05fe255c641 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 0fb4975453a..7abaeb44c1c 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -569,4 +569,3 @@ pub fn llblock(&self, bb: mir::BasicBlock) -> BasicBlockRef { self.blocks[bb.index()].llbb } } -