diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/ty.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/opt_vec.rs | 174 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 7 |
13 files changed, 85 insertions, 267 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d1d9ae2322d..0f81791aea4 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,7 @@ use codemap::{Span, Spanned, DUMMY_SP}; use abi::AbiSet; use ast_util; -use opt_vec::OptVec; +use owned_slice::OwnedSlice; use parse::token::{InternedString, special_idents, str_to_ident}; use parse::token; @@ -143,7 +143,7 @@ pub struct PathSegment { /// The lifetime parameters for this path segment. lifetimes: Vec<Lifetime>, /// The type parameters for this path segment, if present. - types: OptVec<P<Ty>>, + types: OwnedSlice<P<Ty>>, } pub type CrateNum = u32; @@ -180,14 +180,14 @@ pub enum TyParamBound { pub struct TyParam { ident: Ident, id: NodeId, - bounds: OptVec<TyParamBound>, + bounds: OwnedSlice<TyParamBound>, default: Option<P<Ty>> } #[deriving(Clone, Eq, Encodable, Decodable, Hash)] pub struct Generics { lifetimes: Vec<Lifetime>, - ty_params: OptVec<TyParam>, + ty_params: OwnedSlice<TyParam>, } impl Generics { @@ -799,7 +799,7 @@ 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<OptVec<TyParamBound>>, + bounds: Option<OwnedSlice<TyParamBound>>, } #[deriving(Eq, Encodable, Decodable, Hash)] @@ -823,7 +823,7 @@ pub enum Ty_ { TyClosure(@ClosureTy), TyBareFn(@BareFnTy), TyTup(Vec<P<Ty>> ), - TyPath(Path, Option<OptVec<TyParamBound>>, NodeId), // for #7264; see above + TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above TyTypeof(@Expr), // TyInfer means the type should be inferred instead of it having been // specified. This can appear anywhere in a type. diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 656ca1c88ba..9d841255aa9 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -13,7 +13,7 @@ use ast; use ast_util; use codemap; use codemap::Span; -use opt_vec; +use owned_slice::OwnedSlice; use parse::token; use print::pprust; use visit::Visitor; @@ -196,7 +196,7 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), } @@ -318,7 +318,7 @@ pub static as_prec: uint = 12u; pub fn empty_generics() -> Generics { Generics {lifetimes: Vec::new(), - ty_params: opt_vec::Empty} + ty_params: OwnedSlice::empty()} } // ______________________________________________________________________ @@ -709,12 +709,12 @@ pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> { mod test { use ast::*; use super::*; - use opt_vec; + use owned_slice::OwnedSlice; fn ident_to_segment(id : &Ident) -> PathSegment { PathSegment {identifier:id.clone(), lifetimes: Vec::new(), - types: opt_vec::Empty} + types: OwnedSlice::empty()} } #[test] fn idents_name_eq_test() { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e860866ebf9..1106dc61db7 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -16,8 +16,7 @@ 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 owned_slice::OwnedSlice; use parse::token::special_idents; use parse::token; @@ -48,7 +47,7 @@ pub trait AstBuilder { fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy; fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>; - fn ty_path(&self, ast::Path, Option<OptVec<ast::TyParamBound>>) -> P<ast::Ty>; + fn ty_path(&self, ast::Path, Option<OwnedSlice<ast::TyParamBound>>) -> P<ast::Ty>; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>; fn ty_rptr(&self, span: Span, @@ -61,14 +60,14 @@ pub trait AstBuilder { fn ty_infer(&self, sp: Span) -> P<ast::Ty>; fn ty_nil(&self) -> P<ast::Ty>; - fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> ; - fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> ; + fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ; + fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ; fn ty_field_imm(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::TypeField; fn strip_bounds(&self, bounds: &Generics) -> Generics; fn typaram(&self, id: ast::Ident, - bounds: OptVec<ast::TyParamBound>, + bounds: OwnedSlice<ast::TyParamBound>, default: Option<P<ast::Ty>>) -> ast::TyParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; @@ -274,13 +273,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::PathSegment { identifier: ident, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } }).collect(); segments.push(ast::PathSegment { identifier: last_identifier, lifetimes: lifetimes, - types: opt_vec::from(types), + types: OwnedSlice::from_vec(types), }); ast::Path { span: sp, @@ -304,7 +303,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }) } - fn ty_path(&self, path: ast::Path, bounds: Option<OptVec<ast::TyParamBound>>) + fn ty_path(&self, path: ast::Path, bounds: Option<OwnedSlice<ast::TyParamBound>>) -> P<ast::Ty> { self.ty(path.span, ast::TyPath(path, bounds, ast::DUMMY_NODE_ID)) @@ -366,7 +365,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, id: ast::Ident, - bounds: OptVec<ast::TyParamBound>, + bounds: OwnedSlice<ast::TyParamBound>, default: Option<P<ast::Ty>>) -> ast::TyParam { ast::TyParam { ident: id, @@ -379,20 +378,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<ast::TyParam>) -> Vec<P<ast::Ty>> { - opt_vec::take_vec( - ty_params.map(|p| self.ty_ident(DUMMY_SP, p.ident))) + fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> { + ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect() } - fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> Vec<P<ast::Ty>> { - 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: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> { + ty_params.iter().map(|p| self.ty_path( + self.path_global(DUMMY_SP, vec!(p.ident)), None)).collect() } 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: OwnedSlice::empty(), ..*ty_param } }); Generics { ty_params: new_params, diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 45a20afab7d..8441fa719ea 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -12,7 +12,7 @@ use ast; use codemap::Span; use ext::base::*; use ext::base; -use opt_vec; +use owned_slice::OwnedSlice; use parse::token; use parse::token::{str_to_ident}; @@ -52,7 +52,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ast::PathSegment { identifier: res, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ) } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 7aa98a60781..89a8b2cd336 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -184,7 +184,7 @@ use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap; use codemap::Span; -use opt_vec; +use owned_slice::OwnedSlice; use parse::token::InternedString; use std::vec; @@ -362,7 +362,7 @@ impl<'a> TraitDef<'a> { let Generics { mut lifetimes, ty_params } = self.generics.to_generics(cx, self.span, type_ident, generics); - let mut ty_params = opt_vec::take_vec(ty_params); + let mut ty_params = ty_params.into_vec(); // Copy the lifetimes lifetimes.extend(&mut generics.lifetimes.iter().map(|l| *l)); @@ -380,11 +380,11 @@ impl<'a> TraitDef<'a> { // require the current trait bounds.push(cx.typarambound(trait_path.clone())); - cx.typaram(ty_param.ident, opt_vec::from(bounds), None) + cx.typaram(ty_param.ident, OwnedSlice::from_vec(bounds), None) })); let trait_generics = Generics { lifetimes: lifetimes, - ty_params: opt_vec::from(ty_params) + ty_params: OwnedSlice::from_vec(ty_params) }; // Create the reference to the trait. @@ -400,7 +400,7 @@ 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); + self_ty_params.into_vec()), None); let attr = cx.attribute( self.span, diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 5b29af185a4..bfdfba7ba78 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -18,7 +18,7 @@ use ast::{P,Expr,Generics,Ident}; use ext::base::ExtCtxt; use ext::build::AstBuilder; use codemap::{Span,respan}; -use opt_vec; +use owned_slice::OwnedSlice; /// The types of pointers pub enum PtrTy<'a> { @@ -116,11 +116,10 @@ fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifet } fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> { - let lifetimes = match *lt { - Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s).name)), - None => opt_vec::Empty - }; - opt_vec::take_vec(lifetimes) + match *lt { + Some(ref s) => vec!(cx.lifetime(span, cx.ident_of(*s).name)), + None => vec!() + } } impl<'a> Ty<'a> { @@ -173,7 +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)) + self_params.into_vec()) } Literal(ref p) => { p.to_path(cx, span, self_ty, self_generics) @@ -187,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<ast::Lifetime> , ty_params: Vec<ast::TyParam> ) -> Generics { Generics { lifetimes: lifetimes, - ty_params: opt_vec::from(ty_params) + ty_params: OwnedSlice::from_vec(ty_params) } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index e1a41471de4..0afde5be9a0 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -13,7 +13,7 @@ use ast; use ast_util; use codemap::{respan, Span, Spanned}; use parse::token; -use opt_vec::OptVec; +use owned_slice::OwnedSlice; use util::small_vector::SmallVector; // We may eventually want to be able to fold over type parameters, too. @@ -424,8 +424,8 @@ pub fn fold_ty_param<T: Folder>(tp: &TyParam, fld: &mut T) -> TyParam { } } -pub fn fold_ty_params<T: Folder>(tps: &OptVec<TyParam>, fld: &mut T) - -> OptVec<TyParam> { +pub fn fold_ty_params<T: Folder>(tps: &OwnedSlice<TyParam>, fld: &mut T) + -> OwnedSlice<TyParam> { tps.map(|tp| fold_ty_param(tp, fld)) } @@ -493,8 +493,8 @@ fn fold_mt<T: Folder>(mt: &MutTy, folder: &mut T) -> MutTy { } } -fn fold_opt_bounds<T: Folder>(b: &Option<OptVec<TyParamBound>>, folder: &mut T) - -> Option<OptVec<TyParamBound>> { +fn fold_opt_bounds<T: Folder>(b: &Option<OwnedSlice<TyParamBound>>, folder: &mut T) + -> Option<OwnedSlice<TyParamBound>> { b.as_ref().map(|bounds| { bounds.map(|bound| { fold_ty_param_bound(bound, folder) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index d0608ac2e30..70fb96e4c5f 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -50,7 +50,6 @@ pub mod syntax { } pub mod owned_slice; -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 425a5a9a5fa..00000000000 --- a/src/libsyntax/opt_vec.rs +++ /dev/null @@ -1,174 +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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - * Defines a type OptVec<T> 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::slice; - -#[deriving(Clone, Encodable, Decodable, Hash)] -pub enum OptVec<T> { - Empty, - Vec(Vec<T> ) -} - -pub fn with<T>(t: T) -> OptVec<T> { - Vec(vec!(t)) -} - -pub fn from<T>(t: Vec<T> ) -> OptVec<T> { - if t.len() == 0 { - Empty - } else { - Vec(t) - } -} - -impl<T> OptVec<T> { - 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<U>(&self, op: |&T| -> U) -> OptVec<U> { - match *self { - Empty => Empty, - Vec(ref v) => Vec(v.map(op)) - } - } - - pub fn map_move<U>(self, op: |T| -> U) -> OptVec<U> { - 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() - } - } - - #[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<B>(&self, op: |&T| -> B) -> Vec<B> { - self.iter().map(op).collect() - } - - pub fn mapi_to_vec<B>(&self, op: |uint, &T| -> B) -> Vec<B> { - let mut index = 0; - self.map_to_vec(|a| { - let i = index; - index += 1; - op(i, a) - }) - } -} - -pub fn take_vec<T>(v: OptVec<T>) -> Vec<T> { - match v { - Empty => Vec::new(), - Vec(v) => v - } -} - -impl<A:Eq> Eq for OptVec<A> { - fn eq(&self, other: &OptVec<A>) -> 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<A>) -> bool { - !self.eq(other) - } -} - -impl<T> Default for OptVec<T> { - fn default() -> OptVec<T> { Empty } -} - -pub struct Items<'a, T> { - priv iter: Option<slice::Items<'a, T>> -} - -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<uint>) { - 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<A> FromIterator<A> for OptVec<A> { - fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> OptVec<A> { - let v: Vec<A> = iterator.collect(); - from(v) - } -} diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 286b44e5c80..eb6b462fb94 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -279,7 +279,7 @@ mod test { use std::io::MemWriter; use std::str; use codemap::{Span, BytePos, Spanned}; - use opt_vec; + use owned_slice::OwnedSlice; use ast; use abi; use parse::parser::Parser; @@ -312,7 +312,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("a"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }), @@ -331,12 +331,12 @@ mod test { ast::PathSegment { identifier: str_to_ident("a"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), }, ast::PathSegment { identifier: str_to_ident("b"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ) }), @@ -545,7 +545,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("d"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }), @@ -567,7 +567,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("b"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }), @@ -595,7 +595,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("b"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }, @@ -623,7 +623,7 @@ mod test { identifier: str_to_ident("int"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }, None, ast::DUMMY_NODE_ID), @@ -641,7 +641,7 @@ mod test { identifier: str_to_ident("b"), lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } ), }, @@ -661,7 +661,7 @@ mod test { abi::AbiSet::Rust(), ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), - ty_params: opt_vec::Empty, + ty_params: OwnedSlice::empty(), }, ast::P(ast::Block { view_items: Vec::new(), @@ -680,7 +680,7 @@ mod test { lifetimes: Vec::new(), types: - opt_vec::Empty + OwnedSlice::empty() } ), }), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3e2b88c1cf1..c8492cc4113 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -75,8 +75,7 @@ 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 owned_slice::OwnedSlice; use std::cell::Cell; use collections::HashSet; @@ -117,13 +116,13 @@ pub enum PathParsingMode { /// for the definition of a path segment.) struct PathSegmentAndBoundSet { segment: ast::PathSegment, - bound_set: Option<OptVec<TyParamBound>>, + bound_set: Option<OwnedSlice<TyParamBound>>, } /// A path paired with optional type bounds. pub struct PathAndBounds { path: ast::Path, - bounds: Option<OptVec<TyParamBound>>, + bounds: Option<OwnedSlice<TyParamBound>>, } enum ItemOrViewItem { @@ -630,7 +629,7 @@ impl<'a> Parser<'a> { &mut self, sep: Option<token::Token>, f: |&mut Parser| -> T) - -> OptVec<T> { + -> OwnedSlice<T> { let mut first = true; let mut v = Vec::new(); while self.token != token::GT @@ -644,14 +643,14 @@ impl<'a> Parser<'a> { } v.push(f(self)); } - return opt_vec::from(v); + return OwnedSlice::from_vec(v); } pub fn parse_seq_to_gt<T>( &mut self, sep: Option<token::Token>, f: |&mut Parser| -> T) - -> OptVec<T> { + -> OwnedSlice<T> { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; @@ -1531,7 +1530,7 @@ impl<'a> Parser<'a> { segment: ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), }, bound_set: bound_set }); @@ -1543,9 +1542,9 @@ impl<'a> Parser<'a> { if mode != NoTypesAllowed && self.eat(&token::LT) { let (lifetimes, types) = self.parse_generic_values_after_lt(); - (true, lifetimes, opt_vec::from(types)) + (true, lifetimes, OwnedSlice::from_vec(types)) } else { - (false, Vec::new(), opt_vec::Empty) + (false, Vec::new(), OwnedSlice::empty()) } }; @@ -3432,7 +3431,7 @@ impl<'a> Parser<'a> { // 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<OptVec<TyParamBound>> { + fn parse_optional_ty_param_bounds(&mut self) -> Option<OwnedSlice<TyParamBound>> { if !self.eat(&token::COLON) { return None; } @@ -3462,7 +3461,7 @@ impl<'a> Parser<'a> { } } - return Some(opt_vec::from(result)); + return Some(OwnedSlice::from_vec(result)); } // matches typaram = IDENT optbounds ( EQ ty )? @@ -3515,7 +3514,7 @@ impl<'a> Parser<'a> { let result = self.parse_seq_to_gt( Some(token::COMMA), |p| p.parse_ty(false)); - (lifetimes, opt_vec::take_vec(result)) + (lifetimes, result.into_vec()) } fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool) @@ -4882,7 +4881,7 @@ impl<'a> Parser<'a> { ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } }).collect() }; @@ -4917,7 +4916,7 @@ impl<'a> Parser<'a> { ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } }).collect() }; @@ -4935,7 +4934,7 @@ impl<'a> Parser<'a> { ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } }).collect() }; @@ -4957,7 +4956,7 @@ impl<'a> Parser<'a> { ast::PathSegment { identifier: identifier, lifetimes: Vec::new(), - types: opt_vec::Empty, + types: OwnedSlice::empty(), } }).collect() }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1b8f48861aa..9cecd5f6c2b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -12,8 +12,7 @@ use abi::AbiSet; use ast::{P, RegionTyParamBound, TraitTyParamBound, Required, Provided}; use ast; use ast_util; -use opt_vec::OptVec; -use opt_vec; +use owned_slice::OwnedSlice; use attr::{AttrMetaMethods, AttributeMethods}; use codemap::{CodeMap, BytePos}; use codemap; @@ -478,7 +477,7 @@ impl<'a> State<'a> { ast::TyBareFn(f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty + ty_params: OwnedSlice::empty() }; try!(self.print_ty_fn(Some(f.abis), None, &None, f.purity, ast::Many, f.decl, None, &None, @@ -487,7 +486,7 @@ impl<'a> State<'a> { ast::TyClosure(f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: opt_vec::Empty + ty_params: OwnedSlice::empty() }; try!(self.print_ty_fn(None, Some(f.sigil), &f.region, f.purity, f.onceness, f.decl, None, &f.bounds, @@ -1518,7 +1517,7 @@ impl<'a> State<'a> { fn print_path_(&mut self, path: &ast::Path, colons_before_params: bool, - opt_bounds: &Option<OptVec<ast::TyParamBound>>) + opt_bounds: &Option<OwnedSlice<ast::TyParamBound>>) -> IoResult<()> { try!(self.maybe_print_comment(path.span.lo)); if path.global { @@ -1564,7 +1563,7 @@ impl<'a> State<'a> { } try!(self.commasep( Inconsistent, - segment.types.map_to_vec(|&t| t).as_slice(), + segment.types.as_slice(), |s, ty| s.print_type_ref(ty))); } @@ -1580,7 +1579,7 @@ impl<'a> State<'a> { } fn print_bounded_path(&mut self, path: &ast::Path, - bounds: &Option<OptVec<ast::TyParamBound>>) + bounds: &Option<OwnedSlice<ast::TyParamBound>>) -> IoResult<()> { self.print_path_(path, false, bounds) } @@ -1826,7 +1825,7 @@ impl<'a> State<'a> { self.maybe_print_comment(decl.output.span.lo) } - pub fn print_bounds(&mut self, bounds: &OptVec<ast::TyParamBound>, + pub fn print_bounds(&mut self, bounds: &OwnedSlice<ast::TyParamBound>, print_colon_anyway: bool) -> IoResult<()> { if !bounds.is_empty() { try!(word(&mut self.s, ":")); @@ -2028,7 +2027,7 @@ impl<'a> State<'a> { onceness: ast::Onceness, decl: &ast::FnDecl, id: Option<ast::Ident>, - opt_bounds: &Option<OptVec<ast::TyParamBound>>, + opt_bounds: &Option<OwnedSlice<ast::TyParamBound>>, generics: Option<&ast::Generics>, opt_explicit_self: Option<ast::ExplicitSelf_>) -> IoResult<()> { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 482bac77777..de3eb1b9b8d 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -13,8 +13,7 @@ use ast::*; use ast; use codemap::Span; use parse; -use opt_vec; -use opt_vec::OptVec; +use owned_slice::OwnedSlice; // 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 @@ -56,7 +55,7 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics { FkFnBlock(..) => { Generics { lifetimes: Vec::new(), - ty_params: opt_vec::Empty, + ty_params: OwnedSlice::empty(), } } } @@ -457,7 +456,7 @@ pub fn walk_foreign_item<E: Clone, V: Visitor<E>>(visitor: &mut V, } pub fn walk_ty_param_bounds<E: Clone, V: Visitor<E>>(visitor: &mut V, - bounds: &OptVec<TyParamBound>, + bounds: &OwnedSlice<TyParamBound>, env: E) { for bound in bounds.iter() { match *bound { |
