diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-12-18 13:43:46 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-12-18 20:02:12 +0530 |
| commit | 9e953df6f05765679db074b8895ed2178d75eb26 (patch) | |
| tree | e71174db4adcf4adf1709afb41ff3fc125d5c35b /src/libsyntax | |
| parent | 158a1bdd7dac47356a0cc44dd52308c7145f4afe (diff) | |
| parent | 6c87b191580be9ecd5a99a34ef97375af0b9d659 (diff) | |
| download | rust-9e953df6f05765679db074b8895ed2178d75eb26.tar.gz rust-9e953df6f05765679db074b8895ed2178d75eb26.zip | |
Rollup merge of #30420 - petrochenkov:owned2, r=nrc
Part of https://github.com/rust-lang/rust/pull/30095 not causing mysterious segfaults. r? @nrc
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/owned_slice.rs | 101 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ptr.rs | 106 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/util/move_map.rs | 6 |
11 files changed, 144 insertions, 177 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index de5595eebee..4b0ec8578c1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -50,7 +50,6 @@ use codemap::{Span, Spanned, DUMMY_SP, ExpnId}; use abi::Abi; use ext::base; use ext::tt::macro_parser; -use owned_slice::OwnedSlice; use parse::token::InternedString; use parse::token; use parse::lexer; @@ -261,8 +260,8 @@ impl PathParameters { pub fn none() -> PathParameters { AngleBracketedParameters(AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }) } @@ -334,10 +333,10 @@ pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. pub lifetimes: Vec<Lifetime>, /// The type parameters for this path segment, if present. - pub types: OwnedSlice<P<Ty>>, + pub types: P<[P<Ty>]>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo<A=Bar>`. - pub bindings: OwnedSlice<P<TypeBinding>>, + pub bindings: P<[P<TypeBinding>]>, } impl AngleBracketedParameterData { @@ -394,7 +393,7 @@ pub enum TraitBoundModifier { Maybe, } -pub type TyParamBounds = OwnedSlice<TyParamBound>; +pub type TyParamBounds = P<[TyParamBound]>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TyParam { @@ -410,7 +409,7 @@ pub struct TyParam { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { pub lifetimes: Vec<LifetimeDef>, - pub ty_params: OwnedSlice<TyParam>, + pub ty_params: P<[TyParam]>, pub where_clause: WhereClause, } @@ -430,7 +429,7 @@ impl Default for Generics { fn default() -> Generics { Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: WhereClause { id: DUMMY_NODE_ID, predicates: Vec::new(), @@ -466,7 +465,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P<Ty>, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: OwnedSlice<TyParamBound>, + pub bounds: TyParamBounds, } /// A lifetime predicate, e.g. `'a: 'b+'c` diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3d3d5347749..d38b771814c 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -12,7 +12,6 @@ use ast::*; use ast; use codemap; use codemap::Span; -use owned_slice::OwnedSlice; use parse::token; use print::pprust; use ptr::P; @@ -43,8 +42,8 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { identifier: identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }) } ), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cdc9cb02453..46a39b98058 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -14,7 +14,6 @@ use ast; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; use ext::base::ExtCtxt; -use owned_slice::OwnedSlice; use parse::token::special_idents; use parse::token::InternedString; use parse::token; @@ -56,7 +55,7 @@ pub trait AstBuilder { fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>; fn ty_path(&self, ast::Path) -> P<ast::Ty>; - fn ty_sum(&self, ast::Path, OwnedSlice<ast::TyParamBound>) -> P<ast::Ty>; + fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P<ast::Ty>; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>; fn ty_rptr(&self, span: Span, @@ -70,13 +69,13 @@ pub trait AstBuilder { fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>; fn ty_infer(&self, sp: Span) -> 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_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ; + fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ; fn typaram(&self, span: Span, id: ast::Ident, - bounds: OwnedSlice<ast::TyParamBound>, + bounds: ast::TyParamBounds, default: Option<P<ast::Ty>>) -> ast::TyParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; @@ -331,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { identifier: last_identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) }); ast::Path { @@ -369,8 +368,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { identifier: ident, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) }); @@ -399,7 +398,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ty(path.span, ast::TyPath(None, path)) } - fn ty_sum(&self, path: ast::Path, bounds: OwnedSlice<ast::TyParamBound>) -> P<ast::Ty> { + fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P<ast::Ty> { self.ty(path.span, ast::TyObjectSum(self.ty_path(path), bounds)) @@ -448,7 +447,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, span: Span, id: ast::Ident, - bounds: OwnedSlice<ast::TyParamBound>, + bounds: ast::TyParamBounds, default: Option<P<ast::Ty>>) -> ast::TyParam { ast::TyParam { ident: id, @@ -462,11 +461,11 @@ 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: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> { + fn ty_vars(&self, ty_params: &P<[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: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> { + fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> { ty_params .iter() .map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident)))) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index cd976884d2f..cd2210c71b8 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -23,7 +23,6 @@ use ast; use attr::{ThinAttributes, ThinAttributesExt}; use ast_util; use codemap::{respan, Span, Spanned}; -use owned_slice::OwnedSlice; use parse::token; use ptr::P; use util::small_vector::SmallVector; @@ -233,7 +232,7 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_ty_params(&mut self, tps: OwnedSlice<TyParam>) -> OwnedSlice<TyParam> { + fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> { noop_fold_ty_params(tps, self) } @@ -257,13 +256,13 @@ pub trait Folder : Sized { noop_fold_opt_lifetime(o_lt, self) } - fn fold_opt_bounds(&mut self, b: Option<OwnedSlice<TyParamBound>>) - -> Option<OwnedSlice<TyParamBound>> { + fn fold_opt_bounds(&mut self, b: Option<TyParamBounds>) + -> Option<TyParamBounds> { noop_fold_opt_bounds(b, self) } - fn fold_bounds(&mut self, b: OwnedSlice<TyParamBound>) - -> OwnedSlice<TyParamBound> { + fn fold_bounds(&mut self, b: TyParamBounds) + -> TyParamBounds { noop_fold_bounds(b, self) } @@ -714,8 +713,8 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam { } } -pub fn noop_fold_ty_params<T: Folder>(tps: OwnedSlice<TyParam>, fld: &mut T) - -> OwnedSlice<TyParam> { +pub fn noop_fold_ty_params<T: Folder>(tps: P<[TyParam]>, fld: &mut T) + -> P<[TyParam]> { tps.move_map(|tp| fld.fold_ty_param(tp)) } @@ -871,8 +870,8 @@ pub fn noop_fold_mt<T: Folder>(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutT } } -pub fn noop_fold_opt_bounds<T: Folder>(b: Option<OwnedSlice<TyParamBound>>, folder: &mut T) - -> Option<OwnedSlice<TyParamBound>> { +pub fn noop_fold_opt_bounds<T: Folder>(b: Option<TyParamBounds>, folder: &mut T) + -> Option<TyParamBounds> { b.map(|bounds| folder.fold_bounds(bounds)) } diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 83369689a94..33a3d578598 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -8,100 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::default::Default; -use std::fmt; -use std::iter::{IntoIterator, FromIterator}; -use std::ops::Deref; -use std::slice; -use std::vec; -use serialize::{Encodable, Decodable, Encoder, Decoder}; - -/// A non-growable owned slice. This is a separate type to allow the -/// representation to change. -#[derive(Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct OwnedSlice<T> { - data: Box<[T]> -} - -impl<T:fmt::Debug> fmt::Debug for OwnedSlice<T> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - self.data.fmt(fmt) - } -} - -impl<T> OwnedSlice<T> { - pub fn empty() -> OwnedSlice<T> { - OwnedSlice { data: Box::new([]) } - } - - #[inline(never)] - pub fn from_vec(v: Vec<T>) -> OwnedSlice<T> { - OwnedSlice { data: v.into_boxed_slice() } - } - - #[inline(never)] - pub fn into_vec(self) -> Vec<T> { - self.data.into_vec() - } - - pub fn as_slice<'a>(&'a self) -> &'a [T] { - &*self.data - } - - pub fn move_iter(self) -> vec::IntoIter<T> { - self.into_vec().into_iter() - } - - pub fn map<U, F: FnMut(&T) -> U>(&self, f: F) -> OwnedSlice<U> { - self.iter().map(f).collect() - } -} - -impl<T> Deref for OwnedSlice<T> { - type Target = [T]; - - fn deref(&self) -> &[T] { - self.as_slice() - } -} - -impl<T> Default for OwnedSlice<T> { - fn default() -> OwnedSlice<T> { - OwnedSlice::empty() - } -} - -impl<T: Clone> Clone for OwnedSlice<T> { - fn clone(&self) -> OwnedSlice<T> { - OwnedSlice::from_vec(self.to_vec()) - } -} - -impl<T> FromIterator<T> for OwnedSlice<T> { - fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> OwnedSlice<T> { - OwnedSlice::from_vec(iter.into_iter().collect()) - } -} - -impl<'a, T> IntoIterator for &'a OwnedSlice<T> { - type Item = &'a T; - type IntoIter = slice::Iter<'a, T>; - fn into_iter(self) -> Self::IntoIter { - self.data.into_iter() - } -} - -impl<T: Encodable> Encodable for OwnedSlice<T> { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - Encodable::encode(&**self, s) - } -} - -impl<T: Decodable> Decodable for OwnedSlice<T> { - fn decode<D: Decoder>(d: &mut D) -> Result<OwnedSlice<T>, D::Error> { - Ok(OwnedSlice::from_vec(match Decodable::decode(d) { - Ok(t) => t, - Err(e) => return Err(e) - })) - } -} +/// A non-growable owned slice. +#[unstable(feature = "rustc_private", issue = "0")] +#[rustc_deprecated(since = "1.7.0", reason = "use `ptr::P<[T]>` instead")] +pub type OwnedSlice<T> = ::ptr::P<[T]>; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index ed87961e7f3..cff106f838a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -671,7 +671,6 @@ mod tests { use super::*; use std::rc::Rc; use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; - use owned_slice::OwnedSlice; use ast::{self, TokenTree}; use abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; @@ -947,7 +946,7 @@ mod tests { abi::Rust, ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b8c4d8d63b5..ebfcf8c5180 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -50,7 +50,7 @@ use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; -use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPtr}; +use ast::{TyParam, TyParamBounds, TyParen, TyPath, TyPtr}; use ast::{TyRptr, TyTup, TyU32, TyVec}; use ast::TypeTraitItem; use ast::{UnnamedField, UnsafeBlock}; @@ -73,7 +73,6 @@ use parse::{new_sub_parser_from_file, ParseSess}; use util::parser::{AssocOp, Fixity}; use print::pprust; use ptr::P; -use owned_slice::OwnedSlice; use parse::PResult; use std::collections::HashSet; @@ -751,7 +750,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_before_gt_or_return<T, F>(&mut self, sep: Option<token::Token>, mut f: F) - -> PResult<(OwnedSlice<T>, bool)> where + -> PResult<(P<[T]>, bool)> where F: FnMut(&mut Parser) -> PResult<Option<T>>, { let mut v = Vec::new(); @@ -772,7 +771,7 @@ impl<'a> Parser<'a> { if i % 2 == 0 { match try!(f(self)) { Some(result) => v.push(result), - None => return Ok((OwnedSlice::from_vec(v), true)) + None => return Ok((P::from_vec(v), true)) } } else { if let Some(t) = sep.as_ref() { @@ -781,7 +780,7 @@ impl<'a> Parser<'a> { } } - return Ok((OwnedSlice::from_vec(v), false)); + return Ok((P::from_vec(v), false)); } /// Parse a sequence bracketed by '<' and '>', stopping @@ -789,7 +788,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_before_gt<T, F>(&mut self, sep: Option<token::Token>, mut f: F) - -> PResult<OwnedSlice<T>> where + -> PResult<P<[T]>> where F: FnMut(&mut Parser) -> PResult<T>, { let (result, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, @@ -801,7 +800,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_gt<T, F>(&mut self, sep: Option<token::Token>, f: F) - -> PResult<OwnedSlice<T>> where + -> PResult<P<[T]>> where F: FnMut(&mut Parser) -> PResult<T>, { let v = try!(self.parse_seq_to_before_gt(sep, f)); @@ -812,7 +811,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_gt_or_return<T, F>(&mut self, sep: Option<token::Token>, f: F) - -> PResult<(OwnedSlice<T>, bool)> where + -> PResult<(P<[T]>, bool)> where F: FnMut(&mut Parser) -> PResult<Option<T>>, { let (v, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, f)); @@ -1076,7 +1075,7 @@ impl<'a> Parser<'a> { let other_bounds = if try!(self.eat(&token::BinOp(token::Plus)) ){ try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)) } else { - OwnedSlice::empty() + P::empty() }; let all_bounds = Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter() @@ -1709,8 +1708,8 @@ impl<'a> Parser<'a> { ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) } else if try!(self.eat(&token::OpenDelim(token::Paren)) ){ let lo = self.last_span.lo; @@ -1773,8 +1772,8 @@ impl<'a> Parser<'a> { identifier: identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }), }); @@ -3882,10 +3881,10 @@ impl<'a> Parser<'a> { // otherwise returns empty list. fn parse_colon_then_ty_param_bounds(&mut self, mode: BoundParsingMode) - -> PResult<OwnedSlice<TyParamBound>> + -> PResult<TyParamBounds> { if !try!(self.eat(&token::Colon) ){ - Ok(OwnedSlice::empty()) + Ok(P::empty()) } else { self.parse_ty_param_bounds(mode) } @@ -3897,7 +3896,7 @@ impl<'a> Parser<'a> { // and bound = 'region | trait_ref fn parse_ty_param_bounds(&mut self, mode: BoundParsingMode) - -> PResult<OwnedSlice<TyParamBound>> + -> PResult<TyParamBounds> { let mut result = vec!(); loop { @@ -3939,7 +3938,7 @@ impl<'a> Parser<'a> { } } - return Ok(OwnedSlice::from_vec(result)); + return Ok(P::from_vec(result)); } /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 08448f25187..1f296dc5d59 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -17,7 +17,6 @@ use ast::Attribute; use attr::ThinAttributesExt; use util::parser::AssocOp; use attr; -use owned_slice::OwnedSlice; use attr::{AttrMetaMethods, AttributeMethods}; use codemap::{self, CodeMap, BytePos}; use errors; @@ -1001,7 +1000,7 @@ impl<'a> State<'a> { ast::TyBareFn(ref f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), @@ -3024,7 +3023,7 @@ impl<'a> State<'a> { } let generics = ast::Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index 83e321f110c..1be0b08086d 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -37,14 +37,15 @@ //! Moreover, a switch to, e.g. `P<'a, T>` would be easy and mostly automated. use std::fmt::{self, Display, Debug}; -use std::hash::{Hash, Hasher}; +use std::iter::FromIterator; use std::ops::Deref; -use std::ptr; +use std::{ptr, slice, vec}; use serialize::{Encodable, Decodable, Encoder, Decoder}; /// An owned smart pointer. -pub struct P<T> { +#[derive(Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct P<T: ?Sized> { ptr: Box<T> } @@ -92,14 +93,6 @@ impl<T: 'static + Clone> Clone for P<T> { } } -impl<T: PartialEq> PartialEq for P<T> { - fn eq(&self, other: &P<T>) -> bool { - **self == **other - } -} - -impl<T: Eq> Eq for P<T> {} - impl<T: Debug> Debug for P<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Debug::fmt(&**self, f) @@ -111,19 +104,12 @@ impl<T: Display> Display for P<T> { } } -#[stable(feature = "rust1", since = "1.0.0")] impl<T> fmt::Pointer for P<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Pointer::fmt(&self.ptr, f) } } -impl<T: Hash> Hash for P<T> { - fn hash<H: Hasher>(&self, state: &mut H) { - (**self).hash(state); - } -} - impl<T: 'static + Decodable> Decodable for P<T> { fn decode<D: Decoder>(d: &mut D) -> Result<P<T>, D::Error> { Decodable::decode(d).map(P) @@ -135,3 +121,87 @@ impl<T: Encodable> Encodable for P<T> { (**self).encode(s) } } + + +impl<T:fmt::Debug> fmt::Debug for P<[T]> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + self.ptr.fmt(fmt) + } +} + +impl<T> P<[T]> { + pub fn empty() -> P<[T]> { + P { ptr: Default::default() } + } + + #[inline(never)] + pub fn from_vec(v: Vec<T>) -> P<[T]> { + P { ptr: v.into_boxed_slice() } + } + + #[inline(never)] + pub fn into_vec(self) -> Vec<T> { + self.ptr.into_vec() + } + + pub fn as_slice<'a>(&'a self) -> &'a [T] { + &*self.ptr + } + + pub fn move_iter(self) -> vec::IntoIter<T> { + self.into_vec().into_iter() + } + + pub fn map<U, F: FnMut(&T) -> U>(&self, f: F) -> P<[U]> { + self.iter().map(f).collect() + } +} + +impl<T> Deref for P<[T]> { + type Target = [T]; + + fn deref(&self) -> &[T] { + self.as_slice() + } +} + +impl<T> Default for P<[T]> { + fn default() -> P<[T]> { + P::empty() + } +} + +impl<T: Clone> Clone for P<[T]> { + fn clone(&self) -> P<[T]> { + P::from_vec(self.to_vec()) + } +} + +impl<T> FromIterator<T> for P<[T]> { + fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> P<[T]> { + P::from_vec(iter.into_iter().collect()) + } +} + +impl<'a, T> IntoIterator for &'a P<[T]> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + self.ptr.into_iter() + } +} + +impl<T: Encodable> Encodable for P<[T]> { + fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { + Encodable::encode(&**self, s) + } +} + +impl<T: Decodable> Decodable for P<[T]> { + fn decode<D: Decoder>(d: &mut D) -> Result<P<[T]>, D::Error> { + Ok(P::from_vec(match Decodable::decode(d) { + Ok(t) => t, + Err(e) => return Err(e) + })) + } +} diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 9e1d80b3f0d..9a6d1f8fdab 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -32,7 +32,6 @@ use ext::expand::ExpansionConfig; use fold::Folder; use util::move_map::MoveMap; use fold; -use owned_slice::OwnedSlice; use parse::token::{intern, InternedString}; use parse::{token, ParseSess}; use print::pprust; diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/move_map.rs index 95c24c66630..e1078b719bf 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/move_map.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use owned_slice::OwnedSlice; - use std::ptr; pub trait MoveMap<T>: Sized { @@ -69,11 +67,11 @@ impl<T> MoveMap<T> for Vec<T> { } } -impl<T> MoveMap<T> for OwnedSlice<T> { +impl<T> MoveMap<T> for ::ptr::P<[T]> { fn move_flat_map<F, I>(self, f: F) -> Self where F: FnMut(T) -> I, I: IntoIterator<Item=T> { - OwnedSlice::from_vec(self.into_vec().move_flat_map(f)) + ::ptr::P::from_vec(self.into_vec().move_flat_map(f)) } } |
