diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 8ba52cdb64f5..abc35634d15f 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -64,7 +64,7 @@ impl<'a> CheckAttrVisitor<'a> { 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 @@ impl<'a> CheckAttrVisitor<'a> { } 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), diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index e9d2aa7e7750..4a082944010b 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -40,7 +40,6 @@ use std::default::Default as StdDefault; 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> { +pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec> { 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> { +pub fn gather_attr(attr: &ast::Attribute) -> Vec> { 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 @@ pub trait LintContext: Sized { 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, diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 991398813752..09c1bd0dd126 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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, _ => (), } } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 16522a73f56a..1502811baee2 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -26,7 +26,7 @@ use middle::cstore; 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::>(); v.extend_from_slice(&default_cfg[..]); diff --git a/src/librustc_driver/target_features.rs b/src/librustc_driver/target_features.rs index 57a9edc5c586..436b44d8b03b 100644 --- a/src/librustc_driver/target_features.rs +++ b/src/librustc_driver/target_features.rs @@ -13,8 +13,7 @@ use llvm::LLVMRustHasFeature; 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]))) } } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 998cbae2cce1..87e6b2befdc3 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -57,7 +57,6 @@ use std::env; 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)>; -type Targets = Vec<(Span, InternedString, ast::NodeId, DepNode)>; +type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode)>; 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 { + fn argument(&self, attr: &ast::Attribute) -> Option { let mut value = None; for list_item in attr.meta_item_list().unwrap_or_default() { match list_item.word() { @@ -127,8 +126,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { 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 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { } 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 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { } }; self.then_this_would_need.push((attr.span, - dep_node_interned.clone().unwrap(), + dep_node_interned.unwrap(), node_id, dep_node)); } diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index 21c628d18bac..55dd222b0db5 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -875,16 +875,19 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { // 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 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { 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); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 51ffb1ebc8e9..3bf7cc0f74c7 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -772,9 +772,9 @@ impl LintPass for DeprecatedAttr { 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, diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index aaca823369bf..5ff131b06848 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -274,7 +274,7 @@ impl LateLintPass for UnusedAttributes { // 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 { diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 5384535024e5..525b8f8227b0 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -37,7 +37,7 @@ use syntax::abi::Abi; 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 @@ impl<'a> CrateLoader<'a> { 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))); } } diff --git a/src/librustc_plugin/load.rs b/src/librustc_plugin/load.rs index 4438241999a3..1bfc445fca98 100644 --- a/src/librustc_plugin/load.rs +++ b/src/librustc_plugin/load.rs @@ -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), } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 5d743fc5d4e4..8a973ab4d954 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -31,7 +31,6 @@ use std::rc::Rc; 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 @@ impl<'b> Resolver<'b> { 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 @@ impl<'b> Resolver<'b> { 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()); } diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 524d491a464e..1a8116872be4 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -27,7 +27,6 @@ use syntax::ext::expand::Expansion; 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 @@ impl<'a> base::Resolver for Resolver<'a> { fn find_attr_invoc(&mut self, attrs: &mut Vec) -> Option { 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)) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index c8e350e475af..e5589b04108e 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -54,7 +54,7 @@ use std::path::{Path, PathBuf}; 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 @@ impl Visitor for PathCollector { } 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 { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bc6d21cab642..8de843fdcb8c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -75,6 +75,12 @@ impl Decodable for Name { } } +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), + List(Name, Vec), /// 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 diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 8f3ef0e16df5..220ecf52ae06 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -15,7 +15,7 @@ pub use self::ReprAttr::*; 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 @@ thread_local! { } enum AttrError { - MultipleItem(InternedString), - UnknownMetaItem(InternedString), + MultipleItem(Name), + UnknownMetaItem(Name), MissingSince, MissingFeature, MultipleStabilityLevels, @@ -134,7 +134,7 @@ impl NestedMetaItem { /// 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 { + pub fn name(&self) -> Option { self.meta_item().and_then(|meta_item| Some(meta_item.name())) } @@ -186,14 +186,14 @@ impl NestedMetaItem { 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 { self.meta().value_str() @@ -218,11 +218,11 @@ impl Attribute { } 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 @@ impl MetaItem { 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 @@ impl Attribute { 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 @@ impl Attribute { /* Constructors */ -pub fn mk_name_value_item_str(name: InternedString, value: InternedString) - -> P { +pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P { 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 { +pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P { mk_spanned_name_value_item(DUMMY_SP, name, value) } -pub fn mk_list_item(name: InternedString, items: Vec) -> P { +pub fn mk_list_item(name: Name, items: Vec) -> P { 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 { +pub fn mk_word_item(name: Name) -> P { mk_spanned_word_item(DUMMY_SP, name) } -pub fn mk_spanned_name_value_item(sp: Span, name: InternedString, value: ast::Lit) - -> P { +pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P { P(respan(sp, MetaItemKind::NameValue(name, value))) } -pub fn mk_spanned_list_item(sp: Span, name: InternedString, items: Vec) - -> P { +pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec) -> P { P(respan(sp, MetaItemKind::List(name, items))) } -pub fn mk_spanned_word_item(sp: Span, name: InternedString) -> P { +pub fn mk_spanned_word_item(sp: Span, name: Name) -> P { 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]) { pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec { 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 } 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), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c3e28cbb006a..75e931351717 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -277,18 +277,18 @@ pub trait AstBuilder { fn attribute(&self, sp: Span, mi: P) -> ast::Attribute; - fn meta_word(&self, sp: Span, w: InternedString) -> P; + fn meta_word(&self, sp: Span, w: ast::Name) -> P; - 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 ) -> P; fn meta_name_value(&self, sp: Span, - name: InternedString, + name: ast::Name, value: ast::LitKind) -> P; @@ -1150,20 +1150,20 @@ impl<'a> AstBuilder for ExtCtxt<'a> { attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi) } - fn meta_word(&self, sp: Span, w: InternedString) -> P { + fn meta_word(&self, sp: Span, w: ast::Name) -> P { 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) + fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec) -> P { 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 { attr::mk_spanned_name_value_item(sp, name, respan(sp, value)) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 841a6bb1b06c..a2d42e145920 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -23,7 +23,7 @@ use fold; 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 @@ impl<'a, 'b> MacroExpander<'a, 'b> { 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 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; attr::mark_used(&attr); - let name = intern(&attr.name()); + let name = attr.name(); self.cx.bt_push(ExpnInfo { call_site: attr.span, callee: NameAndSpan { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 2416ead12240..b002378601a8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -757,7 +757,7 @@ pub struct GatedCfg { impl GatedCfg { pub fn gate(cfg: &ast::MetaItem) -> Option { - 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"); diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 8818b94209e0..c72c4646a236 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -227,22 +227,21 @@ impl<'a> Parser<'a> { 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)))) } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ea4a9177d426..c86302f4e259 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -19,7 +19,7 @@ use attr; 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 @@ pub trait PrintState<'a> { 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[..], diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index f0cfd42c8240..8cc0e01b24e5 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -12,7 +12,7 @@ use ast; 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(), diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 59a7e75d1255..194bd4a90855 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -191,8 +191,8 @@ impl fold::Folder for EntryPointCleaner { 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 P { 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![])); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index d7bc2a6faeeb..c2a166e0819b 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 fa0fb2492c55..a1be573551eb 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 6b2e36e63b65..85d29f5e2139 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 c46d4b34173f..1b6ccfd012cd 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 597ff306b3dd..7d76722ee97d 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 e101757ad232..1076a6a6d63a 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, + attrs: Vec, } impl CustomDerive { - pub fn new(inner: fn(TokenStream) -> TokenStream, - attrs: Vec) - -> CustomDerive { + pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec) -> CustomDerive { CustomDerive { inner: inner, attrs: attrs } } } diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index b15fd2b49a65..0b97213394b4 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 e6b63be3efc0..b245e399f1cd 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 09d529f5313f..32dcdcfd1107 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 36fd6408b4f3..1165eb46bf01 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, + attrs: Vec, } 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::>() + cd.attrs.iter().map(|s| cx.expr_str(cd.span, s.as_str())).collect::>() ); (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);