None => continue,
};
- let (message, label) = match &*name {
+ let (message, label) = match &*name.as_str() {
"C" => {
conflicting_reprs += 1;
if target != Target::Struct &&
}
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),
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};
/// 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);
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,
};
};
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
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))
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,
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,
_ => (),
}
}
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;
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))
}
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[..]);
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
_ => &[],
};
- 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])))
}
}
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};
}
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>,
}
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() {
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(
} 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(
}
};
self.then_this_would_need.push((attr.span,
- dep_node_interned.clone().unwrap(),
+ dep_node_interned.unwrap(),
node_id,
dep_node));
}
// 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
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);
}
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,
// 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 {
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;
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)));
}
}
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),
}
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};
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");
}
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());
}
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;
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))
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;
}
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 {
}
}
+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() }
/// 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
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};
}
enum AttrError {
- MultipleItem(InternedString),
- UnknownMetaItem(InternedString),
+ MultipleItem(Name),
+ UnknownMetaItem(Name),
MissingSince,
MissingFeature,
MultipleStabilityLevels,
/// 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()))
}
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()
}
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,
}
}
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 {
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 {
/* 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)))
}
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),
}
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"); });
// 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)
}),
'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
}
}
};
- match tag {
+ match &*tag.as_str() {
"rustc_deprecated" => {
if rustc_depr.is_some() {
span_err!(diagnostic, item_sp, E0540,
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 },
_ => {
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 },
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 },
_ => {
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 },
_ => {
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() {
}
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),
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>;
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))
}
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;
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)
}
};
attr::mark_used(&attr);
- let name = intern(&attr.name());
+ let name = attr.name();
self.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
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| {
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 {
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");
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))))
}
}
}
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};
// 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));
}
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[..],
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;
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),
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(),
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(),
// 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,
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![]));
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;
_ => 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,
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;
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,
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;
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,
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;
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,
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;
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,
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 {
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) {
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 }
}
}
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;
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,
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;
attrs.extend(item.attrs
.iter()
.filter(|a| {
- match &a.name()[..] {
+ match &*a.name().as_str() {
"allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
_ => false,
}
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());
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;
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,
},
}
};
+ 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
});
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)
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));
}
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
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 {
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);
// 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| {
// 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| {
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,
},
};
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();
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,
}
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,
},
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> {
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");
}
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)| {
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);