diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-11-15 04:34:52 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-11-20 11:46:06 +0000 |
| commit | a2626410d78c3b4bb9b7072b9ca1ee2ed7ce600f (patch) | |
| tree | 61e0f8af79f0924bedcdccdbdf9d0699cde9beab /src/libsyntax_ext | |
| parent | ff4994235aa27b911422c8b4241c5d8f3d112d65 (diff) | |
| download | rust-a2626410d78c3b4bb9b7072b9ca1ee2ed7ce600f.tar.gz rust-a2626410d78c3b4bb9b7072b9ca1ee2ed7ce600f.zip | |
Refactor `MetaItemKind` to use `Name`s instead of `InternedString`s.
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/clone.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/eq.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/ord.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_eq.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_ord.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/custom.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/default.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/mod.rs | 56 | ||||
| -rw-r--r-- | src/libsyntax_ext/proc_macro_registrar.rs | 15 |
10 files changed, 59 insertions, 67 deletions
diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index d7bc2a6faee..c2a166e0819 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -15,7 +15,7 @@ use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::{keywords, InternedString}; +use syntax::parse::token::{self, keywords}; use syntax::ptr::P; use syntax_pos::Span; @@ -74,7 +74,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, _ => cx.span_bug(span, "#[derive(Clone)] on trait item or impl item"), } - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span: span, diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index fa0fb2492c5..a1be573551e 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -14,7 +14,7 @@ use deriving::generic::ty::*; use syntax::ast::{self, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::InternedString; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -23,9 +23,9 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, mitem: &MetaItem, item: &Annotatable, push: &mut FnMut(Annotatable)) { - let inline = cx.meta_word(span, InternedString::new("inline")); - let hidden = cx.meta_list_item_word(span, InternedString::new("hidden")); - let doc = cx.meta_list(span, InternedString::new("doc"), vec![hidden]); + let inline = cx.meta_word(span, token::intern("inline")); + let hidden = cx.meta_list_item_word(span, token::intern("hidden")); + let doc = cx.meta_list(span, token::intern("doc"), vec![hidden]); let attrs = vec![cx.attribute(span, inline), cx.attribute(span, doc)]; let trait_def = TraitDef { span: span, diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 6b2e36e63b6..85d29f5e213 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -14,7 +14,7 @@ use deriving::generic::ty::*; use syntax::ast::{self, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::InternedString; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -23,7 +23,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, mitem: &MetaItem, item: &Annotatable, push: &mut FnMut(Annotatable)) { - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span: span, diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index c46d4b34173..1b6ccfd012c 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -14,7 +14,7 @@ use deriving::generic::ty::*; use syntax::ast::{BinOpKind, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::InternedString; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -64,7 +64,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, macro_rules! md { ($name:expr, $f:ident) => { { - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; MethodDef { name: $name, diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 597ff306b3d..7d76722ee97 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -16,7 +16,7 @@ use deriving::generic::ty::*; use syntax::ast::{self, BinOpKind, Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::InternedString; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -27,7 +27,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, push: &mut FnMut(Annotatable)) { macro_rules! md { ($name:expr, $op:expr, $equal:expr) => { { - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; MethodDef { name: $name, @@ -51,7 +51,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, vec![Box::new(ordering_ty)], true)); - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; let partial_cmp_def = MethodDef { diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index e101757ad23..1076a6a6d63 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -17,10 +17,9 @@ use syntax::attr::{mark_used, mark_known}; use syntax::codemap::Span; use syntax::ext::base::*; use syntax::fold::Folder; -use syntax::parse::token::InternedString; use syntax::visit::Visitor; -struct MarkAttrs<'a>(&'a [InternedString]); +struct MarkAttrs<'a>(&'a [ast::Name]); impl<'a> Visitor for MarkAttrs<'a> { fn visit_attribute(&mut self, attr: &Attribute) { @@ -33,13 +32,11 @@ impl<'a> Visitor for MarkAttrs<'a> { pub struct CustomDerive { inner: fn(TokenStream) -> TokenStream, - attrs: Vec<InternedString>, + attrs: Vec<ast::Name>, } impl CustomDerive { - pub fn new(inner: fn(TokenStream) -> TokenStream, - attrs: Vec<InternedString>) - -> CustomDerive { + pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> CustomDerive { CustomDerive { inner: inner, attrs: attrs } } } diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index b15fd2b49a6..0b97213394b 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -14,7 +14,7 @@ use deriving::generic::ty::*; use syntax::ast::{Expr, MetaItem}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; -use syntax::parse::token::InternedString; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -23,7 +23,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, mitem: &MetaItem, item: &Annotatable, push: &mut FnMut(Annotatable)) { - let inline = cx.meta_word(span, InternedString::new("inline")); + let inline = cx.meta_word(span, token::intern("inline")); let attrs = vec![cx.attribute(span, inline)]; let trait_def = TraitDef { span: span, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e6b63be3efc..b245e399f1c 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -198,7 +198,7 @@ use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::codemap::{self, dummy_spanned, respan}; use syntax::util::move_map::MoveMap; -use syntax::parse::token::{InternedString, keywords}; +use syntax::parse::token::{self, keywords}; use syntax::ptr::P; use syntax_pos::{DUMMY_SP, Span}; use errors::Handler; @@ -442,7 +442,7 @@ impl<'a> TraitDef<'a> { attrs.extend(item.attrs .iter() .filter(|a| { - match &a.name()[..] { + match &*a.name().as_str() { "allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true, _ => false, } @@ -639,15 +639,15 @@ impl<'a> TraitDef<'a> { let attr = cx.attribute(self.span, cx.meta_word(self.span, - InternedString::new("automatically_derived"))); + token::intern("automatically_derived"))); // Just mark it now since we know that it'll end up used downstream attr::mark_used(&attr); let opt_trait_ref = Some(trait_ref); - let unused_qual = cx.attribute(self.span, - cx.meta_list(self.span, - InternedString::new("allow"), - vec![cx.meta_list_item_word(self.span, - InternedString::new("unused_qualifications"))])); + let unused_qual = { + let word = cx.meta_list_item_word(self.span, token::intern("unused_qualifications")); + cx.attribute(self.span, cx.meta_list(self.span, token::intern("allow"), vec![word])) + }; + let mut a = vec![attr, unused_qual]; a.extend(self.attributes.iter().cloned()); diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index 09d529f5313..32dcdcfd110 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -16,7 +16,7 @@ use syntax::codemap; use syntax::ext::base::{Annotatable, ExtCtxt, SyntaxExtension}; use syntax::ext::build::AstBuilder; use syntax::feature_gate::{self, emit_feature_err}; -use syntax::parse::token::{intern, intern_and_get_ident}; +use syntax::parse::token; use syntax::ptr::P; use syntax_pos::Span; @@ -80,7 +80,7 @@ fn allow_unstable(cx: &mut ExtCtxt, span: Span, attr_name: &str) -> Span { expn_id: cx.codemap().record_expansion(codemap::ExpnInfo { call_site: span, callee: codemap::NameAndSpan { - format: codemap::MacroAttribute(intern(attr_name)), + format: codemap::MacroAttribute(token::intern(attr_name)), span: Some(span), allow_internal_unstable: true, }, @@ -105,9 +105,10 @@ pub fn expand_derive(cx: &mut ExtCtxt, } }; + let derive = token::intern("derive"); let mut derive_attrs = Vec::new(); item = item.map_attrs(|attrs| { - let partition = attrs.into_iter().partition(|attr| &attr.name() == "derive"); + let partition = attrs.into_iter().partition(|attr| attr.name() == derive); derive_attrs = partition.0; partition.1 }); @@ -158,9 +159,8 @@ pub fn expand_derive(cx: &mut ExtCtxt, let tword = titem.word().unwrap(); let tname = tword.name(); - if is_builtin_trait(&tname) || { - let derive_mode = - ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(intern(&tname))); + if is_builtin_trait(tname) || { + let derive_mode = ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(tname)); cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| { if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false } }).unwrap_or(false) @@ -176,7 +176,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, feature_gate::EXPLAIN_CUSTOM_DERIVE); } else { cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE); - let name = intern_and_get_ident(&format!("derive_{}", tname)); + let name = token::intern(&format!("derive_{}", tname)); let mitem = cx.meta_word(titem.span, name); new_attributes.push(cx.attribute(mitem.span, mitem)); } @@ -186,9 +186,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, item = item.map(|mut i| { i.attrs.extend(new_attributes); if traits.len() > 0 { - let list = cx.meta_list(mitem.span, - intern_and_get_ident("derive"), - traits); + let list = cx.meta_list(mitem.span, derive, traits); i.attrs.push(cx.attribute(mitem.span, list)); } i @@ -217,7 +215,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, let macros_11_derive = traits.iter() .cloned() .enumerate() - .filter(|&(_, ref name)| !is_builtin_trait(&name.name().unwrap())) + .filter(|&(_, ref name)| !is_builtin_trait(name.name().unwrap())) .next(); if let Some((i, titem)) = macros_11_derive { if !cx.ecfg.features.unwrap().proc_macro { @@ -226,24 +224,20 @@ pub fn expand_derive(cx: &mut ExtCtxt, emit_feature_err(cx.parse_sess, "proc_macro", titem.span, issue, msg); } - let tname = ast::Ident::with_empty_ctxt(intern(&titem.name().unwrap())); + let tname = ast::Ident::with_empty_ctxt(titem.name().unwrap()); let path = ast::Path::from_ident(titem.span, tname); let ext = cx.resolver.resolve_macro(cx.current_expansion.mark, &path, false).unwrap(); traits.remove(i); if traits.len() > 0 { item = item.map(|mut i| { - let list = cx.meta_list(mitem.span, - intern_and_get_ident("derive"), - traits); + let list = cx.meta_list(mitem.span, derive, traits); i.attrs.push(cx.attribute(mitem.span, list)); i }); } let titem = cx.meta_list_item_word(titem.span, titem.name().unwrap()); - let mitem = cx.meta_list(titem.span, - intern_and_get_ident("derive"), - vec![titem]); + let mitem = cx.meta_list(titem.span, derive, vec![titem]); let item = Annotatable::Item(item); if let SyntaxExtension::CustomDerive(ref ext) = *ext { return ext.expand(cx, mitem.span, &mitem, item); @@ -257,9 +251,10 @@ pub fn expand_derive(cx: &mut ExtCtxt, // RFC #1445. `#[derive(PartialEq, Eq)]` adds a (trusted) // `#[structural_match]` attribute. - if traits.iter().filter_map(|t| t.name()).any(|t| t == "PartialEq") && - traits.iter().filter_map(|t| t.name()).any(|t| t == "Eq") { - let structural_match = intern_and_get_ident("structural_match"); + let (partial_eq, eq) = (token::intern("PartialEq"), token::intern("Eq")); + if traits.iter().any(|t| t.name() == Some(partial_eq)) && + traits.iter().any(|t| t.name() == Some(eq)) { + let structural_match = token::intern("structural_match"); let span = allow_unstable(cx, span, "derive(PartialEq, Eq)"); let meta = cx.meta_word(span, structural_match); item = item.map(|mut i| { @@ -272,9 +267,10 @@ pub fn expand_derive(cx: &mut ExtCtxt, // the same as the copy implementation. // // Add a marker attribute here picked up during #[derive(Clone)] - if traits.iter().filter_map(|t| t.name()).any(|t| t == "Clone") && - traits.iter().filter_map(|t| t.name()).any(|t| t == "Copy") { - let marker = intern_and_get_ident("rustc_copy_clone_marker"); + let (copy, clone) = (token::intern("Copy"), token::intern("Clone")); + if traits.iter().any(|t| t.name() == Some(clone)) && + traits.iter().any(|t| t.name() == Some(copy)) { + let marker = token::intern("rustc_copy_clone_marker"); let span = allow_unstable(cx, span, "derive(Copy, Clone)"); let meta = cx.meta_word(span, marker); item = item.map(|mut i| { @@ -286,14 +282,14 @@ pub fn expand_derive(cx: &mut ExtCtxt, let mut items = Vec::new(); for titem in traits.iter() { let tname = titem.word().unwrap().name(); - let name = intern_and_get_ident(&format!("derive({})", tname)); + let name = token::intern(&format!("derive({})", tname)); let mitem = cx.meta_word(titem.span, name); let span = Span { expn_id: cx.codemap().record_expansion(codemap::ExpnInfo { call_site: titem.span, callee: codemap::NameAndSpan { - format: codemap::MacroAttribute(intern(&format!("derive({})", tname))), + format: codemap::MacroAttribute(token::intern(&format!("derive({})", tname))), span: Some(titem.span), allow_internal_unstable: true, }, @@ -302,7 +298,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, }; let my_item = Annotatable::Item(item); - expand_builtin(&tname, cx, span, &mitem, &my_item, &mut |a| { + expand_builtin(&tname.as_str(), cx, span, &mitem, &my_item, &mut |a| { items.push(a); }); item = my_item.expect_item(); @@ -314,8 +310,8 @@ pub fn expand_derive(cx: &mut ExtCtxt, macro_rules! derive_traits { ($( $name:expr => $func:path, )+) => { - pub fn is_builtin_trait(name: &str) -> bool { - match name { + pub fn is_builtin_trait(name: ast::Name) -> bool { + match &*name.as_str() { $( $name )|+ => true, _ => false, } @@ -412,7 +408,7 @@ fn call_intrinsic(cx: &ExtCtxt, span.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo { call_site: span, callee: codemap::NameAndSpan { - format: codemap::MacroAttribute(intern("derive")), + format: codemap::MacroAttribute(token::intern("derive")), span: Some(span), allow_internal_unstable: true, }, diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index 36fd6408b4f..1165eb46bf0 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -17,7 +17,7 @@ use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::ext::expand::ExpansionConfig; use syntax::parse::ParseSess; -use syntax::parse::token::{self, InternedString}; +use syntax::parse::token; use syntax::feature_gate::Features; use syntax::fold::Folder; use syntax::ptr::P; @@ -27,10 +27,10 @@ use syntax::visit::{self, Visitor}; use deriving; struct CustomDerive { - trait_name: InternedString, + trait_name: ast::Name, function_name: Ident, span: Span, - attrs: Vec<InternedString>, + attrs: Vec<ast::Name>, } struct CollectCustomDerives<'a> { @@ -183,7 +183,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> { self.handler.span_err(trait_attr.span(), "must only be one word"); } - if deriving::is_builtin_trait(&trait_name) { + if deriving::is_builtin_trait(trait_name) { self.handler.span_err(trait_attr.span(), "cannot override a built-in #[derive] mode"); } @@ -290,10 +290,10 @@ fn mk_registrar(cx: &mut ExtCtxt, let register_custom_derive = token::str_to_ident("register_custom_derive"); let stmts = custom_derives.iter().map(|cd| { let path = cx.path_global(cd.span, vec![cd.function_name]); - let trait_name = cx.expr_str(cd.span, cd.trait_name.clone()); + let trait_name = cx.expr_str(cd.span, cd.trait_name.as_str()); let attrs = cx.expr_vec_slice( span, - cd.attrs.iter().map(|s| cx.expr_str(cd.span, s.clone())).collect::<Vec<_>>() + cd.attrs.iter().map(|s| cx.expr_str(cd.span, s.as_str())).collect::<Vec<_>>() ); (path, trait_name, attrs) }).map(|(path, trait_name, attrs)| { @@ -316,8 +316,7 @@ fn mk_registrar(cx: &mut ExtCtxt, cx.ty(span, ast::TyKind::Tup(Vec::new())), cx.block(span, stmts)); - let derive_registrar = token::intern_and_get_ident("rustc_derive_registrar"); - let derive_registrar = cx.meta_word(span, derive_registrar); + let derive_registrar = cx.meta_word(span, token::intern("rustc_derive_registrar")); let derive_registrar = cx.attribute(span, derive_registrar); let func = func.map(|mut i| { i.attrs.push(derive_registrar); |
