]> git.lizzy.rs Git - rust.git/commitdiff
Refactor `MetaItemKind` to use `Name`s instead of `InternedString`s.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 15 Nov 2016 04:34:52 +0000 (04:34 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sun, 20 Nov 2016 11:46:06 +0000 (11:46 +0000)
33 files changed:
src/librustc/hir/check_attr.rs
src/librustc/lint/context.rs
src/librustc/middle/dead.rs
src/librustc/session/config.rs
src/librustc_driver/target_features.rs
src/librustc_incremental/assert_dep_graph.rs
src/librustc_incremental/calculate_svh/svh_visitor.rs
src/librustc_lint/builtin.rs
src/librustc_lint/unused.rs
src/librustc_metadata/creader.rs
src/librustc_plugin/load.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/macros.rs
src/librustc_save_analysis/lib.rs
src/libsyntax/ast.rs
src/libsyntax/attr.rs
src/libsyntax/ext/build.rs
src/libsyntax/ext/expand.rs
src/libsyntax/feature_gate.rs
src/libsyntax/parse/attr.rs
src/libsyntax/print/pprust.rs
src/libsyntax/std_inject.rs
src/libsyntax/test.rs
src/libsyntax_ext/deriving/clone.rs
src/libsyntax_ext/deriving/cmp/eq.rs
src/libsyntax_ext/deriving/cmp/ord.rs
src/libsyntax_ext/deriving/cmp/partial_eq.rs
src/libsyntax_ext/deriving/cmp/partial_ord.rs
src/libsyntax_ext/deriving/custom.rs
src/libsyntax_ext/deriving/default.rs
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/mod.rs
src/libsyntax_ext/proc_macro_registrar.rs

index 8ba52cdb64f5fd83a6c274f2dfa3720f676fdfdd..abc35634d15f456e21372a311f77bff177392a6e 100644 (file)
@@ -64,7 +64,7 @@ fn check_repr(&self, attr: &ast::Attribute, target: Target) {
                 None => continue,
             };
 
-            let (message, label) = match &*name {
+            let (message, label) = match &*name.as_str() {
                 "C" => {
                     conflicting_reprs += 1;
                     if target != Target::Struct &&
@@ -120,7 +120,7 @@ fn check_repr(&self, attr: &ast::Attribute, target: Target) {
     }
 
     fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
-        let name: &str = &attr.name();
+        let name: &str = &attr.name().as_str();
         match name {
             "inline" => self.check_inline(attr, target),
             "repr" => self.check_repr(attr, target),
index e9d2aa7e7750c4af5320c1d196058144364949f3..4a082944010b2838fb73d12cc26d84f9d7bea0eb 100644 (file)
@@ -40,7 +40,6 @@
 use std::mem;
 use std::fmt;
 use syntax::attr;
-use syntax::parse::token::InternedString;
 use syntax::ast;
 use syntax_pos::{MultiSpan, Span};
 use errors::{self, Diagnostic, DiagnosticBuilder};
@@ -384,8 +383,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $ps:ident, $($args:expr),*) => ({
 /// Parse the lint attributes into a vector, with `Err`s for malformed lint
 /// attributes. Writing this as an iterator is an enormous mess.
 // See also the hir version just below.
-pub fn gather_attrs(attrs: &[ast::Attribute])
-                    -> Vec<Result<(InternedString, Level, Span), Span>> {
+pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec<Result<(ast::Name, Level, Span), Span>> {
     let mut out = vec![];
     for attr in attrs {
         let r = gather_attr(attr);
@@ -394,11 +392,10 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
     out
 }
 
-pub fn gather_attr(attr: &ast::Attribute)
-                   -> Vec<Result<(InternedString, Level, Span), Span>> {
+pub fn gather_attr(attr: &ast::Attribute) -> Vec<Result<(ast::Name, Level, Span), Span>> {
     let mut out = vec![];
 
-    let level = match Level::from_str(&attr.name()) {
+    let level = match Level::from_str(&attr.name().as_str()) {
         None => return out,
         Some(lvl) => lvl,
     };
@@ -414,9 +411,7 @@ pub fn gather_attr(attr: &ast::Attribute)
     };
 
     for li in metas {
-        out.push(li.word().map_or(Err(li.span), |word| {
-            Ok((word.name().clone(), level, word.span))
-        }));
+        out.push(li.word().map_or(Err(li.span), |word| Ok((word.name(), level, word.span))));
     }
 
     out
@@ -629,10 +624,10 @@ fn with_lint_attrs<F>(&mut self,
                     continue;
                 }
                 Ok((lint_name, level, span)) => {
-                    match self.lints().find_lint(&lint_name, &self.sess(), Some(span)) {
+                    match self.lints().find_lint(&lint_name.as_str(), &self.sess(), Some(span)) {
                         Ok(lint_id) => vec![(lint_id, level, span)],
                         Err(FindLintError::NotFound) => {
-                            match self.lints().lint_groups.get(&lint_name[..]) {
+                            match self.lints().lint_groups.get(&*lint_name.as_str()) {
                                 Some(&(ref v, _)) => v.iter()
                                                       .map(|lint_id: &LintId|
                                                            (*lint_id, level, span))
@@ -1193,8 +1188,7 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
                 continue;
             }
             Ok((lint_name, _, span)) => {
-                match check_lint_name(&cx.lints,
-                                      &lint_name[..]) {
+                match check_lint_name(&cx.lints, &lint_name.as_str()) {
                     CheckLintNameResult::Ok => (),
                     CheckLintNameResult::Warning(ref msg) => {
                         cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,
index 991398813752f8a5991536259f804b0d1a8f0749..09c1bd0dd126c921dca66c958af55381a6626c58 100644 (file)
@@ -309,8 +309,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
     let dead_code = lint::builtin::DEAD_CODE.name_lower();
     for attr in lint::gather_attrs(attrs) {
         match attr {
-            Ok((ref name, lint::Allow, _))
-                if &name[..] == dead_code => return true,
+            Ok((name, lint::Allow, _)) if name == &*dead_code => return true,
             _ => (),
         }
     }
index 16522a73f56a514fa2b551f47545edc00014753f..1502811baee25d0d48a5ac74b045c442a83b7c47 100644 (file)
@@ -26,7 +26,7 @@
 
 use syntax::ast::{self, IntTy, UintTy};
 use syntax::attr;
-use syntax::parse;
+use syntax::parse::{self, token};
 use syntax::parse::token::InternedString;
 use syntax::feature_gate::UnstableFeatures;
 
@@ -947,41 +947,40 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
 
     let mk = attr::mk_name_value_item_str;
     let mut ret = vec![ // Target bindings.
-        mk(InternedString::new("target_os"), intern(os)),
-        mk(InternedString::new("target_family"), fam.clone()),
-        mk(InternedString::new("target_arch"), intern(arch)),
-        mk(InternedString::new("target_endian"), intern(end)),
-        mk(InternedString::new("target_pointer_width"), intern(wordsz)),
-        mk(InternedString::new("target_env"), intern(env)),
-        mk(InternedString::new("target_vendor"), intern(vendor)),
+        mk(token::intern("target_os"), intern(os)),
+        mk(token::intern("target_family"), fam.clone()),
+        mk(token::intern("target_arch"), intern(arch)),
+        mk(token::intern("target_endian"), intern(end)),
+        mk(token::intern("target_pointer_width"), intern(wordsz)),
+        mk(token::intern("target_env"), intern(env)),
+        mk(token::intern("target_vendor"), intern(vendor)),
     ];
     match &fam[..] {
-        "windows" | "unix" => ret.push(attr::mk_word_item(fam)),
+        "windows" | "unix" => ret.push(attr::mk_word_item(token::intern(&fam))),
         _ => (),
     }
     if sess.target.target.options.has_elf_tls {
-        ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
+        ret.push(attr::mk_word_item(token::intern("target_thread_local")));
     }
     for &i in &[8, 16, 32, 64, 128] {
         if i <= max_atomic_width {
             let s = i.to_string();
-            ret.push(mk(InternedString::new("target_has_atomic"), intern(&s)));
+            ret.push(mk(token::intern("target_has_atomic"), intern(&s)));
             if &s == wordsz {
-                ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr")));
+                ret.push(mk(token::intern("target_has_atomic"), intern("ptr")));
             }
         }
     }
     if sess.opts.debug_assertions {
-        ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
+        ret.push(attr::mk_word_item(token::intern("debug_assertions")));
     }
     if sess.opts.crate_types.contains(&CrateTypeProcMacro) {
-        ret.push(attr::mk_word_item(InternedString::new("proc_macro")));
+        ret.push(attr::mk_word_item(token::intern("proc_macro")));
     }
     return ret;
 }
 
-pub fn append_configuration(cfg: &mut ast::CrateConfig,
-                            name: InternedString) {
+pub fn append_configuration(cfg: &mut ast::CrateConfig, name: ast::Name) {
     if !cfg.iter().any(|mi| mi.name() == name) {
         cfg.push(attr::mk_word_item(name))
     }
@@ -995,7 +994,7 @@ pub fn build_configuration(sess: &Session,
     let default_cfg = default_configuration(sess);
     // If the user wants a test runner, then add the test cfg
     if sess.opts.test {
-        append_configuration(&mut user_cfg, InternedString::new("test"))
+        append_configuration(&mut user_cfg, token::intern("test"))
     }
     let mut v = user_cfg.into_iter().collect::<Vec<_>>();
     v.extend_from_slice(&default_cfg[..]);
index 57a9edc5c586b532081f0eba7c3c34c9d8224982..436b44d8b03b91a2b1e5f6d6a4a51106eb21fd8f 100644 (file)
@@ -13,8 +13,7 @@
 use rustc::session::Session;
 use rustc_trans::back::write::create_target_machine;
 use syntax::feature_gate::UnstableFeatures;
-use syntax::parse::token::InternedString;
-use syntax::parse::token::intern_and_get_ident as intern;
+use syntax::parse::token::{self, intern_and_get_ident as intern};
 use libc::c_char;
 
 // WARNING: the features must be known to LLVM or the feature
@@ -41,11 +40,11 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
         _ => &[],
     };
 
-    let tf = InternedString::new("target_feature");
+    let tf = token::intern("target_feature");
     for feat in whitelist {
         assert_eq!(feat.chars().last(), Some('\0'));
         if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
-            cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1])))
+            cfg.push(attr::mk_name_value_item_str(tf, intern(&feat[..feat.len() - 1])))
         }
     }
 
index 998cbae2cce150b94bace00a20f21653a69520c1..87e6b2befdc3281fcbbb9359c11bf499d4eaccfd 100644 (file)
@@ -57,7 +57,6 @@
 use std::fs::File;
 use std::io::Write;
 use syntax::ast;
-use syntax::parse::token::InternedString;
 use syntax_pos::Span;
 use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
 
@@ -97,7 +96,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
 }
 
 type Sources = Vec<(Span, DefId, DepNode<DefId>)>;
-type Targets = Vec<(Span, InternedString, ast::NodeId, DepNode<DefId>)>;
+type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode<DefId>)>;
 
 struct IfThisChanged<'a, 'tcx:'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -106,7 +105,7 @@ struct IfThisChanged<'a, 'tcx:'a> {
 }
 
 impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
-    fn argument(&self, attr: &ast::Attribute) -> Option<InternedString> {
+    fn argument(&self, attr: &ast::Attribute) -> Option<ast::Name> {
         let mut value = None;
         for list_item in attr.meta_item_list().unwrap_or_default() {
             match list_item.word() {
@@ -127,8 +126,8 @@ fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
                 let dep_node_interned = self.argument(attr);
                 let dep_node = match dep_node_interned {
                     None => DepNode::Hir(def_id),
-                    Some(ref n) => {
-                        match DepNode::from_label_string(&n[..], def_id) {
+                    Some(n) => {
+                        match DepNode::from_label_string(&n.as_str(), def_id) {
                             Ok(n) => n,
                             Err(()) => {
                                 self.tcx.sess.span_fatal(
@@ -142,8 +141,8 @@ fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
             } else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
                 let dep_node_interned = self.argument(attr);
                 let dep_node = match dep_node_interned {
-                    Some(ref n) => {
-                        match DepNode::from_label_string(&n[..], def_id) {
+                    Some(n) => {
+                        match DepNode::from_label_string(&n.as_str(), def_id) {
                             Ok(n) => n,
                             Err(()) => {
                                 self.tcx.sess.span_fatal(
@@ -159,7 +158,7 @@ fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
                     }
                 };
                 self.then_this_would_need.push((attr.span,
-                                                dep_node_interned.clone().unwrap(),
+                                                dep_node_interned.unwrap(),
                                                 node_id,
                                                 dep_node));
             }
index 21c628d18bac95d86ad28fc7c127a6c2fa6ab2ef..55dd222b0db5e5d8abbcd8a888a940c3d6ab24e6 100644 (file)
@@ -875,16 +875,19 @@ fn hash_meta_item(&mut self, meta_item: &ast::MetaItem) {
         // ignoring span information, it doesn't matter here
         self.hash_discriminant(&meta_item.node);
         match meta_item.node {
-            ast::MetaItemKind::Word(ref s) => {
+            ast::MetaItemKind::Word(s) => {
+                let s = &*s.as_str();
                 s.len().hash(self.st);
                 s.hash(self.st);
             }
-            ast::MetaItemKind::NameValue(ref s, ref lit) => {
+            ast::MetaItemKind::NameValue(s, ref lit) => {
+                let s = &*s.as_str();
                 s.len().hash(self.st);
                 s.hash(self.st);
                 lit.node.hash(self.st);
             }
-            ast::MetaItemKind::List(ref s, ref items) => {
+            ast::MetaItemKind::List(s, ref items) => {
+                let s = &*s.as_str();
                 s.len().hash(self.st);
                 s.hash(self.st);
                 // Sort subitems so the hash does not depend on their order
@@ -916,7 +919,7 @@ pub fn hash_attributes(&mut self, attributes: &[ast::Attribute]) {
         for i in indices {
             let attr = &attributes[i];
             if !attr.is_sugared_doc &&
-               !IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) {
+               !IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
                 SawAttribute(attr.style).hash(self.st);
                 self.hash_meta_item(&*attr.value);
             }
index 51ffb1ebc8e99ae1d687fa5c8cfe99e1b1198890..3bf7cc0f74c75f0acd9a42c8bef2f6c4c174cbec 100644 (file)
@@ -772,9 +772,9 @@ fn get_lints(&self) -> LintArray {
 
 impl EarlyLintPass for DeprecatedAttr {
     fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
-        let name = &*attr.name();
+        let name = attr.name();
         for &&(n, _, ref g) in &self.depr_attrs {
-            if n == name {
+            if name == n {
                 if let &AttributeGate::Gated(Stability::Deprecated(link),
                                              ref name,
                                              ref reason,
index aaca823369bf8bbf980d4a9bec8aabd6a74817d7..5ff131b06848e88420a1be863797a10e20db497c 100644 (file)
@@ -274,7 +274,7 @@ fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
             // Has a plugin registered this attribute as one which must be used at
             // the crate level?
             let plugin_crate = plugin_attributes.iter()
-                .find(|&&(ref x, t)| &*attr.name() == x && AttributeType::CrateLevel == t)
+                .find(|&&(ref x, t)| attr.name() == &**x && AttributeType::CrateLevel == t)
                 .is_some();
             if known_crate || plugin_crate {
                 let msg = match attr.style {
index 5384535024e537f23e8c3ec1d119389be26a0f57..525b8f8227b0896d3076a0b5b823b82270d15e4c 100644 (file)
@@ -37,7 +37,7 @@
 use syntax::attr;
 use syntax::ext::base::SyntaxExtension;
 use syntax::feature_gate::{self, GateIssue};
-use syntax::parse::token::{InternedString, intern};
+use syntax::parse::token::{self, InternedString};
 use syntax_pos::{Span, DUMMY_SP};
 use log;
 
@@ -582,11 +582,11 @@ fn register_custom_derive(&mut self,
                                       trait_name: &str,
                                       expand: fn(TokenStream) -> TokenStream,
                                       attributes: &[&'static str]) {
-                let attrs = attributes.iter().map(|s| InternedString::new(s)).collect();
+                let attrs = attributes.iter().cloned().map(token::intern).collect();
                 let derive = SyntaxExtension::CustomDerive(
                     Box::new(CustomDerive::new(expand, attrs))
                 );
-                self.0.push((intern(trait_name), Rc::new(derive)));
+                self.0.push((token::intern(trait_name), Rc::new(derive)));
             }
         }
 
index 4438241999a3940e4f6c289d0032f0bb473569fc..1bfc445fca98d72ca4f7c8f03a92b63dda875fc1 100644 (file)
@@ -69,9 +69,9 @@ pub fn load_plugins(sess: &Session,
             for plugin in plugins {
                 // plugins must have a name and can't be key = value
                 match plugin.name() {
-                    Some(ref name) if !plugin.is_value_str() => {
+                    Some(name) if !plugin.is_value_str() => {
                         let args = plugin.meta_item_list().map(ToOwned::to_owned);
-                        loader.load_plugin(plugin.span, name, args.unwrap_or_default());
+                        loader.load_plugin(plugin.span, &name.as_str(), args.unwrap_or_default());
                     },
                     _ => call_malformed_plugin_attribute(sess, attr.span),
                 }
index 5d743fc5d4e4db17faf4717eb154308cb54e33d0..8a973ab4d954b267e6a380e6cdc058e2fc5fb051 100644 (file)
@@ -31,7 +31,6 @@
 
 use syntax::ast::Name;
 use syntax::attr;
-use syntax::parse::token;
 
 use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
 use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
@@ -632,7 +631,7 @@ fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImpor
                 match attr.meta_item_list() {
                     Some(names) => for attr in names {
                         if let Some(word) = attr.word() {
-                            imports.imports.push((token::intern(&word.name()), attr.span()));
+                            imports.imports.push((word.name(), attr.span()));
                         } else {
                             span_err!(self.session, attr.span(), E0466, "bad macro import");
                         }
@@ -646,7 +645,7 @@ fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImpor
                 if let Some(names) = attr.meta_item_list() {
                     for attr in names {
                         if let Some(word) = attr.word() {
-                            imports.reexports.push((token::intern(&word.name()), attr.span()));
+                            imports.reexports.push((word.name(), attr.span()));
                         } else {
                             bad_macro_reexport(self, attr.span());
                         }
index 524d491a464e2525e178cb531e830edd5befa535..1a8116872be436ec303b5cc6e3773bba62c5b6ed 100644 (file)
@@ -27,7 +27,6 @@
 use syntax::ext::hygiene::Mark;
 use syntax::ext::tt::macro_rules;
 use syntax::fold::Folder;
-use syntax::parse::token::intern;
 use syntax::ptr::P;
 use syntax::util::lev_distance::find_best_match_for_name;
 use syntax::visit::Visitor;
@@ -207,8 +206,7 @@ fn resolve_imports(&mut self) {
 
     fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
         for i in 0..attrs.len() {
-            let name = intern(&attrs[i].name());
-            match self.builtin_macros.get(&name).cloned() {
+            match self.builtin_macros.get(&attrs[i].name()).cloned() {
                 Some(binding) => match *self.get_macro(binding) {
                     MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
                         return Some(attrs.remove(i))
index c8e350e475af16a412ca2e0be3e36af998cda1cb..e5589b04108e7e965d7a9a63a03cae172c7fb93e 100644 (file)
@@ -54,7 +54,7 @@
 
 use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID};
 use syntax::parse::lexer::comments::strip_doc_comment_decoration;
-use syntax::parse::token::{self, keywords, InternedString};
+use syntax::parse::token::{self, keywords};
 use syntax::visit::{self, Visitor};
 use syntax::print::pprust::{ty_to_string, arg_to_string};
 use syntax::codemap::MacroAttribute;
@@ -728,7 +728,7 @@ fn visit_pat(&mut self, p: &ast::Pat) {
 }
 
 fn docs_for_attrs(attrs: &[Attribute]) -> String {
-    let doc = InternedString::new("doc");
+    let doc = token::intern("doc");
     let mut result = String::new();
 
     for attr in attrs {
index bc6d21cab642fd21f989f048a2a191fd16c6c640..8de843fdcb8c4057898169738ac712b459f111de 100644 (file)
@@ -75,6 +75,12 @@ fn decode<D: Decoder>(d: &mut D) -> Result<Name, D::Error> {
     }
 }
 
+impl<'a> ::std::cmp::PartialEq<&'a str> for Name {
+    fn eq(&self, other: &&str) -> bool {
+        *self.as_str() == **other
+    }
+}
+
 impl Ident {
     pub const fn with_empty_ctxt(name: Name) -> Ident {
         Ident { name: name, ctxt: SyntaxContext::empty() }
@@ -518,15 +524,15 @@ pub enum MetaItemKind {
     /// Word meta item.
     ///
     /// E.g. `test` as in `#[test]`
-    Word(InternedString),
+    Word(Name),
     /// List meta item.
     ///
     /// E.g. `derive(..)` as in `#[derive(..)]`
-    List(InternedString, Vec<NestedMetaItem>),
+    List(Name, Vec<NestedMetaItem>),
     /// Name value meta item.
     ///
     /// E.g. `feature = "foo"` as in `#[feature = "foo"]`
-    NameValue(InternedString, Lit),
+    NameValue(Name, Lit),
 }
 
 // can't be derived because the MetaItemKind::List requires an unordered comparison
index 8f3ef0e16df5ed53d5521eca3e98fe9f6997bb3d..220ecf52ae06b083ad499fc5cf72fa6cdbb26949 100644 (file)
@@ -15,7 +15,7 @@
 pub use self::IntType::*;
 
 use ast;
-use ast::{AttrId, Attribute};
+use ast::{AttrId, Attribute, Name};
 use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
 use ast::{Lit, Expr, Item, Local, Stmt, StmtKind};
 use codemap::{respan, spanned, dummy_spanned, mk_sp};
@@ -37,8 +37,8 @@
 }
 
 enum AttrError {
-    MultipleItem(InternedString),
-    UnknownMetaItem(InternedString),
+    MultipleItem(Name),
+    UnknownMetaItem(Name),
     MissingSince,
     MissingFeature,
     MultipleStabilityLevels,
@@ -134,7 +134,7 @@ pub fn check_name(&self, name: &str) -> bool {
 
     /// Returns the name of the meta item, e.g. `foo` in `#[foo]`,
     /// `#[foo="bar"]` and `#[foo(bar)]`, if self is a MetaItem
-    pub fn name(&self) -> Option<InternedString> {
+    pub fn name(&self) -> Option<Name> {
         self.meta_item().and_then(|meta_item| Some(meta_item.name()))
     }
 
@@ -186,14 +186,14 @@ pub fn is_meta_item_list(&self) -> bool {
 
 impl Attribute {
     pub fn check_name(&self, name: &str) -> bool {
-        let matches = name == &self.name()[..];
+        let matches = self.name() == name;
         if matches {
             mark_used(self);
         }
         matches
     }
 
-    pub fn name(&self) -> InternedString { self.meta().name() }
+    pub fn name(&self) -> Name { self.meta().name() }
 
     pub fn value_str(&self) -> Option<InternedString> {
         self.meta().value_str()
@@ -218,11 +218,11 @@ pub fn is_value_str(&self) -> bool {
 }
 
 impl MetaItem {
-    pub fn name(&self) -> InternedString {
+    pub fn name(&self) -> Name {
         match self.node {
-            MetaItemKind::Word(ref n) => (*n).clone(),
-            MetaItemKind::NameValue(ref n, _) => (*n).clone(),
-            MetaItemKind::List(ref n, _) => (*n).clone(),
+            MetaItemKind::Word(n) => n,
+            MetaItemKind::NameValue(n, _) => n,
+            MetaItemKind::List(n, _) => n,
         }
     }
 
@@ -255,7 +255,7 @@ pub fn is_word(&self) -> bool {
     pub fn span(&self) -> Span { self.span }
 
     pub fn check_name(&self, name: &str) -> bool {
-        name == &self.name()[..]
+        self.name() == name
     }
 
     pub fn is_value_str(&self) -> bool {
@@ -282,7 +282,7 @@ pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
         if self.is_sugared_doc {
             let comment = self.value_str().unwrap();
             let meta = mk_name_value_item_str(
-                InternedString::new("doc"),
+                token::intern("doc"),
                 token::intern_and_get_ident(&strip_doc_comment_decoration(
                         &comment)));
             if self.style == ast::AttrStyle::Outer {
@@ -298,40 +298,36 @@ pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
 
 /* Constructors */
 
-pub fn mk_name_value_item_str(name: InternedString, value: InternedString)
-                              -> P<MetaItem> {
+pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P<MetaItem> {
     let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
     mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
 }
 
-pub fn mk_name_value_item(name: InternedString, value: ast::Lit)
-                          -> P<MetaItem> {
+pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P<MetaItem> {
     mk_spanned_name_value_item(DUMMY_SP, name, value)
 }
 
-pub fn mk_list_item(name: InternedString, items: Vec<NestedMetaItem>) -> P<MetaItem> {
+pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
     mk_spanned_list_item(DUMMY_SP, name, items)
 }
 
-pub fn mk_list_word_item(name: InternedString) -> ast::NestedMetaItem {
+pub fn mk_list_word_item(name: Name) -> ast::NestedMetaItem {
     dummy_spanned(NestedMetaItemKind::MetaItem(mk_spanned_word_item(DUMMY_SP, name)))
 }
 
-pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
+pub fn mk_word_item(name: Name) -> P<MetaItem> {
     mk_spanned_word_item(DUMMY_SP, name)
 }
 
-pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit)
-                          -> P<MetaItem> {
+pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
     P(respan(sp, MetaItemKind::NameValue(name, value)))
 }
 
-pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec<NestedMetaItem>)
-                            -> P<MetaItem> {
+pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
     P(respan(sp, MetaItemKind::List(name, items)))
 }
 
-pub fn mk_spanned_word_item(sp: Span, name: InternedString) -> P<MetaItem> {
+pub fn mk_spanned_word_item(sp: Span, name: Name) -> P<MetaItem> {
     P(respan(sp, MetaItemKind::Word(name)))
 }
 
@@ -398,7 +394,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
     Attribute {
         id: id,
         style: style,
-        value: P(spanned(lo, hi, MetaItemKind::NameValue(InternedString::new("doc"), lit))),
+        value: P(spanned(lo, hi, MetaItemKind::NameValue(token::intern("doc"), lit))),
         is_sugared_doc: true,
         span: mk_sp(lo, hi),
     }
@@ -490,11 +486,11 @@ pub enum InlineAttr {
 pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
     attrs.iter().fold(InlineAttr::None, |ia,attr| {
         match attr.value.node {
-            MetaItemKind::Word(ref n) if n == "inline" => {
+            MetaItemKind::Word(n) if n == "inline" => {
                 mark_used(attr);
                 InlineAttr::Hint
             }
-            MetaItemKind::List(ref n, ref items) if n == "inline" => {
+            MetaItemKind::List(n, ref items) if n == "inline" => {
                 mark_used(attr);
                 if items.len() != 1 {
                     diagnostic.map(|d|{ span_err!(d, attr.span, E0534, "expected one argument"); });
@@ -537,7 +533,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
 
             // The unwraps below may look dangerous, but we've already asserted
             // that they won't fail with the loop above.
-            match &pred[..] {
+            match &*pred.as_str() {
                 "any" => mis.iter().any(|mi| {
                     cfg_matches(mi.meta_item().unwrap(), sess, features)
                 }),
@@ -611,7 +607,6 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
 
     'outer: for attr in attrs_iter {
         let tag = attr.name();
-        let tag = &*tag;
         if tag != "rustc_deprecated" && tag != "unstable" && tag != "stable" {
             continue // not a stability level
         }
@@ -633,7 +628,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                 }
             };
 
-            match tag {
+            match &*tag.as_str() {
                 "rustc_deprecated" => {
                     if rustc_depr.is_some() {
                         span_err!(diagnostic, item_sp, E0540,
@@ -645,7 +640,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                     let mut reason = None;
                     for meta in metas {
                         if let Some(mi) = meta.meta_item() {
-                            match &*mi.name() {
+                            match &*mi.name().as_str() {
                                 "since" => if !get(mi, &mut since) { continue 'outer },
                                 "reason" => if !get(mi, &mut reason) { continue 'outer },
                                 _ => {
@@ -688,7 +683,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                     let mut issue = None;
                     for meta in metas {
                         if let Some(mi) = meta.meta_item() {
-                            match &*mi.name() {
+                            match &*mi.name().as_str() {
                                 "feature" => if !get(mi, &mut feature) { continue 'outer },
                                 "reason" => if !get(mi, &mut reason) { continue 'outer },
                                 "issue" => if !get(mi, &mut issue) { continue 'outer },
@@ -743,7 +738,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
                     let mut since = None;
                     for meta in metas {
                         if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
-                            match &*mi.name() {
+                            match &*mi.name().as_str() {
                                 "feature" => if !get(mi, &mut feature) { continue 'outer },
                                 "since" => if !get(mi, &mut since) { continue 'outer },
                                 _ => {
@@ -839,7 +834,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
             let mut note = None;
             for meta in metas {
                 if let NestedMetaItemKind::MetaItem(ref mi) = meta.node {
-                    match &*mi.name() {
+                    match &*mi.name().as_str() {
                         "since" => if !get(mi, &mut since) { continue 'outer },
                         "note" => if !get(mi, &mut note) { continue 'outer },
                         _ => {
@@ -897,7 +892,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
 pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
     let mut acc = Vec::new();
     match attr.value.node {
-        ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
+        ast::MetaItemKind::List(s, ref items) if s == "repr" => {
             mark_used(attr);
             for item in items {
                 if !item.is_meta_item() {
@@ -906,7 +901,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
                 }
 
                 if let Some(mi) = item.word() {
-                    let word = &*mi.name();
+                    let word = &*mi.name().as_str();
                     let hint = match word {
                         // Can't use "extern" because it's not a lexical identifier.
                         "C" => Some(ReprExtern),
index c3e28cbb006a07795499c4af50cae727df286ed4..75e931351717c87a25aed93968dc55d45ccf4802 100644 (file)
@@ -277,18 +277,18 @@ fn item_ty_poly(&self,
 
     fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
 
-    fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem>;
+    fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem>;
 
-    fn meta_list_item_word(&self, sp: Span, w: InternedString) -> ast::NestedMetaItem;
+    fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem;
 
     fn meta_list(&self,
                  sp: Span,
-                 name: InternedString,
+                 name: ast::Name,
                  mis: Vec<ast::NestedMetaItem> )
                  -> P<ast::MetaItem>;
     fn meta_name_value(&self,
                        sp: Span,
-                       name: InternedString,
+                       name: ast::Name,
                        value: ast::LitKind)
                        -> P<ast::MetaItem>;
 
@@ -1150,20 +1150,20 @@ fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
         attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi)
     }
 
-    fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem> {
+    fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem> {
         attr::mk_spanned_word_item(sp, w)
     }
 
-    fn meta_list_item_word(&self, sp: Span, w: InternedString) -> ast::NestedMetaItem {
+    fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem {
         respan(sp, ast::NestedMetaItemKind::MetaItem(attr::mk_spanned_word_item(sp, w)))
     }
 
-    fn meta_list(&self, sp: Span, name: InternedString, mis: Vec<ast::NestedMetaItem>)
+    fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
                  -> P<ast::MetaItem> {
         attr::mk_spanned_list_item(sp, name, mis)
     }
 
-    fn meta_name_value(&self, sp: Span, name: InternedString, value: ast::LitKind)
+    fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
                        -> P<ast::MetaItem> {
         attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
     }
index 841a6bb1b06c0fdda36149bf9274f7994c026c65..a2d42e1459208cb8baa68a23100e309e1cb59640 100644 (file)
@@ -23,7 +23,7 @@
 use fold::*;
 use parse::{ParseSess, PResult, lexer};
 use parse::parser::Parser;
-use parse::token::{self, intern, keywords};
+use parse::token::{self, keywords};
 use print::pprust;
 use ptr::P;
 use std_inject;
@@ -246,7 +246,7 @@ fn expand(&mut self, expansion: Expansion) -> Expansion {
                     self.cx.resolver.resolve_macro(scope, &mac.node.path, force)
                 }
                 InvocationKind::Attr { ref attr, .. } => {
-                    let ident = ast::Ident::with_empty_ctxt(intern(&*attr.name()));
+                    let ident = ast::Ident::with_empty_ctxt(attr.name());
                     let path = ast::Path::from_ident(attr.span, ident);
                     self.cx.resolver.resolve_macro(scope, &path, force)
                 }
@@ -341,7 +341,7 @@ fn expand_attr_invoc(&mut self, invoc: Invocation, ext: Rc<SyntaxExtension>) ->
         };
 
         attr::mark_used(&attr);
-        let name = intern(&attr.name());
+        let name = attr.name();
         self.cx.bt_push(ExpnInfo {
             call_site: attr.span,
             callee: NameAndSpan {
index 2416ead122404f36837d3070f000f7c382d6863a..b002378601a80dccc058c264d55065daf7c15df8 100644 (file)
@@ -757,7 +757,7 @@ pub struct GatedCfg {
 
 impl GatedCfg {
     pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> {
-        let name = cfg.name();
+        let name = &*cfg.name().as_str();
         GATED_CFGS.iter()
                   .position(|info| info.0 == name)
                   .map(|idx| {
@@ -804,7 +804,7 @@ macro_rules! gate_feature {
 impl<'a> Context<'a> {
     fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
         debug!("check_attribute(attr = {:?})", attr);
-        let name = &*attr.name();
+        let name = &*attr.name().as_str();
         for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES {
             if n == name {
                 if let &Gated(_, ref name, ref desc, ref has_feature) = gateage {
@@ -1351,7 +1351,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> F
             Some(list) => {
                 for mi in list {
                     let name = if let Some(word) = mi.word() {
-                        word.name()
+                        word.name().as_str()
                     } else {
                         span_err!(span_handler, mi.span, E0556,
                                   "malformed feature, expected just one word");
index 8818b94209e02e5ea7cbc1edc4d7683c8991f32f..c72c4646a236f57f8259b5b355cb767e3f6142a9 100644 (file)
@@ -227,22 +227,21 @@ pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
 
         let lo = self.span.lo;
         let ident = self.parse_ident()?;
-        let name = self.id_to_interned_str(ident);
         match self.token {
             token::Eq => {
                 self.bump();
                 let lit = self.parse_unsuffixed_lit()?;
                 let hi = self.prev_span.hi;
-                Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(name, lit))))
+                Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(ident.name, lit))))
             }
             token::OpenDelim(token::Paren) => {
                 let inner_items = self.parse_meta_seq()?;
                 let hi = self.prev_span.hi;
-                Ok(P(spanned(lo, hi, ast::MetaItemKind::List(name, inner_items))))
+                Ok(P(spanned(lo, hi, ast::MetaItemKind::List(ident.name, inner_items))))
             }
             _ => {
                 let hi = self.prev_span.hi;
-                Ok(P(spanned(lo, hi, ast::MetaItemKind::Word(name))))
+                Ok(P(spanned(lo, hi, ast::MetaItemKind::Word(ident.name))))
             }
         }
     }
index ea4a9177d426bb2d9787112eb79b4adc19ae273d..c86302f4e2596b3bfc7832bf1ea9aed93f6da2be 100644 (file)
@@ -19,7 +19,7 @@
 use codemap::{self, CodeMap};
 use syntax_pos::{self, BytePos};
 use errors;
-use parse::token::{self, keywords, BinOpToken, Token, InternedString};
+use parse::token::{self, keywords, BinOpToken, Token};
 use parse::lexer::comments;
 use parse;
 use print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
@@ -119,14 +119,13 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
         // of the feature gate, so we fake them up here.
 
         // #![feature(prelude_import)]
-        let prelude_import_meta = attr::mk_list_word_item(InternedString::new("prelude_import"));
-        let list = attr::mk_list_item(InternedString::new("feature"),
-                                      vec![prelude_import_meta]);
+        let prelude_import_meta = attr::mk_list_word_item(token::intern("prelude_import"));
+        let list = attr::mk_list_item(token::intern("feature"), vec![prelude_import_meta]);
         let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list);
         try!(s.print_attribute(&fake_attr));
 
         // #![no_std]
-        let no_std_meta = attr::mk_word_item(InternedString::new("no_std"));
+        let no_std_meta = attr::mk_word_item(token::intern("no_std"));
         let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), no_std_meta);
         try!(s.print_attribute(&fake_attr));
     }
@@ -779,15 +778,15 @@ fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> {
         try!(self.ibox(INDENT_UNIT));
         match item.node {
             ast::MetaItemKind::Word(ref name) => {
-                try!(word(self.writer(), &name));
+                try!(word(self.writer(), &name.as_str()));
             }
             ast::MetaItemKind::NameValue(ref name, ref value) => {
-                try!(self.word_space(&name[..]));
+                try!(self.word_space(&name.as_str()));
                 try!(self.word_space("="));
                 try!(self.print_literal(value));
             }
             ast::MetaItemKind::List(ref name, ref items) => {
-                try!(word(self.writer(), &name));
+                try!(word(self.writer(), &name.as_str()));
                 try!(self.popen());
                 try!(self.commasep(Consistent,
                               &items[..],
index f0cfd42c8240b5e76932449137c5f251ed93461c..8cc0e01b24e52c0c1da397f7cc9d7d2c0ac0c7ae 100644 (file)
@@ -12,7 +12,7 @@
 use attr;
 use syntax_pos::{DUMMY_SP, Span};
 use codemap::{self, ExpnInfo, NameAndSpan, MacroAttribute};
-use parse::token::{intern, InternedString, keywords};
+use parse::token::{intern, keywords};
 use parse::{token, ParseSess};
 use ptr::P;
 
@@ -57,7 +57,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
 
     krate.module.items.insert(0, P(ast::Item {
         attrs: vec![attr::mk_attr_outer(attr::mk_attr_id(),
-                                        attr::mk_word_item(InternedString::new("macro_use")))],
+                                        attr::mk_word_item(token::intern("macro_use")))],
         vis: ast::Visibility::Inherited,
         node: ast::ItemKind::ExternCrate(Some(crate_name)),
         ident: token::str_to_ident(name),
@@ -70,7 +70,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
         attrs: vec![ast::Attribute {
             style: ast::AttrStyle::Outer,
             value: P(ast::MetaItem {
-                node: ast::MetaItemKind::Word(token::intern_and_get_ident("prelude_import")),
+                node: ast::MetaItemKind::Word(token::intern("prelude_import")),
                 span: span,
             }),
             id: attr::mk_attr_id(),
index 59a7e75d12557039c10813c7dd1b88c67dfc76bb..194bd4a90855e61138d56ca1facf7042d4a94262 100644 (file)
@@ -191,8 +191,8 @@ fn fold_item(&mut self, i: P<ast::Item>) -> SmallVector<P<ast::Item>> {
             EntryPointType::MainAttr |
             EntryPointType::Start =>
                 folded.map(|ast::Item {id, ident, attrs, node, vis, span}| {
-                    let allow_str = InternedString::new("allow");
-                    let dead_code_str = InternedString::new("dead_code");
+                    let allow_str = token::intern("allow");
+                    let dead_code_str = token::intern("dead_code");
                     let word_vec = vec![attr::mk_list_word_item(dead_code_str)];
                     let allow_dead_code_item = attr::mk_list_item(allow_str, word_vec);
                     let allow_dead_code = attr::mk_attr_outer(attr::mk_attr_id(),
@@ -229,8 +229,8 @@ fn mk_reexport_mod(cx: &mut TestCtxt, parent: ast::NodeId, tests: Vec<ast::Ident
     // Generate imports with `#[allow(private_in_public)]` to work around issue #36768.
     let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list(
         DUMMY_SP,
-        InternedString::new("allow"),
-        vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, InternedString::new("private_in_public"))],
+        token::intern("allow"),
+        vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, token::intern("private_in_public"))],
     ));
     let items = tests.into_iter().map(|r| {
         cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public,
@@ -496,7 +496,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
                                        vec![tests_ident_expr]);
     let call_test_main = ecx.stmt_expr(call_test_main);
     // #![main]
-    let main_meta = ecx.meta_word(sp, token::intern_and_get_ident("main"));
+    let main_meta = ecx.meta_word(sp, token::intern("main"));
     let main_attr = ecx.attribute(sp, main_meta);
     // pub fn main() { ... }
     let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));
index d7bc2a6faeeb993f29f60007b80e88e07815bdb4..c2a166e0819b5bc2cb34f38592a24f0279b99411 100644 (file)
@@ -15,7 +15,7 @@
 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,
index fa0fb2492c551c439287a6be89795bbe1cbc758d..a1be573551eb0863586e7c0ffc9d28ce3ced5932 100644 (file)
@@ -14,7 +14,7 @@
 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,
index 6b2e36e63b65708d5152098d517405b075de9cea..85d29f5e21394b756e6d175347b9244112cf85de 100644 (file)
@@ -14,7 +14,7 @@
 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,
index c46d4b34173f65fb48acefd057fc044264985ba5..1b6ccfd012cd20d6f60e4cef6869d44da8a9aab5 100644 (file)
@@ -14,7 +14,7 @@
 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 @@ fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
 
     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,
index 597ff306b3dd8edf4c7cb08d145cdd0a25f73be2..7d76722ee97d688767aadb20f926035aaabea691 100644 (file)
@@ -16,7 +16,7 @@
 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 @@ macro_rules! md {
                                     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 {
index e101757ad23220dfabebc1a5a1ba707b245ca084..1076a6a6d63a5bef4e90c8816dc9304af46c4b8d 100644 (file)
 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 @@ fn visit_attribute(&mut self, attr: &Attribute) {
 
 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 }
     }
 }
index b15fd2b49a65547c241ed463f0c5a55767754f71..0b97213394b4d960f3a7bcf9bb7d5573bfa94d3f 100644 (file)
@@ -14,7 +14,7 @@
 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,
index e6b63be3efc0d963f063d7b665c56966f38bf8b3..b245e399f1cdc89617254ccf04b87737177daab1 100644 (file)
 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 @@ pub fn expand_ext(&self,
                 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 @@ fn create_derived_impl(&self,
 
         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());
 
index 09d529f5313f880f6e832145c346f98b004a28e0..32dcdcfd1107e84cd640afa67d96df251461a729 100644 (file)
@@ -16,7 +16,7 @@
 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,
         },
index 36fd6408b4f316287d8db0d2ff27b814b57372e1..1165eb46bf011466e1336893ad9aaed053287595 100644 (file)
@@ -17,7 +17,7 @@
 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;
 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 @@ fn visit_item(&mut self, item: &ast::Item) {
             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);