From 8f2a7316e66ca3c53fb83428f317b1525855ebf8 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 4 Mar 2014 12:16:03 +1100 Subject: [PATCH] syntax: replace OptVec with plain Vec. The new vector representation has no allocations when empty, so OptVec is now useless overhead. --- src/librustc/front/std_inject.rs | 9 +- src/librustc/front/test.rs | 9 +- src/librustc/metadata/tydecode.rs | 4 +- src/librustc/middle/borrowck/move_data.rs | 9 +- src/librustc/middle/cfg/construct.rs | 7 +- src/librustc/middle/cfg/mod.rs | 5 +- src/librustc/middle/kind.rs | 5 +- src/librustc/middle/privacy.rs | 6 +- src/librustc/middle/resolve.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 11 +- src/librustc/middle/subst.rs | 6 +- src/librustc/middle/trans/cleanup.rs | 18 +- src/librustc/middle/trans/debuginfo.rs | 5 +- src/librustc/middle/trans/type_of.rs | 4 +- src/librustc/middle/ty.rs | 13 +- src/librustc/middle/typeck/astconv.rs | 10 +- src/librustc/middle/typeck/check/mod.rs | 22 +- src/librustc/middle/typeck/coherence.rs | 4 +- src/librustc/middle/typeck/collect.rs | 10 +- src/librustc/middle/typeck/infer/combine.rs | 5 +- .../middle/typeck/infer/error_reporting.rs | 8 +- .../typeck/infer/region_inference/mod.rs | 17 +- src/librustc/middle/typeck/rscope.rs | 4 +- src/librustc/middle/typeck/variance.rs | 10 +- src/librustc/util/ppaux.rs | 11 +- src/librustdoc/clean.rs | 9 - src/libsyntax/ast.rs | 19 +- src/libsyntax/ast_util.rs | 14 +- src/libsyntax/ext/build.rs | 44 ++-- src/libsyntax/ext/concat_idents.rs | 7 +- src/libsyntax/ext/deriving/generic.rs | 9 +- src/libsyntax/ext/deriving/rand.rs | 3 +- src/libsyntax/ext/deriving/ty.rs | 19 +- src/libsyntax/ext/env.rs | 4 +- src/libsyntax/ext/format.rs | 6 +- src/libsyntax/fold.rs | 14 +- src/libsyntax/lib.rs | 1 - src/libsyntax/opt_vec.rs | 218 ------------------ src/libsyntax/parse/mod.rs | 41 ++-- src/libsyntax/parse/parser.rs | 56 +++-- src/libsyntax/print/pprust.rs | 16 +- src/libsyntax/visit.rs | 12 +- 42 files changed, 226 insertions(+), 482 deletions(-) delete mode 100644 src/libsyntax/opt_vec.rs diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs index eec44cc31b1a3..5b2093d07dcf3 100644 --- a/src/librustc/front/std_inject.rs +++ b/src/librustc/front/std_inject.rs @@ -19,7 +19,6 @@ use syntax::codemap::DUMMY_SP; use syntax::codemap; use syntax::fold::Folder; use syntax::fold; -use syntax::opt_vec; use syntax::parse::token::InternedString; use syntax::parse::token; use syntax::util::small_vector::SmallVector; @@ -164,13 +163,13 @@ impl fold::Folder for PreludeInjector { segments: vec!( ast::PathSegment { identifier: token::str_to_ident("std"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }, ast::PathSegment { identifier: token::str_to_ident("prelude"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }), }; diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 333504b7e8247..690b5f26dfc47 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -30,7 +30,6 @@ use syntax::codemap; use syntax::ext::base::ExtCtxt; use syntax::fold::Folder; use syntax::fold; -use syntax::opt_vec; use syntax::parse::token::InternedString; use syntax::parse::token; use syntax::print::pprust; @@ -370,8 +369,8 @@ fn path_node(ids: ~[ast::Ident]) -> ast::Path { global: false, segments: ids.move_iter().map(|identifier| ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }).collect() } } @@ -382,8 +381,8 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path { global: true, segments: ids.move_iter().map(|identifier| ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }).collect() } } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index f566571d0eb3c..932326d3cbd8f 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -20,11 +20,11 @@ use middle::ty; use std::str; use std::uint; +use std::vec_ng::Vec; use syntax::abi::AbiSet; use syntax::abi; use syntax::ast; use syntax::ast::*; -use syntax::opt_vec; use syntax::parse::token; // Compact string representation for ty::t values. API ty_str & @@ -192,7 +192,7 @@ fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts { match next(st) { 'e' => ty::ErasedRegions, 'n' => { - let mut regions = opt_vec::Empty; + let mut regions = Vec::new(); while peek(st) != '.' { let r = parse_region(st, |x,y| conv(x,y)); regions.push(r); diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 35368645eb328..036c2df8d855b 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -17,6 +17,7 @@ comments in the section "Moves and initialization" and in `doc.rs`. use std::cell::RefCell; use std::uint; +use std::vec_ng::Vec; use collections::{HashMap, HashSet}; use middle::borrowck::*; use middle::dataflow::DataFlowContext; @@ -26,8 +27,6 @@ use middle::typeck; use syntax::ast; use syntax::ast_util; use syntax::codemap::Span; -use syntax::opt_vec::OptVec; -use syntax::opt_vec; use util::ppaux::Repr; pub struct MoveData { @@ -314,15 +313,15 @@ impl MoveData { fn existing_base_paths(&self, lp: @LoanPath) - -> OptVec { - let mut result = opt_vec::Empty; + -> Vec { + let mut result = Vec::new(); self.add_existing_base_paths(lp, &mut result); result } fn add_existing_base_paths(&self, lp: @LoanPath, - result: &mut OptVec) { + result: &mut Vec) { /*! * Adds any existing move path indices for `lp` and any base * paths of `lp` to `result`, but does not add new move paths diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index b76d4cb858903..9fe92d0349a6f 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -15,7 +15,8 @@ use middle::ty; use collections::HashMap; use syntax::ast; use syntax::ast_util; -use syntax::opt_vec; + +use std::vec_ng::Vec; struct CFGBuilder { tcx: ty::ctxt, @@ -471,7 +472,7 @@ impl CFGBuilder { fn add_contained_edge(&mut self, source: CFGIndex, target: CFGIndex) { - let data = CFGEdgeData {exiting_scopes: opt_vec::Empty}; + let data = CFGEdgeData {exiting_scopes: Vec::new()}; self.graph.add_edge(source, target, data); } @@ -480,7 +481,7 @@ impl CFGBuilder { from_index: CFGIndex, to_loop: LoopScope, to_index: CFGIndex) { - let mut data = CFGEdgeData {exiting_scopes: opt_vec::Empty}; + let mut data = CFGEdgeData {exiting_scopes: Vec::new()}; let mut scope_id = from_expr.id; while scope_id != to_loop.loop_id { data.exiting_scopes.push(scope_id); diff --git a/src/librustc/middle/cfg/mod.rs b/src/librustc/middle/cfg/mod.rs index d6d54b604c8c5..80b7d8a0db3f5 100644 --- a/src/librustc/middle/cfg/mod.rs +++ b/src/librustc/middle/cfg/mod.rs @@ -20,7 +20,8 @@ use middle::ty; use middle::typeck; use collections::HashMap; use syntax::ast; -use syntax::opt_vec::OptVec; + +use std::vec_ng::Vec; mod construct; @@ -36,7 +37,7 @@ pub struct CFGNodeData { } pub struct CFGEdgeData { - exiting_scopes: OptVec + exiting_scopes: Vec } pub type CFGIndex = graph::NodeIndex; diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 5b7ac704e2a22..c884b1b876c5e 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -19,7 +19,6 @@ use util::ppaux::UserString; use syntax::ast::*; use syntax::attr; use syntax::codemap::Span; -use syntax::opt_vec; use syntax::print::pprust::expr_to_str; use syntax::{visit,ast_util}; use syntax::visit::Visitor; @@ -50,6 +49,8 @@ use syntax::visit::Visitor; // primitives in the stdlib are explicitly annotated to only take sendable // types. +use std::vec_ng::Vec; + #[deriving(Clone)] pub struct Context { tcx: ty::ctxt, @@ -92,7 +93,7 @@ fn check_struct_safe_for_destructor(cx: &mut Context, let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did); if !struct_tpt.generics.has_type_params() { let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs { - regions: ty::NonerasedRegions(opt_vec::Empty), + regions: ty::NonerasedRegions(Vec::new()), self_ty: None, tps: ~[] }); diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 3d90566ee7931..1054b07193eb7 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -13,6 +13,7 @@ //! which are available for use externally when compiled as a library. use std::mem::replace; +use std::vec_ng::Vec; use collections::{HashSet, HashMap}; use metadata::csearch; @@ -28,7 +29,6 @@ use syntax::ast_util::{is_local, def_id_of_def, local_def}; use syntax::attr; use syntax::codemap::Span; use syntax::parse::token; -use syntax::opt_vec; use syntax::visit; use syntax::visit::Visitor; @@ -855,8 +855,8 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { debug!("privacy - list {}", pid.node.id); let seg = ast::PathSegment { identifier: pid.node.name, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }; let segs = vec!(seg); let path = ast::Path { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 58de36a796825..1e12bbfe27eff 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -25,12 +25,12 @@ use syntax::parse::token::special_idents; use syntax::parse::token; use syntax::print::pprust::path_to_str; use syntax::codemap::{Span, DUMMY_SP, Pos}; -use syntax::opt_vec::OptVec; use syntax::visit; use syntax::visit::Visitor; use std::cell::{Cell, RefCell}; use std::uint; +use std::vec_ng::Vec; use std::mem::replace; use collections::{HashMap, HashSet}; @@ -3966,7 +3966,7 @@ impl Resolver { } fn resolve_type_parameters(&mut self, - type_parameters: &OptVec) { + type_parameters: &Vec) { for type_parameter in type_parameters.iter() { for bound in type_parameter.bounds.iter() { self.resolve_type_parameter_bound(type_parameter.id, bound); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 4e780f45111b5..0e70a5dafee97 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -19,10 +19,11 @@ use driver::session; use std::cell::RefCell; +use std::vec_ng::Vec; + use collections::HashMap; use syntax::ast; use syntax::codemap::Span; -use syntax::opt_vec::OptVec; use syntax::parse::token::special_idents; use syntax::parse::token; use syntax::print::pprust::{lifetime_to_str}; @@ -39,8 +40,8 @@ struct LifetimeContext { } enum ScopeChain<'a> { - ItemScope(&'a OptVec), - FnScope(ast::NodeId, &'a OptVec, &'a ScopeChain<'a>), + ItemScope(&'a Vec), + FnScope(ast::NodeId, &'a Vec, &'a ScopeChain<'a>), BlockScope(ast::NodeId, &'a ScopeChain<'a>), RootScope } @@ -265,7 +266,7 @@ impl LifetimeContext { token::get_name(lifetime_ref.ident))); } - fn check_lifetime_names(&self, lifetimes: &OptVec) { + fn check_lifetime_names(&self, lifetimes: &Vec) { for i in range(0, lifetimes.len()) { let lifetime_i = lifetimes.get(i); @@ -311,7 +312,7 @@ impl LifetimeContext { } } -fn search_lifetimes(lifetimes: &OptVec, +fn search_lifetimes(lifetimes: &Vec, lifetime_ref: &ast::Lifetime) -> Option<(uint, ast::NodeId)> { for (i, lifetime_decl) in lifetimes.iter().enumerate() { diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 7176b512c719f..f59224cb54241 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -16,8 +16,8 @@ use middle::ty_fold::TypeFolder; use util::ppaux::Repr; use std::rc::Rc; +use std::vec_ng::Vec; use syntax::codemap::Span; -use syntax::opt_vec::OptVec; /////////////////////////////////////////////////////////////////////////// // Public trait `Subst` @@ -145,10 +145,10 @@ impl Subst for Rc { } } -impl Subst for OptVec { +impl Subst for Vec { fn subst_spanned(&self, tcx: ty::ctxt, substs: &ty::substs, - span: Option) -> OptVec { + span: Option) -> Vec { self.map(|t| t.subst_spanned(tcx, substs, span)) } } diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index 2cf24ff123a3c..bbca451bbbd90 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -24,10 +24,10 @@ use middle::trans::glue; use middle::trans::type_::Type; use middle::ty; use syntax::ast; -use syntax::opt_vec; -use syntax::opt_vec::OptVec; use util::ppaux::Repr; +use std::vec_ng::Vec; + pub struct CleanupScope<'a> { // The id of this cleanup scope. If the id is None, // this is a *temporary scope* that is pushed during trans to @@ -37,9 +37,9 @@ pub struct CleanupScope<'a> { kind: CleanupScopeKind<'a>, // Cleanups to run upon scope exit. - cleanups: OptVec<~Cleanup>, + cleanups: Vec<~Cleanup>, - cached_early_exits: OptVec, + cached_early_exits: Vec, cached_landing_pad: Option, } @@ -379,7 +379,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { assert!(orig_scopes_len > 0); // Remove any scopes that do not have cleanups on failure: - let mut popped_scopes = opt_vec::Empty; + let mut popped_scopes = Vec::new(); while !self.top_scope(|s| s.needs_invoke()) { debug!("top scope does not need invoke"); popped_scopes.push(self.pop_scope()); @@ -510,7 +510,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { let orig_scopes_len = self.scopes_len(); let mut prev_llbb; - let mut popped_scopes = opt_vec::Empty; + let mut popped_scopes = Vec::new(); // First we pop off all the cleanup stacks that are // traversed until the exit is reached, pushing them @@ -706,14 +706,14 @@ impl<'a> CleanupScope<'a> { fn new(kind: CleanupScopeKind<'a>) -> CleanupScope<'a> { CleanupScope { kind: kind, - cleanups: opt_vec::Empty, - cached_early_exits: opt_vec::Empty, + cleanups: Vec::new(), + cached_early_exits: Vec::new(), cached_landing_pad: None, } } fn clear_cached_exits(&mut self) { - self.cached_early_exits = opt_vec::Empty; + self.cached_early_exits = Vec::new(); self.cached_landing_pad = None; } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 44e6bbf91cf7c..46293c426a561 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -148,8 +148,9 @@ use std::libc::{c_uint, c_ulonglong, c_longlong}; use std::ptr; use std::sync::atomics; use std::vec; +use std::vec_ng::Vec; use syntax::codemap::{Span, Pos}; -use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec}; +use syntax::{abi, ast, codemap, ast_util, ast_map}; use syntax::parse::token; use syntax::parse::token::special_idents; @@ -538,7 +539,7 @@ pub fn create_function_debug_context(cx: &CrateContext, return FunctionWithoutDebugInfo; } - let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty }; + let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: Vec::new() }; let fnitem = cx.tcx.map.get(fn_ast_id); diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 55e237fda5ddd..d636bfa6b4006 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -19,8 +19,8 @@ use util::ppaux::Repr; use middle::trans::type_::Type; +use std::vec_ng::Vec; use syntax::ast; -use syntax::opt_vec; pub fn arg_is_indirect(ccx: &CrateContext, arg_ty: ty::t) -> bool { !type_is_immediate(ccx, arg_ty) @@ -320,7 +320,7 @@ pub fn llvm_type_name(cx: &CrateContext, an_enum => { "enum" } }; let tstr = ppaux::parameterized(cx.tcx, ty::item_path_str(cx.tcx, did), - &ty::NonerasedRegions(opt_vec::Empty), + &ty::NonerasedRegions(Vec::new()), tps, did, false); if did.krate == 0 { format!("{}.{}", name, tstr) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index e043bc8683f48..a5f054914f84e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -40,6 +40,7 @@ use std::hash::{Hash, sip}; use std::ops; use std::rc::Rc; use std::vec; +use std::vec_ng::Vec; use collections::{HashMap, HashSet}; use syntax::ast::*; use syntax::ast_util::{is_local, lit_is_str}; @@ -50,8 +51,6 @@ use syntax::codemap::Span; use syntax::parse::token; use syntax::parse::token::InternedString; use syntax::{ast, ast_map}; -use syntax::opt_vec::OptVec; -use syntax::opt_vec; use syntax::abi::AbiSet; use syntax; use collections::enum_set::{EnumSet, CLike}; @@ -194,8 +193,8 @@ pub enum ast_ty_to_ty_cache_entry { #[deriving(Clone, Eq, Decodable, Encodable)] pub struct ItemVariances { self_param: Option, - type_params: OptVec, - region_params: OptVec + type_params: Vec, + region_params: Vec } #[deriving(Clone, Eq, Decodable, Encodable, Show)] @@ -650,7 +649,7 @@ pub enum BoundRegion { #[deriving(Clone, Eq, Hash)] pub enum RegionSubsts { ErasedRegions, - NonerasedRegions(OptVec) + NonerasedRegions(Vec) } /** @@ -4660,7 +4659,7 @@ pub fn visitor_object_ty(tcx: ctxt, Err(s) => { return Err(s); } }; let substs = substs { - regions: ty::NonerasedRegions(opt_vec::Empty), + regions: ty::NonerasedRegions(Vec::new()), self_ty: None, tps: ~[] }; @@ -5110,7 +5109,7 @@ impl substs { substs { self_ty: None, tps: ~[], - regions: NonerasedRegions(opt_vec::Empty) + regions: NonerasedRegions(Vec::new()) } } } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index e1157d29d9d82..6cef720c42800 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -64,8 +64,6 @@ use std::vec_ng::Vec; use syntax::abi::AbiSet; use syntax::{ast, ast_util}; use syntax::codemap::Span; -use syntax::opt_vec::OptVec; -use syntax::opt_vec; use syntax::print::pprust::{lifetime_to_str, path_to_str}; pub trait AstConv { @@ -186,9 +184,9 @@ fn ast_path_substs( } match anon_regions { - Ok(v) => opt_vec::from(v.move_iter().collect()), - Err(()) => opt_vec::from(Vec::from_fn(expected_num_region_params, - |_| ty::ReStatic)) // hokey + Ok(v) => v.move_iter().collect(), + Err(()) => Vec::from_fn(expected_num_region_params, + |_| ty::ReStatic) // hokey } }; @@ -816,7 +814,7 @@ pub fn ty_of_closure( } } -fn conv_builtin_bounds(tcx: ty::ctxt, ast_bounds: &Option>, +fn conv_builtin_bounds(tcx: ty::ctxt, ast_bounds: &Option>, store: ty::TraitStore) -> ty::BuiltinBounds { //! Converts a list of bounds from the AST into a `BuiltinBounds` diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 6e9cfc9d0d2b0..a7a8b736eac71 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -117,6 +117,7 @@ use collections::HashMap; use std::mem::replace; use std::result; use std::vec; +use std::vec_ng::Vec; use syntax::abi::AbiSet; use syntax::ast::{Provided, Required}; use syntax::ast; @@ -125,8 +126,6 @@ use syntax::ast_util; use syntax::attr; use syntax::codemap::Span; use syntax::codemap; -use syntax::opt_vec::OptVec; -use syntax::opt_vec; use syntax::parse::token; use syntax::print::pprust; use syntax::visit; @@ -889,7 +888,7 @@ fn compare_impl_method(tcx: ty::ctxt, impl_m.generics.type_param_defs().iter().enumerate(). map(|(i,t)| ty::mk_param(tcx, i + impl_tps, t.def_id)). collect(); - let dummy_impl_regions: OptVec = + let dummy_impl_regions: Vec = impl_generics.region_param_defs().iter(). map(|l| ty::ReFree(ty::FreeRegion { scope_id: impl_m_body_id, @@ -1398,8 +1397,7 @@ pub fn impl_self_ty(vcx: &VtableContext, let tps = vcx.infcx.next_ty_vars(n_tps); let substs = substs { - regions: ty::NonerasedRegions(opt_vec::from(rps.move_iter() - .collect())), + regions: ty::NonerasedRegions(rps.move_iter().collect()), self_ty: None, tps: tps, }; @@ -2421,7 +2419,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, region_parameter_count).move_iter().collect(); let type_parameters = fcx.infcx().next_ty_vars(type_parameter_count); let substitutions = substs { - regions: ty::NonerasedRegions(opt_vec::from(regions)), + regions: ty::NonerasedRegions(regions), self_ty: None, tps: type_parameters }; @@ -2479,7 +2477,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, region_parameter_count).move_iter().collect(); let type_parameters = fcx.infcx().next_ty_vars(type_parameter_count); let substitutions = substs { - regions: ty::NonerasedRegions(opt_vec::from(regions)), + regions: ty::NonerasedRegions(regions), self_ty: None, tps: type_parameters }; @@ -2599,7 +2597,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, } }; let regions = - ty::NonerasedRegions(opt_vec::Empty); + ty::NonerasedRegions(Vec::new()); let sty = ty::mk_struct(tcx, gc_struct_id, substs { @@ -3671,9 +3669,9 @@ pub fn instantiate_path(fcx: @FnCtxt, num_expected_regions, num_supplied_regions)); } - opt_vec::from(fcx.infcx().next_region_vars( + fcx.infcx().next_region_vars( infer::BoundRegionInTypeOrImpl(span), - num_expected_regions).move_iter().collect()) + num_expected_regions).move_iter().collect() }; let regions = ty::NonerasedRegions(regions); @@ -3924,7 +3922,7 @@ pub fn may_break(cx: ty::ctxt, id: ast::NodeId, b: ast::P) -> bool { pub fn check_bounds_are_used(ccx: @CrateCtxt, span: Span, - tps: &OptVec, + tps: &Vec, ty: ty::t) { debug!("check_bounds_are_used(n_tps={}, ty={})", tps.len(), ppaux::ty_to_str(ccx.tcx, ty)); @@ -4041,7 +4039,7 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) { Ok(did) => (1u, ~[], ty::mk_struct(ccx.tcx, did, substs { self_ty: None, tps: ~[], - regions: ty::NonerasedRegions(opt_vec::Empty) + regions: ty::NonerasedRegions(Vec::new()) }) ), Err(msg) => { tcx.sess.span_fatal(it.span, msg); } } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index e47b6e722f386..afabd237c6766 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -42,7 +42,6 @@ use syntax::ast_map::NodeItem; use syntax::ast_map; use syntax::ast_util::{def_id_of_def, local_def}; use syntax::codemap::Span; -use syntax::opt_vec; use syntax::parse::token; use syntax::visit; @@ -524,8 +523,7 @@ impl CoherenceChecker { let type_parameters = self.inference_context.next_ty_vars(bounds_count); let substitutions = substs { - regions: ty::NonerasedRegions(opt_vec::from( - region_parameters.move_iter().collect())), + regions: ty::NonerasedRegions(region_parameters.move_iter().collect()), self_ty: None, tps: type_parameters }; diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index f7733335c9177..71b8d01691cdd 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -46,6 +46,7 @@ use util::ppaux::Repr; use std::rc::Rc; use std::vec; +use std::vec_ng::Vec; use syntax::abi::AbiSet; use syntax::ast::{RegionTyParamBound, TraitTyParamBound}; use syntax::ast; @@ -57,7 +58,6 @@ use syntax::parse::token::special_idents; use syntax::parse::token; use syntax::print::pprust::{path_to_str}; use syntax::visit; -use syntax::opt_vec::OptVec; struct CollectItemTypesVisitor { ccx: @CrateCtxt @@ -963,7 +963,7 @@ pub fn ty_generics(ccx: &CrateCtxt, ty::RegionParameterDef { ident: l.ident, def_id: local_def(l.id) } }).collect()), - type_param_defs: Rc::new(generics.ty_params.mapi_to_vec(|offset, param| { + type_param_defs: Rc::new(generics.ty_params.iter().enumerate().map(|(offset, param)| { let existing_def_opt = { let ty_param_defs = ccx.tcx.ty_param_defs.borrow(); ty_param_defs.get().find(¶m.id).map(|def| *def) @@ -990,13 +990,13 @@ pub fn ty_generics(ccx: &CrateCtxt, def } } - }).move_iter().collect()) + }).collect()) }; fn compute_bounds( ccx: &CrateCtxt, param_ty: ty::param_ty, - ast_bounds: &OptVec) -> ty::ParamBounds + ast_bounds: &Vec) -> ty::ParamBounds { /*! * Translate the AST's notion of ty param bounds (which are an @@ -1076,7 +1076,7 @@ pub fn mk_item_substs(ccx: &CrateCtxt, ty_generics.type_param_defs().iter().enumerate().map( |(i, t)| ty::mk_param(ccx.tcx, i, t.def_id)).collect(); - let regions: OptVec = + let regions: Vec = ty_generics.region_param_defs().iter().enumerate().map( |(i, l)| ty::ReEarlyBound(l.def_id.node, i, l.ident)).collect(); diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 95d605823da3e..cb33faebcc11b 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -63,9 +63,10 @@ use util::common::indent; use util::ppaux::Repr; use std::result; +use std::vec_ng::Vec; + use syntax::ast::{Onceness, Purity}; use syntax::ast; -use syntax::opt_vec; use syntax::abi::AbiSet; pub trait Combine { @@ -159,7 +160,7 @@ pub trait Combine { assert_eq!(num_region_params, a_rs.len()); assert_eq!(num_region_params, b_rs.len()); - let mut rs = opt_vec::Empty; + let mut rs = Vec::new(); for i in range(0, num_region_params) { let a_r = *a_rs.get(i); let b_r = *b_rs.get(i); diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 3a3f24a2e2d88..e83fcd070f3c3 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -71,14 +71,15 @@ use middle::typeck::infer::region_inference::RegionResolutionError; use middle::typeck::infer::region_inference::ConcreteFailure; use middle::typeck::infer::region_inference::SubSupConflict; use middle::typeck::infer::region_inference::SupSupConflict; -use syntax::opt_vec::OptVec; use util::ppaux::UserString; use util::ppaux::bound_region_to_str; use util::ppaux::note_and_explain_region; +use std::vec_ng::Vec; + pub trait ErrorReporting { fn report_region_errors(&self, - errors: &OptVec); + errors: &Vec); fn report_and_explain_type_error(&self, trace: TypeTrace, @@ -121,7 +122,7 @@ trait ErrorReportingHelpers { impl ErrorReporting for InferCtxt { fn report_region_errors(&self, - errors: &OptVec) { + errors: &Vec) { for error in errors.iter() { match *error { ConcreteFailure(origin, sub, sup) => { @@ -661,4 +662,3 @@ impl Resolvable for @ty::TraitRef { ty::trait_ref_contains_error(*self) } } - diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index 98fe0bedb3be8..d98b2800e6eb1 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -27,10 +27,9 @@ use util::ppaux::{Repr}; use std::cell::{Cell, RefCell}; use std::uint; use std::vec; +use std::vec_ng::Vec; use collections::{HashMap, HashSet}; use syntax::ast; -use syntax::opt_vec; -use syntax::opt_vec::OptVec; mod doc; @@ -526,9 +525,9 @@ impl RegionVarBindings { constraints, assuming such values can be found; if they cannot, errors are reported. */ - pub fn resolve_regions(&self) -> OptVec { + pub fn resolve_regions(&self) -> Vec { debug!("RegionVarBindings: resolve_regions()"); - let mut errors = opt_vec::Empty; + let mut errors = Vec::new(); let v = self.infer_variable_values(&mut errors); let mut values = self.values.borrow_mut(); *values.get() = Some(v); @@ -780,7 +779,7 @@ type RegionGraph = graph::Graph<(), Constraint>; impl RegionVarBindings { fn infer_variable_values(&self, - errors: &mut OptVec) + errors: &mut Vec) -> ~[VarValue] { let mut var_data = self.construct_var_data(); self.expansion(var_data); @@ -969,7 +968,7 @@ impl RegionVarBindings { fn collect_concrete_region_errors( &self, - errors: &mut OptVec) + errors: &mut Vec) { let constraints = self.constraints.borrow(); for (constraint, _) in constraints.get().iter() { @@ -998,7 +997,7 @@ impl RegionVarBindings { fn extract_values_and_collect_conflicts( &self, var_data: &[VarData], - errors: &mut OptVec) + errors: &mut Vec) -> ~[VarValue] { debug!("extract_values_and_collect_conflicts()"); @@ -1123,7 +1122,7 @@ impl RegionVarBindings { var_data: &[VarData], dup_vec: &mut [uint], node_idx: RegionVid, - errors: &mut OptVec) + errors: &mut Vec) { // Errors in expanding nodes result from a lower-bound that is // not contained by an upper-bound. @@ -1172,7 +1171,7 @@ impl RegionVarBindings { var_data: &[VarData], dup_vec: &mut [uint], node_idx: RegionVid, - errors: &mut OptVec) + errors: &mut Vec) { // Errors in contracting nodes result from two upper-bounds // that have no intersection. diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc/middle/typeck/rscope.rs index b20312c2241c9..19958f0342749 100644 --- a/src/librustc/middle/typeck/rscope.rs +++ b/src/librustc/middle/typeck/rscope.rs @@ -13,9 +13,9 @@ use middle::ty; use std::cell::Cell; use std::vec; +use std::vec_ng::Vec; use syntax::ast; use syntax::codemap::Span; -use syntax::opt_vec::OptVec; /// Defines strategies for handling regions that are omitted. For /// example, if one writes the type `&Foo`, then the lifetime of of @@ -75,7 +75,7 @@ impl RegionScope for BindingRscope { } pub fn bound_type_regions(defs: &[ty::RegionParameterDef]) - -> OptVec { + -> Vec { assert!(defs.iter().all(|def| def.def_id.krate == ast::LOCAL_CRATE)); defs.iter().enumerate().map( |(i, def)| ty::ReEarlyBound(def.def_id.node, i, def.ident)).collect() diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index bd244b431c20e..8f5bf35cada55 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -198,9 +198,9 @@ use arena::Arena; use middle::ty; use std::vec; use std::fmt; +use std::vec_ng::Vec; use syntax::ast; use syntax::ast_util; -use syntax::opt_vec; use syntax::visit; use syntax::visit::Visitor; use util::ppaux::Repr; @@ -287,8 +287,8 @@ fn determine_parameters_to_be_inferred<'a>(tcx: ty::ctxt, // cache and share the variance struct used for items with // no type/region parameters empty_variances: @ty::ItemVariances { self_param: None, - type_params: opt_vec::Empty, - region_params: opt_vec::Empty } + type_params: Vec::new(), + region_params: Vec::new() } }; visit::walk_crate(&mut terms_cx, krate, ()); @@ -905,8 +905,8 @@ impl<'a> SolveContext<'a> { let item_id = inferred_infos[index].item_id; let mut item_variances = ty::ItemVariances { self_param: None, - type_params: opt_vec::Empty, - region_params: opt_vec::Empty + type_params: Vec::new(), + region_params: Vec::new() }; while index < num_inferred && inferred_infos[index].item_id == item_id { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1384bf182a762..a64e2bedb20cc 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -28,8 +28,8 @@ use syntax::codemap::{Span, Pos}; use syntax::parse::token; use syntax::print::pprust; use syntax::{ast, ast_util}; -use syntax::opt_vec; -use syntax::opt_vec::OptVec; + +use std::vec_ng::Vec; /// Produces a string suitable for debugging output. pub trait Repr { @@ -599,12 +599,9 @@ impl<'a, T:Repr> Repr for &'a [T] { } } -impl Repr for OptVec { +impl Repr for Vec { fn repr(&self, tcx: ctxt) -> ~str { - match *self { - opt_vec::Empty => ~"[]", - opt_vec::Vec(ref v) => repr_vec(tcx, v.as_slice()) - } + repr_vec(tcx, self.as_slice()) } } diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index ce922e7d6951f..8467b20127281 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -62,15 +62,6 @@ impl, U> Clean> for Option { } } -impl, U> Clean> for syntax::opt_vec::OptVec { - fn clean(&self) -> Vec { - match self { - &syntax::opt_vec::Empty => Vec::new(), - &syntax::opt_vec::Vec(ref v) => v.clean() - } - } -} - #[deriving(Clone, Encodable, Decodable)] pub struct Crate { name: ~str, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 947463d8f47b1..be9a5a3080e22 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,6 @@ use codemap::{Span, Spanned, DUMMY_SP}; use abi::AbiSet; use ast_util; -use opt_vec::OptVec; use parse::token::{InternedString, special_idents, str_to_ident}; use parse::token; @@ -175,9 +174,9 @@ pub struct PathSegment { /// The identifier portion of this path segment. identifier: Ident, /// The lifetime parameters for this path segment. - lifetimes: OptVec, + lifetimes: Vec, /// The type parameters for this path segment, if present. - types: OptVec>, + types: Vec>, } pub type CrateNum = u32; @@ -214,14 +213,14 @@ pub enum TyParamBound { pub struct TyParam { ident: Ident, id: NodeId, - bounds: OptVec, + bounds: Vec, default: Option> } #[deriving(Clone, Eq, Encodable, Decodable, Hash)] pub struct Generics { - lifetimes: OptVec, - ty_params: OptVec, + lifetimes: Vec, + ty_params: Vec, } impl Generics { @@ -828,7 +827,7 @@ impl fmt::Show for Onceness { pub struct ClosureTy { sigil: Sigil, region: Option, - lifetimes: OptVec, + lifetimes: Vec, purity: Purity, onceness: Onceness, decl: P, @@ -836,14 +835,14 @@ pub struct ClosureTy { // implement issue #7264. None means "fn()", which means infer a default // bound based on pointer sigil during typeck. Some(Empty) means "fn:()", // which means use no bounds (e.g., not even Owned on a ~fn()). - bounds: Option>, + bounds: Option>, } #[deriving(Eq, Encodable, Decodable, Hash)] pub struct BareFnTy { purity: Purity, abis: AbiSet, - lifetimes: OptVec, + lifetimes: Vec, decl: P } @@ -860,7 +859,7 @@ pub enum Ty_ { TyClosure(@ClosureTy), TyBareFn(@BareFnTy), TyTup(Vec> ), - TyPath(Path, Option>, NodeId), // for #7264; see above + TyPath(Path, Option>, NodeId), // for #7264; see above TyTypeof(@Expr), // TyInfer means the type should be inferred instead of it having been // specified. This should only appear at the "top level" of a type and not diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index db9ea480e9620..f8e4ac5c086ed 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -12,7 +12,6 @@ use ast::*; use ast; use ast_util; use codemap::Span; -use opt_vec; use parse::token; use print::pprust; use visit::Visitor; @@ -197,8 +196,8 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { segments: vec!( ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), } @@ -313,8 +312,8 @@ pub fn operator_prec(op: ast::BinOp) -> uint { pub static as_prec: uint = 12u; pub fn empty_generics() -> Generics { - Generics {lifetimes: opt_vec::Empty, - ty_params: opt_vec::Empty} + Generics {lifetimes: Vec::new(), + ty_params: Vec::new()} } // ______________________________________________________________________ @@ -936,15 +935,14 @@ pub fn lit_is_str(lit: @Lit) -> bool { mod test { use ast::*; use super::*; - use opt_vec; use collections::HashMap; use std::vec_ng::Vec; fn ident_to_segment(id : &Ident) -> PathSegment { PathSegment {identifier:id.clone(), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty} + lifetimes: Vec::new(), + types: Vec::new()} } #[test] fn idents_name_eq_test() { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 34625923ea1f6..277b6893bb1a1 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -16,8 +16,6 @@ use codemap::{Span, respan, DUMMY_SP}; use ext::base::ExtCtxt; use ext::quote::rt::*; use fold::Folder; -use opt_vec; -use opt_vec::OptVec; use parse::token::special_idents; use parse::token; @@ -42,7 +40,7 @@ pub trait AstBuilder { fn path_all(&self, sp: Span, global: bool, idents: Vec , - lifetimes: OptVec, + lifetimes: Vec, types: Vec> ) -> ast::Path; @@ -50,7 +48,7 @@ pub trait AstBuilder { fn ty_mt(&self, ty: P, mutbl: ast::Mutability) -> ast::MutTy; fn ty(&self, span: Span, ty: ast::Ty_) -> P; - fn ty_path(&self, ast::Path, Option>) -> P; + fn ty_path(&self, ast::Path, Option>) -> P; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P; fn ty_rptr(&self, span: Span, @@ -63,14 +61,14 @@ pub trait AstBuilder { fn ty_infer(&self, sp: Span) -> P; fn ty_nil(&self) -> P; - fn ty_vars(&self, ty_params: &OptVec) -> Vec> ; - fn ty_vars_global(&self, ty_params: &OptVec) -> Vec> ; + fn ty_vars(&self, ty_params: &Vec) -> Vec> ; + fn ty_vars_global(&self, ty_params: &Vec) -> Vec> ; fn ty_field_imm(&self, span: Span, name: Ident, ty: P) -> ast::TypeField; fn strip_bounds(&self, bounds: &Generics) -> Generics; fn typaram(&self, id: ast::Ident, - bounds: OptVec, + bounds: Vec, default: Option>) -> ast::TyParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; @@ -255,19 +253,19 @@ pub trait AstBuilder { impl<'a> AstBuilder for ExtCtxt<'a> { fn path(&self, span: Span, strs: Vec ) -> ast::Path { - self.path_all(span, false, strs, opt_vec::Empty, Vec::new()) + self.path_all(span, false, strs, Vec::new(), Vec::new()) } fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path { self.path(span, vec!(id)) } fn path_global(&self, span: Span, strs: Vec ) -> ast::Path { - self.path_all(span, true, strs, opt_vec::Empty, Vec::new()) + self.path_all(span, true, strs, Vec::new(), Vec::new()) } fn path_all(&self, sp: Span, global: bool, mut idents: Vec , - lifetimes: OptVec, + lifetimes: Vec, types: Vec> ) -> ast::Path { let last_identifier = idents.pop().unwrap(); @@ -275,14 +273,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { .map(|ident| { ast::PathSegment { identifier: ident, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } }).collect(); segments.push(ast::PathSegment { identifier: last_identifier, lifetimes: lifetimes, - types: opt_vec::from(types), + types: types, }); ast::Path { span: sp, @@ -306,7 +304,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }) } - fn ty_path(&self, path: ast::Path, bounds: Option>) + fn ty_path(&self, path: ast::Path, bounds: Option>) -> P { self.ty(path.span, ast::TyPath(path, bounds, ast::DUMMY_NODE_ID)) @@ -342,7 +340,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ident_of("option"), self.ident_of("Option") ), - opt_vec::Empty, + Vec::new(), vec!( ty )), None) } @@ -368,7 +366,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, id: ast::Ident, - bounds: OptVec, + bounds: Vec, default: Option>) -> ast::TyParam { ast::TyParam { ident: id, @@ -381,20 +379,18 @@ impl<'a> AstBuilder for ExtCtxt<'a> { // these are strange, and probably shouldn't be used outside of // pipes. Specifically, the global version possible generates // incorrect code. - fn ty_vars(&self, ty_params: &OptVec) -> Vec> { - opt_vec::take_vec( - ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident))) + fn ty_vars(&self, ty_params: &Vec) -> Vec> { + ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident)) } - fn ty_vars_global(&self, ty_params: &OptVec) -> Vec> { - opt_vec::take_vec( - ty_params.map(|p| self.ty_path( - self.path_global(DUMMY_SP, vec!(p.ident)), None))) + fn ty_vars_global(&self, ty_params: &Vec) -> Vec> { + ty_params.map(|p| self.ty_path( + self.path_global(DUMMY_SP, vec!(p.ident)), None)) } fn strip_bounds(&self, generics: &Generics) -> Generics { let new_params = generics.ty_params.map(|ty_param| { - ast::TyParam { bounds: opt_vec::Empty, ..*ty_param } + ast::TyParam { bounds: Vec::new(), ..*ty_param } }); Generics { ty_params: new_params, diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 2552586939811..a9c53b13da378 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -12,10 +12,11 @@ use ast; use codemap::Span; use ext::base::*; use ext::base; -use opt_vec; use parse::token; use parse::token::{str_to_ident}; +use std::vec_ng::Vec; + pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { let mut res_str = ~""; @@ -51,8 +52,8 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) segments: vec!( ast::PathSegment { identifier: res, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ) } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 1dc474551cf7c..a8a170a9f8798 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -184,7 +184,6 @@ use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap; use codemap::Span; -use opt_vec; use parse::token::InternedString; use parse::token; @@ -372,12 +371,12 @@ impl<'a> TraitDef<'a> { for ty_param in generics.ty_params.iter() { // I don't think this can be moved out of the loop, since // a TyParamBound requires an ast id - let mut bounds = opt_vec::from( + let mut bounds = // extra restrictions on the generics parameters to the type being derived upon self.additional_bounds.map(|p| { cx.typarambound(p.to_path(cx, self.span, type_ident, generics)) - })); + }); // require the current trait bounds.push(cx.typarambound(trait_path.clone())); @@ -396,8 +395,8 @@ impl<'a> TraitDef<'a> { // Create the type of `self`. let self_type = cx.ty_path( - cx.path_all(self.span, false, vec!( type_ident ), self_lifetimes, - opt_vec::take_vec(self_ty_params)), None); + cx.path_all(self.span, false, vec!( type_ident ), self_lifetimes, self_ty_params), + None); let doc_attr = cx.attribute( self.span, diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index da9679eb65578..b2be0d71cac02 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -14,7 +14,6 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::{AstBuilder}; use ext::deriving::generic::*; -use opt_vec; use std::vec_ng::Vec; @@ -85,7 +84,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let rand_name = cx.path_all(trait_span, true, rand_ident.clone(), - opt_vec::Empty, + Vec::new(), Vec::new()); let rand_name = cx.expr_path(rand_name); diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index b88cd117911c7..7b9452babaa39 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -18,8 +18,6 @@ use ast::{P,Expr,Generics,Ident}; use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap::{Span,respan}; -use opt_vec; -use opt_vec::OptVec; use std::vec_ng::Vec; @@ -118,10 +116,10 @@ fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option) -> OptVec { +fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec { match *lt { - Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)), - None => opt_vec::Empty + Some(ref s) => vec!(cx.lifetime(span, cx.ident_of(*s).name)), + None => Vec::new() } } @@ -174,8 +172,7 @@ impl<'a> Ty<'a> { }); let lifetimes = self_generics.lifetimes.clone(); - cx.path_all(span, false, vec!(self_ty), lifetimes, - opt_vec::take_vec(self_params)) + cx.path_all(span, false, vec!(self_ty), lifetimes, self_params) } Literal(ref p) => { p.to_path(cx, span, self_ty, self_generics) @@ -189,18 +186,18 @@ impl<'a> Ty<'a> { fn mk_ty_param(cx: &ExtCtxt, span: Span, name: &str, bounds: &[Path], self_ident: Ident, self_generics: &Generics) -> ast::TyParam { - let bounds = opt_vec::from( + let bounds = bounds.iter().map(|b| { let path = b.to_path(cx, span, self_ident, self_generics); cx.typarambound(path) - }).collect()); + }).collect(); cx.typaram(cx.ident_of(name), bounds, None) } fn mk_generics(lifetimes: Vec , ty_params: Vec ) -> Generics { Generics { - lifetimes: opt_vec::from(lifetimes), - ty_params: opt_vec::from(ty_params) + lifetimes: lifetimes, + ty_params: ty_params } } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index b0b5fa26015cc..0c7b92d0373cc 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -19,10 +19,10 @@ use codemap::Span; use ext::base::*; use ext::base; use ext::build::AstBuilder; -use opt_vec; use parse::token; use std::os; +use std::vec_ng::Vec; pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { @@ -38,7 +38,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) vec!(cx.ident_of("std"), cx.ident_of("option"), cx.ident_of("None")), - opt_vec::Empty, + Vec::new(), vec!(cx.ty_rptr(sp, cx.ty_ident(sp, cx.ident_of("str")), diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index b27ea3df21ec0..8aa80178f4502 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -14,7 +14,6 @@ use codemap::{Span, respan}; use ext::base::*; use ext::base; use ext::build::AstBuilder; -use opt_vec; use parse::token::InternedString; use parse::token; use rsparse = parse; @@ -509,7 +508,7 @@ impl<'a> Context<'a> { sp, true, self.rtpath("Method"), - opt_vec::with(life), + vec!(life), Vec::new() ), None); let st = ast::ItemStatic(ty, ast::MutImmutable, method); @@ -632,8 +631,7 @@ impl<'a> Context<'a> { self.ecx.ident_of("fmt"), self.ecx.ident_of("rt"), self.ecx.ident_of("Piece")), - opt_vec::with( - self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)), + vec!(self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static").name)), Vec::new() ), None); let ty = ast::TyFixedLengthVec( diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index b01ba7718ba58..084c2be60a59a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -13,7 +13,6 @@ use ast; use ast_util; use codemap::{respan, Span, Spanned}; use parse::token; -use opt_vec::OptVec; use util::small_vector::SmallVector; use std::vec_ng::Vec; @@ -426,8 +425,8 @@ pub fn fold_ty_param(tp: &TyParam, fld: &mut T) -> TyParam { } } -pub fn fold_ty_params(tps: &OptVec, fld: &mut T) - -> OptVec { +pub fn fold_ty_params(tps: &Vec, fld: &mut T) + -> Vec { tps.map(|tp| fold_ty_param(tp, fld)) } @@ -439,8 +438,8 @@ pub fn fold_lifetime(l: &Lifetime, fld: &mut T) -> Lifetime { } } -pub fn fold_lifetimes(lts: &OptVec, fld: &mut T) - -> OptVec { +pub fn fold_lifetimes(lts: &Vec, fld: &mut T) + -> Vec { lts.map(|l| fold_lifetime(l, fld)) } @@ -495,8 +494,8 @@ fn fold_mt(mt: &MutTy, folder: &mut T) -> MutTy { } } -fn fold_opt_bounds(b: &Option>, folder: &mut T) - -> Option> { +fn fold_opt_bounds(b: &Option>, folder: &mut T) + -> Option> { b.as_ref().map(|bounds| { bounds.map(|bound| { fold_ty_param_bound(bound, folder) @@ -933,4 +932,3 @@ mod test { ~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))"); } } - diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 42c9ab461aa00..850e81d4722af 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -48,7 +48,6 @@ pub mod syntax { pub use parse; } -pub mod opt_vec; pub mod attr; pub mod diagnostic; pub mod codemap; diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs deleted file mode 100644 index ec81fff51c791..0000000000000 --- a/src/libsyntax/opt_vec.rs +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - * Defines a type OptVec that can be used in place of ~[T]. - * OptVec avoids the need for allocation for empty vectors. - * OptVec implements the iterable interface as well as - * other useful things like `push()` and `len()`. - */ - -use std::default::Default; -use std::vec; -use std::vec_ng::Vec; - -#[deriving(Clone, Encodable, Decodable, Hash)] -pub enum OptVec { - Empty, - Vec(Vec ) -} - -pub fn with(t: T) -> OptVec { - Vec(vec!(t)) -} - -pub fn from(t: Vec ) -> OptVec { - if t.len() == 0 { - Empty - } else { - Vec(t) - } -} - -impl OptVec { - pub fn push(&mut self, t: T) { - match *self { - Vec(ref mut v) => { - v.push(t); - return; - } - Empty => { - *self = Vec(vec!(t)); - } - } - } - - pub fn pop(&mut self) -> Option { - match *self { - Vec(ref mut v) => v.pop(), - Empty => None - } - } - - pub fn last<'a>(&'a self) -> Option<&'a T> { - match *self { - Vec(ref v) => v.last(), - Empty => None - } - } - - pub fn mut_last<'a>(&'a mut self) -> Option<&'a mut T> { - match *self { - Vec(ref mut v) => v.mut_last(), - Empty => None - } - } - - pub fn map(&self, op: |&T| -> U) -> OptVec { - match *self { - Empty => Empty, - Vec(ref v) => Vec(v.map(op)) - } - } - - pub fn map_move(self, op: |T| -> U) -> OptVec { - match self { - Empty => Empty, - Vec(v) => Vec(v.move_iter().map(op).collect()) - } - } - - pub fn get<'a>(&'a self, i: uint) -> &'a T { - match *self { - Empty => fail!("invalid index {}", i), - Vec(ref v) => v.get(i) - } - } - - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - - pub fn len(&self) -> uint { - match *self { - Empty => 0, - Vec(ref v) => v.len() - } - } - - pub fn swap_remove(&mut self, index: uint) { - match *self { - Empty => { fail!("index out of bounds"); } - Vec(ref mut v) => { - assert!(index < v.len()); - v.swap_remove(index); - } - } - } - - #[inline] - pub fn iter<'r>(&'r self) -> Items<'r, T> { - match *self { - Empty => Items{iter: None}, - Vec(ref v) => Items{iter: Some(v.iter())} - } - } - - #[inline] - pub fn map_to_vec(&self, op: |&T| -> B) -> Vec { - self.iter().map(op).collect() - } - - pub fn mapi_to_vec(&self, op: |uint, &T| -> B) -> Vec { - let mut index = 0; - self.map_to_vec(|a| { - let i = index; - index += 1; - op(i, a) - }) - } -} - -pub fn take_vec(v: OptVec) -> Vec { - match v { - Empty => Vec::new(), - Vec(v) => v - } -} - -impl OptVec { - pub fn prepend(&self, t: T) -> OptVec { - let mut v0 = vec!(t); - match *self { - Empty => {} - Vec(ref v1) => { v0.push_all(v1.as_slice()); } - } - return Vec(v0); - } -} - -impl Eq for OptVec { - fn eq(&self, other: &OptVec) -> bool { - // Note: cannot use #[deriving(Eq)] here because - // (Empty, Vec(~[])) ought to be equal. - match (self, other) { - (&Empty, &Empty) => true, - (&Empty, &Vec(ref v)) => v.is_empty(), - (&Vec(ref v), &Empty) => v.is_empty(), - (&Vec(ref v1), &Vec(ref v2)) => *v1 == *v2 - } - } - - fn ne(&self, other: &OptVec) -> bool { - !self.eq(other) - } -} - -impl Default for OptVec { - fn default() -> OptVec { Empty } -} - -pub struct Items<'a, T> { - priv iter: Option> -} - -impl<'a, T> Iterator<&'a T> for Items<'a, T> { - #[inline] - fn next(&mut self) -> Option<&'a T> { - match self.iter { - Some(ref mut x) => x.next(), - None => None - } - } - - #[inline] - fn size_hint(&self) -> (uint, Option) { - match self.iter { - Some(ref x) => x.size_hint(), - None => (0, Some(0)) - } - } -} - -impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { - #[inline] - fn next_back(&mut self) -> Option<&'a T> { - match self.iter { - Some(ref mut x) => x.next_back(), - None => None - } - } -} - -impl FromIterator for OptVec { - fn from_iterator>(iterator: &mut T) -> OptVec { - let mut r = Empty; - for x in *iterator { - r.push(x); - } - r - } -} diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 9e5db1770bf31..a2c476680c223 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -291,7 +291,6 @@ mod test { use std::str; use std::vec_ng::Vec; use codemap::{Span, BytePos, Spanned}; - use opt_vec; use ast; use abi; use parse::parser::Parser; @@ -323,8 +322,8 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("a"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }), @@ -342,13 +341,13 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("a"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }, ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ) }), @@ -556,8 +555,8 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("d"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }), @@ -578,8 +577,8 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }), @@ -605,8 +604,8 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }, @@ -633,8 +632,8 @@ mod test { ast::PathSegment { identifier: str_to_ident("int"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }, None, ast::DUMMY_NODE_ID), @@ -651,8 +650,8 @@ mod test { ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } ), }, @@ -671,8 +670,8 @@ mod test { ast::ImpureFn, abi::AbiSet::Rust(), ast::Generics{ // no idea on either of these: - lifetimes: opt_vec::Empty, - ty_params: opt_vec::Empty, + lifetimes: Vec::new(), + ty_params: Vec::new(), }, ast::P(ast::Block { view_items: Vec::new(), @@ -689,9 +688,9 @@ mod test { str_to_ident( "b"), lifetimes: - opt_vec::Empty, + Vec::new(), types: - opt_vec::Empty + Vec::new() } ), }), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2557af5e436a2..4a5827bd14023 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -75,8 +75,6 @@ use parse::token::{is_ident, is_ident_or_path, is_plain_ident}; use parse::token::{keywords, special_idents, token_to_binop}; use parse::token; use parse::{new_sub_parser_from_file, ParseSess}; -use opt_vec; -use opt_vec::OptVec; use std::cell::Cell; use collections::HashSet; @@ -118,13 +116,13 @@ pub enum PathParsingMode { /// for the definition of a path segment.) struct PathSegmentAndBoundSet { segment: ast::PathSegment, - bound_set: Option>, + bound_set: Option>, } /// A path paired with optional type bounds. pub struct PathAndBounds { path: ast::Path, - bounds: Option>, + bounds: Option>, } enum ItemOrViewItem { @@ -631,9 +629,9 @@ impl Parser { &mut self, sep: Option, f: |&mut Parser| -> T) - -> OptVec { + -> Vec { let mut first = true; - let mut v = opt_vec::Empty; + let mut v = Vec::new(); while self.token != token::GT && self.token != token::BINOP(token::SHR) { match sep { @@ -652,7 +650,7 @@ impl Parser { &mut self, sep: Option, f: |&mut Parser| -> T) - -> OptVec { + -> Vec { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; @@ -957,7 +955,7 @@ impl Parser { lifetimes } else { - opt_vec::Empty + Vec::new() }; let inputs = if self.eat(&token::OROR) { @@ -1014,7 +1012,7 @@ impl Parser { // parse a function type (following the 'fn') pub fn parse_ty_fn_decl(&mut self, allow_variadic: bool) - -> (P, OptVec) { + -> (P, Vec) { /* (fn) <'lt> (S) -> T @@ -1030,7 +1028,7 @@ impl Parser { self.expect_gt(); lifetimes } else { - opt_vec::Empty + Vec::new() }; let (inputs, variadic) = self.parse_fn_args(false, allow_variadic); @@ -1509,8 +1507,8 @@ impl Parser { segments.push(PathSegmentAndBoundSet { segment: ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), }, bound_set: bound_set }); @@ -1522,9 +1520,9 @@ impl Parser { if mode != NoTypesAllowed && self.eat(&token::LT) { let (lifetimes, types) = self.parse_generic_values_after_lt(); - (true, lifetimes, opt_vec::from(types)) + (true, lifetimes, types) } else { - (false, opt_vec::Empty, opt_vec::Empty) + (false, Vec::new(), Vec::new()) } }; @@ -1620,7 +1618,7 @@ impl Parser { // matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) // actually, it matches the empty one too, but putting that in there // messes up the grammar.... - pub fn parse_lifetimes(&mut self) -> OptVec { + pub fn parse_lifetimes(&mut self) -> Vec { /*! * * Parses zero or more comma separated lifetimes. @@ -1629,7 +1627,7 @@ impl Parser { * lists, where we expect something like `<'a, 'b, T>`. */ - let mut res = opt_vec::Empty; + let mut res = Vec::new(); loop { match self.token { token::LIFETIME(_) => { @@ -1994,7 +1992,7 @@ impl Parser { self.expect(&token::LT); self.parse_generic_values_after_lt() } else { - (opt_vec::Empty, Vec::new()) + (Vec::new(), Vec::new()) }; // expr.f() method call @@ -3445,12 +3443,12 @@ impl Parser { // Returns "Some(Empty)" if there's a colon but nothing after (e.g. "T:") // Returns "Some(stuff)" otherwise (e.g. "T:stuff"). // NB: The None/Some distinction is important for issue #7264. - fn parse_optional_ty_param_bounds(&mut self) -> Option> { + fn parse_optional_ty_param_bounds(&mut self) -> Option> { if !self.eat(&token::COLON) { return None; } - let mut result = opt_vec::Empty; + let mut result = Vec::new(); loop { match self.token { token::LIFETIME(lifetime) => { @@ -3523,12 +3521,12 @@ impl Parser { } } - fn parse_generic_values_after_lt(&mut self) -> (OptVec, Vec> ) { + fn parse_generic_values_after_lt(&mut self) -> (Vec, Vec> ) { let lifetimes = self.parse_lifetimes(); let result = self.parse_seq_to_gt( Some(token::COMMA), |p| p.parse_ty(false)); - (lifetimes, opt_vec::take_vec(result)) + (lifetimes, result) } fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool) @@ -4894,8 +4892,8 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } }).collect() }; @@ -4929,8 +4927,8 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } }).collect() }; @@ -4947,8 +4945,8 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } }).collect() }; @@ -4969,8 +4967,8 @@ impl Parser { segments: path.move_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: opt_vec::Empty, - types: opt_vec::Empty, + lifetimes: Vec::new(), + types: Vec::new(), } }).collect() }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ec8c474d19402..656d341310e7b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -12,8 +12,6 @@ use abi::AbiSet; use ast::{P, RegionTyParamBound, TraitTyParamBound, Required, Provided}; use ast; use ast_util; -use opt_vec::OptVec; -use opt_vec; use attr::{AttrMetaMethods, AttributeMethods}; use codemap::{CodeMap, BytePos}; use codemap; @@ -473,7 +471,7 @@ pub fn print_type(s: &mut State, ty: &ast::Ty) -> io::IoResult<()> { ast::TyBareFn(f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty + ty_params: Vec::new() }; try!(print_ty_fn(s, Some(f.abis), None, &None, f.purity, ast::Many, f.decl, None, &None, @@ -482,7 +480,7 @@ pub fn print_type(s: &mut State, ty: &ast::Ty) -> io::IoResult<()> { ast::TyClosure(f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty + ty_params: Vec::new() }; try!(print_ty_fn(s, None, Some(f.sigil), &f.region, f.purity, f.onceness, f.decl, None, &f.bounds, @@ -1614,7 +1612,7 @@ pub fn print_for_decl(s: &mut State, loc: &ast::Local, fn print_path_(s: &mut State, path: &ast::Path, colons_before_params: bool, - opt_bounds: &Option>) + opt_bounds: &Option>) -> io::IoResult<()> { try!(maybe_print_comment(s, path.span.lo)); @@ -1661,7 +1659,7 @@ fn print_path_(s: &mut State, } try!(commasep(s, Inconsistent, - segment.types.map_to_vec(|&t| t).as_slice(), + segment.types.map(|&t| t).as_slice(), print_type_ref)); } @@ -1677,7 +1675,7 @@ fn print_path(s: &mut State, path: &ast::Path, } fn print_bounded_path(s: &mut State, path: &ast::Path, - bounds: &Option>) + bounds: &Option>) -> io::IoResult<()> { print_path_(s, path, false, bounds) } @@ -1945,7 +1943,7 @@ pub fn print_proc_args(s: &mut State, decl: &ast::FnDecl) -> io::IoResult<()> { maybe_print_comment(s, decl.output.span.lo) } -pub fn print_bounds(s: &mut State, bounds: &OptVec, +pub fn print_bounds(s: &mut State, bounds: &Vec, print_colon_anyway: bool) -> io::IoResult<()> { if !bounds.is_empty() { try!(word(&mut s.s, ":")); @@ -2148,7 +2146,7 @@ pub fn print_ty_fn(s: &mut State, onceness: ast::Onceness, decl: &ast::FnDecl, id: Option, - opt_bounds: &Option>, + opt_bounds: &Option>, generics: Option<&ast::Generics>, opt_explicit_self: Option) -> io::IoResult<()> diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 2edfd367f4ef2..59568cf5ee15d 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -13,8 +13,8 @@ use ast::*; use ast; use codemap::Span; use parse; -use opt_vec; -use opt_vec::OptVec; + +use std::vec_ng::Vec; // Context-passing AST walker. Each overridden visit method has full control // over what happens with its node, it can do its own traversal of the node's @@ -55,8 +55,8 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics { } FkFnBlock(..) => { Generics { - lifetimes: opt_vec::Empty, - ty_params: opt_vec::Empty, + lifetimes: Vec::new(), + ty_params: Vec::new(), } } } @@ -370,7 +370,7 @@ pub fn walk_ty>(visitor: &mut V, typ: &Ty, env: E) { } fn walk_lifetime_decls>(visitor: &mut V, - lifetimes: &OptVec, + lifetimes: &Vec, env: E) { for l in lifetimes.iter() { visitor.visit_lifetime_decl(l, env.clone()); @@ -457,7 +457,7 @@ pub fn walk_foreign_item>(visitor: &mut V, } pub fn walk_ty_param_bounds>(visitor: &mut V, - bounds: &OptVec, + bounds: &Vec, env: E) { for bound in bounds.iter() { match *bound {