From c1ba80f1fdd59fde23a3380836b1305079de99dd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 23 Nov 2016 11:25:57 -0800 Subject: [PATCH] Update to syntex 0.51 --- Cargo.toml | 2 +- src/attr.rs | 204 ++++++++++++++++++++++++------------- src/expr.rs | 8 +- src/generics.rs | 8 +- src/ident.rs | 4 +- src/item.rs | 9 +- src/lib.rs | 18 ++-- src/lifetime.rs | 14 +-- src/lit.rs | 14 +-- src/mac.rs | 4 +- src/name.rs | 32 ------ src/path.rs | 6 +- src/str.rs | 38 ------- src/symbol.rs | 38 +++++++ src/ty.rs | 6 +- src/ty_param.rs | 4 +- src/where_predicate.rs | 6 +- tests/test_attr.rs | 31 +++--- tests/test_item.rs | 36 ++++--- tests/test_lit.rs | 2 +- tests/test_struct_field.rs | 54 +++++----- 21 files changed, 278 insertions(+), 260 deletions(-) delete mode 100644 src/name.rs delete mode 100644 src/str.rs create mode 100644 src/symbol.rs diff --git a/Cargo.toml b/Cargo.toml index 18ab37d56..fbbf500ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ with-syntex = ["syntex_syntax"] unstable-testing = ["clippy", "compiletest_rs"] [dependencies] -syntex_syntax = { version = "^0.50.0", optional = true } +syntex_syntax = { version = "^0.51.0", optional = true } clippy = { version = "0.*", optional = true } compiletest_rs = { version = "^0.2.0", optional = true } diff --git a/src/attr.rs b/src/attr.rs index 3f2fef047..9c2b62121 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -3,12 +3,12 @@ use std::iter::IntoIterator; use syntax::ast; use syntax::attr; use syntax::codemap::{DUMMY_SP, Span, respan}; -use syntax::parse::token; use syntax::ptr::P; +use syntax::symbol::Symbol; use invoke::{Invoke, Identity}; use lit::LitBuilder; -use str::ToInternedString; +use symbol::ToSymbol; ////////////////////////////////////////////////////////////////////////////// @@ -47,40 +47,49 @@ impl AttrBuilder self } - pub fn build_meta_item(self, item: P) -> F::Result { - let attr = respan(self.span, ast::Attribute_ { + pub fn outer(mut self) -> Self { + self.style = ast::AttrStyle::Outer; + self + } + + pub fn build_meta_item(self, item: ast::MetaItem) -> F::Result { + let attr = ast::Attribute { id: attr::mk_attr_id(), style: self.style, value: item, is_sugared_doc: self.is_sugared_doc, - }); + span: self.span, + }; self.callback.invoke(attr) } - pub fn build_meta_item_(self, item: ast::MetaItemKind) -> F::Result { - let item = P(respan(self.span, item)); - self.build_meta_item(item) + pub fn named(self, name: N) -> NamedAttrBuilder + where N: ToSymbol + { + NamedAttrBuilder::with_callback(name, self) } pub fn word(self, word: T) -> F::Result - where T: ToInternedString + where T: ToSymbol { - self.build_meta_item_(ast::MetaItemKind::Word(word.to_interned_string())) + let item = ast::MetaItem { + name: word.to_symbol(), + node: ast::MetaItemKind::Word, + span: self.span, + }; + self.build_meta_item(item) } pub fn list(self, word: T) -> AttrListBuilder - where T: ToInternedString + where T: ToSymbol { AttrListBuilder::with_callback(word, self) } pub fn name_value(self, name: T) -> LitBuilder> - where T: ToInternedString, + where T: ToSymbol, { - LitBuilder::with_callback(AttrNameValueBuilder { - callback: self, - name: name.to_interned_string(), - }) + LitBuilder::with_callback(AttrNameValueBuilder::with_callback(name, self)) } pub fn automatically_derived(self) -> F::Result { @@ -97,35 +106,35 @@ impl AttrBuilder pub fn allow(self, iter: I) -> F::Result where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { self.list("allow").words(iter).build() } pub fn warn(self, iter: I) -> F::Result where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { self.list("warn").words(iter).build() } pub fn deny(self, iter: I) -> F::Result where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { self.list("deny").words(iter).build() } pub fn features(self, iter: I) -> F::Result where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { self.list("feature").words(iter).build() } pub fn plugins(self, iter: I) -> F::Result where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { self.list("plugin").words(iter).build() } @@ -136,30 +145,64 @@ impl AttrBuilder * comment. */ pub fn doc(mut self, doc: T) -> F::Result - where T: ToInternedString, + where T: ToSymbol, { self.is_sugared_doc = true; self.name_value("doc").str(doc) } } -impl Invoke> for AttrBuilder +impl Invoke for AttrBuilder where F: Invoke, { type Result = F::Result; - fn invoke(self, item: P) -> F::Result { + fn invoke(self, item: ast::MetaItem) -> F::Result { self.build_meta_item(item) } } -impl Invoke for AttrBuilder - where F: Invoke, +////////////////////////////////////////////////////////////////////////////// + +pub struct NamedAttrBuilder { + callback: F, + span: Span, + name: Symbol, +} + +impl NamedAttrBuilder + where F: Invoke { - type Result = F::Result; + pub fn with_callback(name: T, callback: F) -> Self + where T: ToSymbol + { + NamedAttrBuilder { + callback: callback, + span: DUMMY_SP, + name: name.to_symbol(), + } + } + + pub fn span(mut self, span: Span) -> Self { + self.span = span; + self + } + + pub fn word(self) -> F::Result { + let item = ast::MetaItem { + name: self.name, + node: ast::MetaItemKind::Word, + span: self.span, + }; + self.callback.invoke(item) + } + + pub fn list(self) -> AttrListBuilder { + AttrListBuilder::with_callback(self.name, self.callback).span(self.span) + } - fn invoke(self, item: ast::MetaItemKind) -> F::Result { - self.build_meta_item_(item) + pub fn name_value(self) -> LitBuilder> { + LitBuilder::with_callback(AttrNameValueBuilder::with_callback(self.name, self.callback)) } } @@ -168,20 +211,20 @@ impl Invoke for AttrBuilder pub struct AttrListBuilder { callback: F, span: Span, - name: token::InternedString, + name: Symbol, items: Vec, } impl AttrListBuilder - where F: Invoke>, + where F: Invoke, { pub fn with_callback(name: T, callback: F) -> Self - where T: ToInternedString, + where T: ToSymbol, { AttrListBuilder { callback: callback, span: DUMMY_SP, - name: name.to_interned_string(), + name: name.to_symbol(), items: vec![], } } @@ -192,7 +235,7 @@ impl AttrListBuilder } pub fn with_meta_items(mut self, iter: I) -> Self - where I: IntoIterator>, + where I: IntoIterator, { let span = self.span; self.items.extend(iter.into_iter().map(|meta_item| { @@ -201,91 +244,106 @@ impl AttrListBuilder self } - pub fn with_meta_items_(self, iter: I) -> Self - where I: IntoIterator, - { - let iter = iter.into_iter(); - let span = self.span; - self.with_meta_items(iter.map(|item| P(respan(span, item)))) - } - - pub fn with_meta_item(mut self, item: P) -> Self { + pub fn with_meta_item(mut self, item: ast::MetaItem) -> Self { self.items.push(respan(self.span, ast::NestedMetaItemKind::MetaItem(item))); self } - pub fn with_meta_item_kind(self, item: ast::MetaItemKind) -> Self { - let span = self.span; - self.with_meta_item(P(respan(span, item))) - } - pub fn words(self, iter: I) -> Self where I: IntoIterator, - T: ToInternedString, + T: ToSymbol, { let iter = iter.into_iter(); - self.with_meta_items_(iter.map(|word| ast::MetaItemKind::Word(word.to_interned_string()))) + let span = self.span; + self.with_meta_items(iter.map(|item| ast::MetaItem { + name: item.to_symbol(), + node: ast::MetaItemKind::Word, + span: span, + })) } pub fn word(self, word: T) -> Self - where T: ToInternedString, + where T: ToSymbol, { - self.with_meta_item_kind(ast::MetaItemKind::Word(word.to_interned_string())) + let span = self.span; + self.with_meta_item(ast::MetaItem { + name: word.to_symbol(), + node: ast::MetaItemKind::Word, + span: span, + }) } pub fn list(self, name: T) -> AttrListBuilder - where T: ToInternedString, + where T: ToSymbol, { AttrListBuilder::with_callback(name, self) } pub fn name_value(self, name: T) -> LitBuilder> - where T: ToInternedString, + where T: ToSymbol, { + let span = self.span; LitBuilder::with_callback(AttrNameValueBuilder { callback: self, - name: name.to_interned_string(), + name: name.to_symbol(), + span: span, }) } pub fn build(self) -> F::Result { - let item = respan(self.span, ast::MetaItemKind::List(self.name, self.items)); - self.callback.invoke(P(item)) + let item = ast::MetaItem { + name: self.name, + node: ast::MetaItemKind::List(self.items), + span: self.span, + }; + self.callback.invoke(item) } } -impl Invoke> for AttrListBuilder - where F: Invoke>, +impl Invoke for AttrListBuilder + where F: Invoke, { type Result = Self; - fn invoke(self, item: P) -> Self { + fn invoke(self, item: ast::MetaItem) -> Self { self.with_meta_item(item) } } -impl Invoke for AttrListBuilder - where F: Invoke>, -{ - type Result = Self; - - fn invoke(self, item: ast::MetaItemKind) -> Self { - self.with_meta_item_kind(item) - } -} - ////////////////////////////////////////////////////////////////////////////// pub struct AttrNameValueBuilder { callback: F, - name: token::InternedString, + span: Span, + name: Symbol, +} + +impl AttrNameValueBuilder { + pub fn with_callback(name: T, callback: F) -> Self + where T: ToSymbol + { + AttrNameValueBuilder { + callback: callback, + span: DUMMY_SP, + name: name.to_symbol(), + } + } + + pub fn span(mut self, span: Span) -> Self { + self.span = span; + self + } } -impl> Invoke> for AttrNameValueBuilder { +impl> Invoke> for AttrNameValueBuilder { type Result = F::Result; fn invoke(self, value: P) -> F::Result { - let item = ast::MetaItemKind::NameValue(self.name, (*value).clone()); + let item = ast::MetaItem { + name: self.name, + node: ast::MetaItemKind::NameValue((*value).clone()), + span: self.span, + }; self.callback.invoke(item) } } diff --git a/src/expr.rs b/src/expr.rs index e2ea38fb6..810fdb0c8 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -17,7 +17,7 @@ use mac::MacBuilder; use pat::PatBuilder; use path::{IntoPath, PathBuilder}; use qpath::QPathBuilder; -use str::ToInternedString; +use symbol::ToSymbol; use ty::TyBuilder; ////////////////////////////////////////////////////////////////////////////// @@ -172,19 +172,19 @@ impl ExprBuilder } pub fn f32(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { self.lit().f32(value) } pub fn f64(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { self.lit().f64(value) } pub fn str(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { self.lit().str(value) } diff --git a/src/generics.rs b/src/generics.rs index 4c27e429f..10cfffcb6 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -7,8 +7,8 @@ use syntax::ptr::P; use ident::ToIdent; use invoke::{Invoke, Identity}; use lifetime::{IntoLifetime, IntoLifetimeDef, LifetimeDefBuilder}; -use name::ToName; use path::IntoPath; +use symbol::ToSymbol; use ty_param::TyParamBuilder; use where_predicate::WherePredicateBuilder; @@ -77,7 +77,7 @@ impl GenericsBuilder pub fn with_lifetime_names(mut self, iter: I) -> Self where I: IntoIterator, - N: ToName, + N: ToSymbol, { for name in iter { self = self.lifetime_name(name); @@ -91,13 +91,13 @@ impl GenericsBuilder } pub fn lifetime_name(self, name: N) -> Self - where N: ToName, + where N: ToSymbol, { self.lifetime(name).build() } pub fn lifetime(self, name: N) -> LifetimeDefBuilder - where N: ToName, + where N: ToSymbol, { LifetimeDefBuilder::with_callback(name, self) } diff --git a/src/ident.rs b/src/ident.rs index 3148c37c3..d7d02efb0 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -1,6 +1,6 @@ use syntax::ast; -use name::ToName; +use symbol::ToSymbol; ////////////////////////////////////////////////////////////////////////////// @@ -22,7 +22,7 @@ impl ToIdent for ast::Name { impl<'a> ToIdent for &'a str { fn to_ident(&self) -> ast::Ident { - self.to_name().to_ident() + self.to_symbol().to_ident() } } diff --git a/src/item.rs b/src/item.rs index 9264304f4..cf2ed2f46 100644 --- a/src/item.rs +++ b/src/item.rs @@ -5,8 +5,8 @@ use std::iter::IntoIterator; use syntax::abi::Abi; use syntax::ast; use syntax::codemap::{DUMMY_SP, Span, respan}; -use syntax::parse::token::keywords; use syntax::ptr::P; +use syntax::symbol::keywords; use attr::AttrBuilder; use block::BlockBuilder; @@ -19,6 +19,7 @@ use mac::MacBuilder; use method::MethodSigBuilder; use path::PathBuilder; use struct_field::StructFieldBuilder; +use symbol::ToSymbol; use ty::TyBuilder; use ty_param::TyParamBoundBuilder; use variant::VariantBuilder; @@ -730,8 +731,10 @@ pub struct ItemExternCrateBuilder { impl ItemExternCrateBuilder where F: Invoke>, { - pub fn with_name(self, name: ast::Name) -> F::Result { - let extern_ = ast::ItemKind::ExternCrate(Some(name)); + pub fn with_name(self, name: N) -> F::Result + where N: ToSymbol + { + let extern_ = ast::ItemKind::ExternCrate(Some(name.to_symbol())); self.builder.build_item_kind(self.id, extern_) } diff --git a/src/lib.rs b/src/lib.rs index b48f2dd5a..6eb4bece5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ extern crate syntax; use syntax::ast; use syntax::codemap::{DUMMY_SP, Span}; -use syntax::parse::token; pub mod arm; pub mod attr; @@ -27,14 +26,13 @@ pub mod lifetime; pub mod lit; pub mod mac; pub mod method; -pub mod name; pub mod pat; pub mod path; pub mod qpath; pub mod self_; pub mod stmt; -pub mod str; pub mod struct_field; +pub mod symbol; pub mod ty; pub mod ty_param; pub mod variant; @@ -60,10 +58,10 @@ impl AstBuilder { self } - pub fn interned_string(&self, s: S) -> token::InternedString - where S: str::ToInternedString + pub fn interned_string(&self, s: S) -> syntax::symbol::InternedString + where S: symbol::ToSymbol { - s.to_interned_string() + s.to_symbol().as_str() } pub fn id(&self, id: I) -> ast::Ident @@ -72,10 +70,10 @@ impl AstBuilder { id.to_ident() } - pub fn name(&self, name: N) -> ast::Name - where N: name::ToName + pub fn symbol(&self, name: N) -> syntax::symbol::Symbol + where N: symbol::ToSymbol { - name.to_name() + name.to_symbol() } pub fn lifetime(&self, lifetime: L) -> ast::Lifetime @@ -109,7 +107,7 @@ impl AstBuilder { } pub fn lifetime_def(&self, name: N) -> lifetime::LifetimeDefBuilder - where N: name::ToName, + where N: symbol::ToSymbol, { lifetime::LifetimeDefBuilder::new(name) } diff --git a/src/lifetime.rs b/src/lifetime.rs index 4f364ee40..20ee84556 100644 --- a/src/lifetime.rs +++ b/src/lifetime.rs @@ -2,7 +2,7 @@ use syntax::ast; use syntax::codemap::{DUMMY_SP}; use invoke::{Invoke, Identity}; -use name::ToName; +use symbol::ToSymbol; ////////////////////////////////////////////////////////////////////////////// @@ -21,7 +21,7 @@ impl<'a> IntoLifetime for &'a str { ast::Lifetime { id: ast::DUMMY_NODE_ID, span: DUMMY_SP, - name: self.to_name(), + name: self.to_symbol(), } } } @@ -70,7 +70,7 @@ pub struct LifetimeDefBuilder { impl LifetimeDefBuilder { pub fn new(name: N) -> Self - where N: ToName, + where N: ToSymbol, { LifetimeDefBuilder::with_callback(name, Identity) } @@ -80,12 +80,12 @@ impl LifetimeDefBuilder where F: Invoke, { pub fn with_callback(name: N, callback: F) -> Self - where N: ToName, + where N: ToSymbol, { let lifetime = ast::Lifetime { id: ast::DUMMY_NODE_ID, span: DUMMY_SP, - name: name.to_name(), + name: name.to_symbol(), }; LifetimeDefBuilder { @@ -96,12 +96,12 @@ impl LifetimeDefBuilder } pub fn bound(mut self, name: N) -> Self - where N: ToName, + where N: ToSymbol, { let lifetime = ast::Lifetime { id: ast::DUMMY_NODE_ID, span: DUMMY_SP, - name: name.to_name(), + name: name.to_symbol(), }; self.bounds.push(lifetime); diff --git a/src/lit.rs b/src/lit.rs index 62f5371f4..6ca5f7a85 100644 --- a/src/lit.rs +++ b/src/lit.rs @@ -7,7 +7,7 @@ use syntax::ptr::P; use invoke::{Invoke, Identity}; -use str::ToInternedString; +use symbol::ToSymbol; ////////////////////////////////////////////////////////////////////////////// @@ -113,19 +113,19 @@ impl LitBuilder } fn build_float(self, value: S, ty: ast::FloatTy) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { - self.build_lit(ast::LitKind::Float(value.to_interned_string(), ty)) + self.build_lit(ast::LitKind::Float(value.to_symbol(), ty)) } pub fn f32(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { self.build_float(value, ast::FloatTy::F32) } pub fn f64(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { self.build_float(value, ast::FloatTy::F64) } @@ -139,9 +139,9 @@ impl LitBuilder } pub fn str(self, value: S) -> F::Result - where S: ToInternedString, + where S: ToSymbol, { - let value = value.to_interned_string(); + let value = value.to_symbol(); self.build_lit(ast::LitKind::Str(value, ast::StrStyle::Cooked)) } diff --git a/src/mac.rs b/src/mac.rs index cdc56e00d..28df86dff 100644 --- a/src/mac.rs +++ b/src/mac.rs @@ -9,8 +9,8 @@ use syntax::tokenstream::TokenTree; use expr::ExprBuilder; use invoke::{Invoke, Identity}; -use name::ToName; use path::PathBuilder; +use symbol::ToSymbol; /// A Builder for macro invocations. /// @@ -130,7 +130,7 @@ fn make_ext_ctxt<'a>(sess: &'a ParseSess, let info = codemap::ExpnInfo { call_site: codemap::DUMMY_SP, callee: codemap::NameAndSpan { - format: codemap::MacroAttribute("test".to_name()), + format: codemap::MacroAttribute("test".to_symbol()), allow_internal_unstable: false, span: None } diff --git a/src/name.rs b/src/name.rs deleted file mode 100644 index 45ba17271..000000000 --- a/src/name.rs +++ /dev/null @@ -1,32 +0,0 @@ -use syntax::ast; -use syntax::parse::token; - -////////////////////////////////////////////////////////////////////////////// - -pub trait ToName { - fn to_name(&self) -> ast::Name; -} - -impl ToName for ast::Name { - fn to_name(&self) -> ast::Name { - *self - } -} - -impl<'a> ToName for &'a str { - fn to_name(&self) -> ast::Name { - token::intern(*self) - } -} - -impl<'a, T> ToName for &'a T where T: ToName { - fn to_name(&self) -> ast::Name { - (**self).to_name() - } -} - -impl<'a, T> ToName for &'a mut T where T: ToName { - fn to_name(&self) -> ast::Name { - (**self).to_name() - } -} diff --git a/src/path.rs b/src/path.rs index c1ec86c63..5e0b2cfae 100644 --- a/src/path.rs +++ b/src/path.rs @@ -7,7 +7,7 @@ use syntax::ptr::P; use invoke::{Invoke, Identity}; use ident::ToIdent; -use name::ToName; +use symbol::ToSymbol; use ty::TyBuilder; use lifetime::IntoLifetime; @@ -234,12 +234,12 @@ impl PathSegmentBuilder } pub fn lifetime(self, name: N) -> Self - where N: ToName, + where N: ToSymbol, { let lifetime = ast::Lifetime { id: ast::DUMMY_NODE_ID, span: self.span, - name: name.to_name(), + name: name.to_symbol(), }; self.with_lifetime(lifetime) } diff --git a/src/str.rs b/src/str.rs deleted file mode 100644 index f8f17c684..000000000 --- a/src/str.rs +++ /dev/null @@ -1,38 +0,0 @@ -use syntax::ast; -use syntax::parse::token; - -////////////////////////////////////////////////////////////////////////////// - -pub trait ToInternedString { - fn to_interned_string(&self) -> token::InternedString; -} - -impl ToInternedString for token::InternedString { - fn to_interned_string(&self) -> token::InternedString { - self.clone() - } -} - -impl<'a> ToInternedString for &'a str { - fn to_interned_string(&self) -> token::InternedString { - token::intern_and_get_ident(self) - } -} - -impl ToInternedString for ast::Ident { - fn to_interned_string(&self) -> token::InternedString { - self.name.as_str() - } -} - -impl ToInternedString for ast::Name { - fn to_interned_string(&self) -> token::InternedString { - self.as_str() - } -} - -impl<'a, T> ToInternedString for &'a T where T: ToInternedString { - fn to_interned_string(&self) -> token::InternedString { - (**self).to_interned_string() - } -} diff --git a/src/symbol.rs b/src/symbol.rs new file mode 100644 index 000000000..a93339180 --- /dev/null +++ b/src/symbol.rs @@ -0,0 +1,38 @@ +use syntax::ast; +use syntax::symbol::Symbol; + +////////////////////////////////////////////////////////////////////////////// + +pub trait ToSymbol { + fn to_symbol(&self) -> Symbol; +} + +impl ToSymbol for Symbol { + fn to_symbol(&self) -> Symbol { + self.clone() + } +} + +impl<'a> ToSymbol for &'a str { + fn to_symbol(&self) -> Symbol { + Symbol::intern(self) + } +} + +impl ToSymbol for ast::Ident { + fn to_symbol(&self) -> Symbol { + self.name + } +} + +impl<'a, T> ToSymbol for &'a T where T: ToSymbol { + fn to_symbol(&self) -> Symbol { + (**self).to_symbol() + } +} + +impl<'a, T> ToSymbol for &'a mut T where T: ToSymbol { + fn to_symbol(&self) -> Symbol { + (**self).to_symbol() + } +} diff --git a/src/ty.rs b/src/ty.rs index dda802740..af688f24c 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -8,9 +8,9 @@ use expr::ExprBuilder; use ident::ToIdent; use invoke::{Invoke, Identity}; use lifetime::IntoLifetime; -use name::ToName; use path::PathBuilder; use qpath::QPathBuilder; +use symbol::ToSymbol; use ty_param::TyParamBoundBuilder; ////////////////////////////////////////////////////////////////////////////// @@ -284,12 +284,12 @@ impl TyRefBuilder } pub fn lifetime(mut self, name: N) -> Self - where N: ToName, + where N: ToSymbol, { self.lifetime = Some(ast::Lifetime { id: ast::DUMMY_NODE_ID, span: self.builder.span, - name: name.to_name(), + name: name.to_symbol(), }); self } diff --git a/src/ty_param.rs b/src/ty_param.rs index 4d6ee62af..74290d323 100644 --- a/src/ty_param.rs +++ b/src/ty_param.rs @@ -5,8 +5,8 @@ use syntax::ptr::P; use ident::ToIdent; use invoke::{Invoke, Identity}; use lifetime::{IntoLifetime, IntoLifetimeDef, LifetimeDefBuilder}; -use name::ToName; use path::{IntoPath, PathBuilder}; +use symbol::ToSymbol; use ty::TyBuilder; ////////////////////////////////////////////////////////////////////////////// @@ -279,7 +279,7 @@ impl PolyTraitRefBuilder } pub fn lifetime(self, name: N) -> LifetimeDefBuilder - where N: ToName, + where N: ToSymbol, { LifetimeDefBuilder::with_callback(name, self) } diff --git a/src/where_predicate.rs b/src/where_predicate.rs index 6f7fb45c2..e7bcf1e28 100644 --- a/src/where_predicate.rs +++ b/src/where_predicate.rs @@ -4,8 +4,8 @@ use syntax::ptr::P; use invoke::{Invoke, Identity}; use lifetime::{IntoLifetime, IntoLifetimeDef, LifetimeDefBuilder}; -use name::ToName; use path::IntoPath; +use symbol::ToSymbol; use ty::TyBuilder; use ty_param::{TyParamBoundBuilder, PolyTraitRefBuilder, TraitTyParamBoundBuilder}; @@ -121,7 +121,7 @@ impl WhereBoundPredicateTyBuilder } pub fn for_lifetime(self, name: N) -> LifetimeDefBuilder - where N: ToName, + where N: ToSymbol, { LifetimeDefBuilder::with_callback(name, self) } @@ -207,7 +207,7 @@ impl WhereBoundPredicateTyBoundsBuilder } pub fn for_lifetime(self, name: N) -> LifetimeDefBuilder - where N: ToName, + where N: ToSymbol, { LifetimeDefBuilder::with_callback(name, self) } diff --git a/tests/test_attr.rs b/tests/test_attr.rs index 51b4fabd6..e5747039f 100644 --- a/tests/test_attr.rs +++ b/tests/test_attr.rs @@ -1,6 +1,5 @@ use syntax::ast; -use syntax::codemap::{DUMMY_SP, respan}; -use syntax::ptr::P; +use syntax::codemap::DUMMY_SP; use aster::AstBuilder; @@ -9,20 +8,18 @@ fn test_doc() { let builder = AstBuilder::new(); assert_eq!( builder.attr().doc("/// doc string"), - respan( - DUMMY_SP, - ast::Attribute_ { - id: ast::AttrId(0), - style: ast::AttrStyle::Outer, - value: P(respan( - DUMMY_SP, - ast::MetaItemKind::NameValue( - builder.interned_string("doc"), - (*builder.lit().str("/// doc string")).clone(), - ), - )), - is_sugared_doc: true, - } - ) + ast::Attribute { + id: ast::AttrId(0), + style: ast::AttrStyle::Outer, + value: ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }, + is_sugared_doc: true, + span: DUMMY_SP, + } ); } diff --git a/tests/test_item.rs b/tests/test_item.rs index 27c60fa12..36c8a9ee0 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -1,13 +1,13 @@ use syntax::abi::Abi; use syntax::ast; use syntax::codemap::{DUMMY_SP, respan}; -use syntax::parse::token::keywords; use syntax::print::pprust; use syntax::ptr::P; +use syntax::symbol::keywords; use aster::AstBuilder; use aster::ident::ToIdent; -use aster::name::ToName; +use aster::symbol::ToSymbol; #[test] fn test_fn() { @@ -405,21 +405,19 @@ fn test_attr() { P(ast::Item { ident: builder.id("Struct"), attrs: vec![ - respan( - DUMMY_SP, - ast::Attribute_ { - id: ast::AttrId(0), - style: ast::AttrStyle::Outer, - value: P(respan( - DUMMY_SP, - ast::MetaItemKind::NameValue( - builder.interned_string("doc"), - (*builder.lit().str("/// doc string")).clone(), - ), - )), - is_sugared_doc: true, - } - ), + ast::Attribute { + id: ast::AttrId(0), + style: ast::AttrStyle::Outer, + value: ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }, + is_sugared_doc: true, + span: DUMMY_SP, + } ], id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Struct( @@ -456,7 +454,7 @@ fn test_extern_crate() { let item = builder.item() .extern_crate("aster") - .with_name("aster1".to_name()); + .with_name("aster1"); assert_eq!( item, @@ -464,7 +462,7 @@ fn test_extern_crate() { ident: builder.id("aster"), attrs: vec![], id: ast::DUMMY_NODE_ID, - node: ast::ItemKind::ExternCrate(Some("aster1".to_name())), + node: ast::ItemKind::ExternCrate(Some("aster1".to_symbol())), vis: ast::Visibility::Inherited, span: DUMMY_SP, }) diff --git a/tests/test_lit.rs b/tests/test_lit.rs index 3bcc72dcc..1462a3bd0 100644 --- a/tests/test_lit.rs +++ b/tests/test_lit.rs @@ -94,7 +94,7 @@ fn test_str() { P(Spanned { span: DUMMY_SP, node: ast::LitKind::Str( - builder.interned_string("string"), + builder.symbol("string"), ast::StrStyle::Cooked, ), }) diff --git a/tests/test_struct_field.rs b/tests/test_struct_field.rs index bbd64248f..3eb64eebe 100644 --- a/tests/test_struct_field.rs +++ b/tests/test_struct_field.rs @@ -1,6 +1,5 @@ use syntax::ast; -use syntax::codemap::{DUMMY_SP, respan}; -use syntax::ptr::P; +use syntax::codemap::DUMMY_SP; use aster::AstBuilder; @@ -54,33 +53,30 @@ fn test_attrs() { ty: builder.ty().isize(), span: DUMMY_SP, attrs: vec![ - respan( - DUMMY_SP, - ast::Attribute_ { - id: ast::AttrId(0), - style: ast::AttrStyle::Outer, - value: P(respan( - DUMMY_SP, - ast::MetaItemKind::NameValue( - builder.interned_string("doc"), - (*builder.lit().str("/// doc string")).clone(), - ), - )), - is_sugared_doc: true, - } - ), - respan( - DUMMY_SP, - ast::Attribute_ { - id: ast::AttrId(1), - style: ast::AttrStyle::Outer, - value: P(respan( - DUMMY_SP, - ast::MetaItemKind::Word(builder.interned_string("automatically_derived")), - )), - is_sugared_doc: false, - } - ), + ast::Attribute { + id: ast::AttrId(0), + style: ast::AttrStyle::Outer, + value: ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }, + is_sugared_doc: true, + span: DUMMY_SP, + }, + ast::Attribute { + id: ast::AttrId(1), + style: ast::AttrStyle::Outer, + value: ast::MetaItem { + name: builder.symbol("automatically_derived"), + node: ast::MetaItemKind::Word, + span: DUMMY_SP, + }, + is_sugared_doc: false, + span: DUMMY_SP, + }, ], } );