From 546c052d225d41cd31f610e87a20f15cd0fa8e3c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Apr 2016 04:12:02 +0300 Subject: syntax: Get rid of token::IdentStyle --- src/libsyntax/parse/mod.rs | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'src/libsyntax/parse/mod.rs') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 29b1d5b9aff..7534683a206 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -734,9 +734,9 @@ mod tests { match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) { ( 4, - Some(&TokenTree::Token(_, token::Ident(name_macro_rules, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(name_macro_rules))), Some(&TokenTree::Token(_, token::Not)), - Some(&TokenTree::Token(_, token::Ident(name_zip, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(name_zip))), Some(&TokenTree::Delimited(_, ref macro_delimed)), ) if name_macro_rules.name.as_str() == "macro_rules" @@ -755,7 +755,7 @@ mod tests { ( 2, Some(&TokenTree::Token(_, token::Dollar)), - Some(&TokenTree::Token(_, token::Ident(ident, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(ident))), ) if first_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, @@ -766,7 +766,7 @@ mod tests { ( 2, Some(&TokenTree::Token(_, token::Dollar)), - Some(&TokenTree::Token(_, token::Ident(ident, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(ident))), ) if second_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, @@ -785,26 +785,17 @@ mod tests { let tts = string_to_tts("fn a (b : i32) { b; }".to_string()); let expected = vec![ - TokenTree::Token(sp(0, 2), - token::Ident(str_to_ident("fn"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(3, 4), - token::Ident(str_to_ident("a"), - token::IdentStyle::Plain)), + TokenTree::Token(sp(0, 2), token::Ident(str_to_ident("fn"))), + TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Delimited( sp(5, 14), Rc::new(ast::Delimited { delim: token::DelimToken::Paren, open_span: sp(5, 6), tts: vec![ - TokenTree::Token(sp(6, 7), - token::Ident(str_to_ident("b"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(8, 9), - token::Colon), - TokenTree::Token(sp(10, 13), - token::Ident(str_to_ident("i32"), - token::IdentStyle::Plain)), + TokenTree::Token(sp(6, 7), token::Ident(str_to_ident("b"))), + TokenTree::Token(sp(8, 9), token::Colon), + TokenTree::Token(sp(10, 13), token::Ident(str_to_ident("i32"))), ], close_span: sp(13, 14), })), @@ -814,11 +805,8 @@ mod tests { delim: token::DelimToken::Brace, open_span: sp(15, 16), tts: vec![ - TokenTree::Token(sp(17, 18), - token::Ident(str_to_ident("b"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(18, 19), - token::Semi) + TokenTree::Token(sp(17, 18), token::Ident(str_to_ident("b"))), + TokenTree::Token(sp(18, 19), token::Semi), ], close_span: sp(20, 21), })) -- cgit 1.4.1-3-g733a5 From 9108fb7bae11f18715d971eeae1e5ca84662e1ee Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 22 Apr 2016 23:43:14 +0300 Subject: Remove some old code from libsyntax --- src/libsyntax/ast.rs | 6 ++--- src/libsyntax/lib.rs | 1 - src/libsyntax/owned_slice.rs | 14 ----------- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 4 +-- src/libsyntax/print/pprust.rs | 4 +-- src/libsyntax/ptr.rs | 42 +++++-------------------------- src/libsyntax_ext/deriving/generic/mod.rs | 8 +++--- src/libsyntax_ext/deriving/generic/ty.rs | 7 +++--- 9 files changed, 21 insertions(+), 67 deletions(-) delete mode 100644 src/libsyntax/owned_slice.rs (limited to 'src/libsyntax/parse/mod.rs') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6bcd8085315..5064bcba4c3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -248,8 +248,8 @@ impl PathParameters { pub fn none() -> PathParameters { PathParameters::AngleBracketed(AngleBracketedParameterData { lifetimes: Vec::new(), - types: P::empty(), - bindings: P::empty(), + types: P::new(), + bindings: P::new(), }) } @@ -421,7 +421,7 @@ impl Default for Generics { fn default() -> Generics { Generics { lifetimes: Vec::new(), - ty_params: P::empty(), + ty_params: P::new(), where_clause: WhereClause { id: DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index f38720c3e50..6cfa1e9847b 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -97,7 +97,6 @@ pub mod config; pub mod entry; pub mod feature_gate; pub mod fold; -pub mod owned_slice; pub mod parse; pub mod ptr; pub mod show_span; diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs deleted file mode 100644 index 33a3d578598..00000000000 --- a/src/libsyntax/owned_slice.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2014 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. - -/// 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 = ::ptr::P<[T]>; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 7534683a206..c2050d2a8f4 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -925,7 +925,7 @@ mod tests { Abi::Rust, ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), - ty_params: P::empty(), + ty_params: P::new(), 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 7842d9dca53..4fb423f787e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1160,7 +1160,7 @@ impl<'a> Parser<'a> { let other_bounds = if self.eat(&token::BinOp(token::Plus)) { self.parse_ty_param_bounds(BoundParsingMode::Bare)? } else { - P::empty() + P::new() }; let all_bounds = Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter() @@ -4239,7 +4239,7 @@ impl<'a> Parser<'a> { -> PResult<'a, TyParamBounds> { if !self.eat(&token::Colon) { - Ok(P::empty()) + Ok(P::new()) } else { self.parse_ty_param_bounds(mode) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 798477d8fe5..1c6ecbd3b5a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -995,7 +995,7 @@ impl<'a> State<'a> { ast::TyKind::BareFn(ref f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: P::empty(), + ty_params: P::new(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), @@ -3011,7 +3011,7 @@ impl<'a> State<'a> { } let generics = ast::Generics { lifetimes: Vec::new(), - ty_params: P::empty(), + ty_params: P::new(), 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 fda9741d35c..9d04cb75daa 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -83,10 +83,10 @@ impl P { } } -impl Deref for P { +impl Deref for P { type Target = T; - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { &self.ptr } } @@ -97,11 +97,12 @@ impl Clone for P { } } -impl Debug for P { +impl Debug for P { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Debug::fmt(&**self, f) + Debug::fmt(&self.ptr, f) } } + impl Display for P { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Display::fmt(&**self, f) @@ -126,19 +127,8 @@ impl Encodable for P { } } - -impl fmt::Debug for P<[T]> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - self.ptr.fmt(fmt) - } -} - impl P<[T]> { pub fn new() -> P<[T]> { - P::empty() - } - - pub fn empty() -> P<[T]> { P { ptr: Default::default() } } @@ -151,31 +141,11 @@ impl P<[T]> { pub fn into_vec(self) -> Vec { self.ptr.into_vec() } - - pub fn as_slice<'a>(&'a self) -> &'a [T] { - &self.ptr - } - - pub fn move_iter(self) -> vec::IntoIter { - self.into_vec().into_iter() - } - - pub fn map U>(&self, f: F) -> P<[U]> { - self.iter().map(f).collect() - } -} - -impl Deref for P<[T]> { - type Target = [T]; - - fn deref(&self) -> &[T] { - self.as_slice() - } } impl Default for P<[T]> { fn default() -> P<[T]> { - P::empty() + P::new() } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a3e70cc6321..5251b0d08d4 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -525,7 +525,7 @@ impl<'a> TraitDef<'a> { span: self.span, bound_lifetimes: wb.bound_lifetimes.clone(), bounded_ty: wb.bounded_ty.clone(), - bounds: P::from_vec(wb.bounds.iter().cloned().collect()) + bounds: wb.bounds.iter().cloned().collect(), }) } ast::WherePredicate::RegionPredicate(ref rb) => { @@ -595,9 +595,9 @@ impl<'a> TraitDef<'a> { let trait_ref = cx.trait_ref(trait_path); // Create the type parameters on the `self` path. - let self_ty_params = generics.ty_params.map(|ty_param| { + let self_ty_params = generics.ty_params.iter().map(|ty_param| { cx.ty_ident(self.span, ty_param.ident) - }); + }).collect(); let self_lifetimes: Vec = generics.lifetimes @@ -608,7 +608,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, - self_ty_params.into_vec(), Vec::new())); + self_ty_params, Vec::new())); let attr = cx.attribute( self.span, diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index e19febe2a12..e31d45d91a5 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -169,15 +169,14 @@ impl<'a> Ty<'a> { -> ast::Path { match *self { Self_ => { - let self_params = self_generics.ty_params.map(|ty_param| { + let self_params = self_generics.ty_params.iter().map(|ty_param| { cx.ty_ident(span, ty_param.ident) - }); + }).collect(); let lifetimes = self_generics.lifetimes.iter() .map(|d| d.lifetime) .collect(); - cx.path_all(span, false, vec!(self_ty), lifetimes, - self_params.into_vec(), Vec::new()) + cx.path_all(span, false, vec![self_ty], lifetimes, self_params, Vec::new()) } Literal(ref p) => { p.to_path(cx, span, self_ty, self_generics) -- cgit 1.4.1-3-g733a5