Skip to content

Commit a262641

Browse files
committed
Refactor MetaItemKind to use Names instead of InternedStrings.
1 parent ff49942 commit a262641

File tree

33 files changed

+187
-206
lines changed

33 files changed

+187
-206
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a> CheckAttrVisitor<'a> {
6464
None => continue,
6565
};
6666

67-
let (message, label) = match &*name {
67+
let (message, label) = match &*name.as_str() {
6868
"C" => {
6969
conflicting_reprs += 1;
7070
if target != Target::Struct &&
@@ -120,7 +120,7 @@ impl<'a> CheckAttrVisitor<'a> {
120120
}
121121

122122
fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
123-
let name: &str = &attr.name();
123+
let name: &str = &attr.name().as_str();
124124
match name {
125125
"inline" => self.check_inline(attr, target),
126126
"repr" => self.check_repr(attr, target),

src/librustc/lint/context.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use std::default::Default as StdDefault;
4040
use std::mem;
4141
use std::fmt;
4242
use syntax::attr;
43-
use syntax::parse::token::InternedString;
4443
use syntax::ast;
4544
use syntax_pos::{MultiSpan, Span};
4645
use errors::{self, Diagnostic, DiagnosticBuilder};
@@ -384,8 +383,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $ps:ident, $($args:expr),*) => ({
384383
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
385384
/// attributes. Writing this as an iterator is an enormous mess.
386385
// See also the hir version just below.
387-
pub fn gather_attrs(attrs: &[ast::Attribute])
388-
-> Vec<Result<(InternedString, Level, Span), Span>> {
386+
pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec<Result<(ast::Name, Level, Span), Span>> {
389387
let mut out = vec![];
390388
for attr in attrs {
391389
let r = gather_attr(attr);
@@ -394,11 +392,10 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
394392
out
395393
}
396394

397-
pub fn gather_attr(attr: &ast::Attribute)
398-
-> Vec<Result<(InternedString, Level, Span), Span>> {
395+
pub fn gather_attr(attr: &ast::Attribute) -> Vec<Result<(ast::Name, Level, Span), Span>> {
399396
let mut out = vec![];
400397

401-
let level = match Level::from_str(&attr.name()) {
398+
let level = match Level::from_str(&attr.name().as_str()) {
402399
None => return out,
403400
Some(lvl) => lvl,
404401
};
@@ -414,9 +411,7 @@ pub fn gather_attr(attr: &ast::Attribute)
414411
};
415412

416413
for li in metas {
417-
out.push(li.word().map_or(Err(li.span), |word| {
418-
Ok((word.name().clone(), level, word.span))
419-
}));
414+
out.push(li.word().map_or(Err(li.span), |word| Ok((word.name(), level, word.span))));
420415
}
421416

422417
out
@@ -629,10 +624,10 @@ pub trait LintContext: Sized {
629624
continue;
630625
}
631626
Ok((lint_name, level, span)) => {
632-
match self.lints().find_lint(&lint_name, &self.sess(), Some(span)) {
627+
match self.lints().find_lint(&lint_name.as_str(), &self.sess(), Some(span)) {
633628
Ok(lint_id) => vec![(lint_id, level, span)],
634629
Err(FindLintError::NotFound) => {
635-
match self.lints().lint_groups.get(&lint_name[..]) {
630+
match self.lints().lint_groups.get(&*lint_name.as_str()) {
636631
Some(&(ref v, _)) => v.iter()
637632
.map(|lint_id: &LintId|
638633
(*lint_id, level, span))
@@ -1193,8 +1188,7 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
11931188
continue;
11941189
}
11951190
Ok((lint_name, _, span)) => {
1196-
match check_lint_name(&cx.lints,
1197-
&lint_name[..]) {
1191+
match check_lint_name(&cx.lints, &lint_name.as_str()) {
11981192
CheckLintNameResult::Ok => (),
11991193
CheckLintNameResult::Warning(ref msg) => {
12001194
cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,

src/librustc/middle/dead.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
309309
let dead_code = lint::builtin::DEAD_CODE.name_lower();
310310
for attr in lint::gather_attrs(attrs) {
311311
match attr {
312-
Ok((ref name, lint::Allow, _))
313-
if &name[..] == dead_code => return true,
312+
Ok((name, lint::Allow, _)) if name == &*dead_code => return true,
314313
_ => (),
315314
}
316315
}

src/librustc/session/config.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use middle::cstore;
2626

2727
use syntax::ast::{self, IntTy, UintTy};
2828
use syntax::attr;
29-
use syntax::parse;
29+
use syntax::parse::{self, token};
3030
use syntax::parse::token::InternedString;
3131
use syntax::feature_gate::UnstableFeatures;
3232

@@ -947,41 +947,40 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
947947

948948
let mk = attr::mk_name_value_item_str;
949949
let mut ret = vec![ // Target bindings.
950-
mk(InternedString::new("target_os"), intern(os)),
951-
mk(InternedString::new("target_family"), fam.clone()),
952-
mk(InternedString::new("target_arch"), intern(arch)),
953-
mk(InternedString::new("target_endian"), intern(end)),
954-
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
955-
mk(InternedString::new("target_env"), intern(env)),
956-
mk(InternedString::new("target_vendor"), intern(vendor)),
950+
mk(token::intern("target_os"), intern(os)),
951+
mk(token::intern("target_family"), fam.clone()),
952+
mk(token::intern("target_arch"), intern(arch)),
953+
mk(token::intern("target_endian"), intern(end)),
954+
mk(token::intern("target_pointer_width"), intern(wordsz)),
955+
mk(token::intern("target_env"), intern(env)),
956+
mk(token::intern("target_vendor"), intern(vendor)),
957957
];
958958
match &fam[..] {
959-
"windows" | "unix" => ret.push(attr::mk_word_item(fam)),
959+
"windows" | "unix" => ret.push(attr::mk_word_item(token::intern(&fam))),
960960
_ => (),
961961
}
962962
if sess.target.target.options.has_elf_tls {
963-
ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
963+
ret.push(attr::mk_word_item(token::intern("target_thread_local")));
964964
}
965965
for &i in &[8, 16, 32, 64, 128] {
966966
if i <= max_atomic_width {
967967
let s = i.to_string();
968-
ret.push(mk(InternedString::new("target_has_atomic"), intern(&s)));
968+
ret.push(mk(token::intern("target_has_atomic"), intern(&s)));
969969
if &s == wordsz {
970-
ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr")));
970+
ret.push(mk(token::intern("target_has_atomic"), intern("ptr")));
971971
}
972972
}
973973
}
974974
if sess.opts.debug_assertions {
975-
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
975+
ret.push(attr::mk_word_item(token::intern("debug_assertions")));
976976
}
977977
if sess.opts.crate_types.contains(&CrateTypeProcMacro) {
978-
ret.push(attr::mk_word_item(InternedString::new("proc_macro")));
978+
ret.push(attr::mk_word_item(token::intern("proc_macro")));
979979
}
980980
return ret;
981981
}
982982

983-
pub fn append_configuration(cfg: &mut ast::CrateConfig,
984-
name: InternedString) {
983+
pub fn append_configuration(cfg: &mut ast::CrateConfig, name: ast::Name) {
985984
if !cfg.iter().any(|mi| mi.name() == name) {
986985
cfg.push(attr::mk_word_item(name))
987986
}
@@ -995,7 +994,7 @@ pub fn build_configuration(sess: &Session,
995994
let default_cfg = default_configuration(sess);
996995
// If the user wants a test runner, then add the test cfg
997996
if sess.opts.test {
998-
append_configuration(&mut user_cfg, InternedString::new("test"))
997+
append_configuration(&mut user_cfg, token::intern("test"))
999998
}
1000999
let mut v = user_cfg.into_iter().collect::<Vec<_>>();
10011000
v.extend_from_slice(&default_cfg[..]);

src/librustc_driver/target_features.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use llvm::LLVMRustHasFeature;
1313
use rustc::session::Session;
1414
use rustc_trans::back::write::create_target_machine;
1515
use syntax::feature_gate::UnstableFeatures;
16-
use syntax::parse::token::InternedString;
17-
use syntax::parse::token::intern_and_get_ident as intern;
16+
use syntax::parse::token::{self, intern_and_get_ident as intern};
1817
use libc::c_char;
1918

2019
// 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) {
4140
_ => &[],
4241
};
4342

44-
let tf = InternedString::new("target_feature");
43+
let tf = token::intern("target_feature");
4544
for feat in whitelist {
4645
assert_eq!(feat.chars().last(), Some('\0'));
4746
if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
48-
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1])))
47+
cfg.push(attr::mk_name_value_item_str(tf, intern(&feat[..feat.len() - 1])))
4948
}
5049
}
5150

src/librustc_incremental/assert_dep_graph.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use std::env;
5757
use std::fs::File;
5858
use std::io::Write;
5959
use syntax::ast;
60-
use syntax::parse::token::InternedString;
6160
use syntax_pos::Span;
6261
use {ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
6362

@@ -97,7 +96,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
9796
}
9897

9998
type Sources = Vec<(Span, DefId, DepNode<DefId>)>;
100-
type Targets = Vec<(Span, InternedString, ast::NodeId, DepNode<DefId>)>;
99+
type Targets = Vec<(Span, ast::Name, ast::NodeId, DepNode<DefId>)>;
101100

102101
struct IfThisChanged<'a, 'tcx:'a> {
103102
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -106,7 +105,7 @@ struct IfThisChanged<'a, 'tcx:'a> {
106105
}
107106

108107
impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
109-
fn argument(&self, attr: &ast::Attribute) -> Option<InternedString> {
108+
fn argument(&self, attr: &ast::Attribute) -> Option<ast::Name> {
110109
let mut value = None;
111110
for list_item in attr.meta_item_list().unwrap_or_default() {
112111
match list_item.word() {
@@ -127,8 +126,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
127126
let dep_node_interned = self.argument(attr);
128127
let dep_node = match dep_node_interned {
129128
None => DepNode::Hir(def_id),
130-
Some(ref n) => {
131-
match DepNode::from_label_string(&n[..], def_id) {
129+
Some(n) => {
130+
match DepNode::from_label_string(&n.as_str(), def_id) {
132131
Ok(n) => n,
133132
Err(()) => {
134133
self.tcx.sess.span_fatal(
@@ -142,8 +141,8 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
142141
} else if attr.check_name(ATTR_THEN_THIS_WOULD_NEED) {
143142
let dep_node_interned = self.argument(attr);
144143
let dep_node = match dep_node_interned {
145-
Some(ref n) => {
146-
match DepNode::from_label_string(&n[..], def_id) {
144+
Some(n) => {
145+
match DepNode::from_label_string(&n.as_str(), def_id) {
147146
Ok(n) => n,
148147
Err(()) => {
149148
self.tcx.sess.span_fatal(
@@ -159,7 +158,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
159158
}
160159
};
161160
self.then_this_would_need.push((attr.span,
162-
dep_node_interned.clone().unwrap(),
161+
dep_node_interned.unwrap(),
163162
node_id,
164163
dep_node));
165164
}

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,16 +875,19 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
875875
// ignoring span information, it doesn't matter here
876876
self.hash_discriminant(&meta_item.node);
877877
match meta_item.node {
878-
ast::MetaItemKind::Word(ref s) => {
878+
ast::MetaItemKind::Word(s) => {
879+
let s = &*s.as_str();
879880
s.len().hash(self.st);
880881
s.hash(self.st);
881882
}
882-
ast::MetaItemKind::NameValue(ref s, ref lit) => {
883+
ast::MetaItemKind::NameValue(s, ref lit) => {
884+
let s = &*s.as_str();
883885
s.len().hash(self.st);
884886
s.hash(self.st);
885887
lit.node.hash(self.st);
886888
}
887-
ast::MetaItemKind::List(ref s, ref items) => {
889+
ast::MetaItemKind::List(s, ref items) => {
890+
let s = &*s.as_str();
888891
s.len().hash(self.st);
889892
s.hash(self.st);
890893
// Sort subitems so the hash does not depend on their order
@@ -916,7 +919,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
916919
for i in indices {
917920
let attr = &attributes[i];
918921
if !attr.is_sugared_doc &&
919-
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) {
922+
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
920923
SawAttribute(attr.style).hash(self.st);
921924
self.hash_meta_item(&*attr.value);
922925
}

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ impl LintPass for DeprecatedAttr {
772772

773773
impl EarlyLintPass for DeprecatedAttr {
774774
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
775-
let name = &*attr.name();
775+
let name = attr.name();
776776
for &&(n, _, ref g) in &self.depr_attrs {
777-
if n == name {
777+
if name == n {
778778
if let &AttributeGate::Gated(Stability::Deprecated(link),
779779
ref name,
780780
ref reason,

src/librustc_lint/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl LateLintPass for UnusedAttributes {
274274
// Has a plugin registered this attribute as one which must be used at
275275
// the crate level?
276276
let plugin_crate = plugin_attributes.iter()
277-
.find(|&&(ref x, t)| &*attr.name() == x && AttributeType::CrateLevel == t)
277+
.find(|&&(ref x, t)| attr.name() == &**x && AttributeType::CrateLevel == t)
278278
.is_some();
279279
if known_crate || plugin_crate {
280280
let msg = match attr.style {

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use syntax::abi::Abi;
3737
use syntax::attr;
3838
use syntax::ext::base::SyntaxExtension;
3939
use syntax::feature_gate::{self, GateIssue};
40-
use syntax::parse::token::{InternedString, intern};
40+
use syntax::parse::token::{self, InternedString};
4141
use syntax_pos::{Span, DUMMY_SP};
4242
use log;
4343

@@ -582,11 +582,11 @@ impl<'a> CrateLoader<'a> {
582582
trait_name: &str,
583583
expand: fn(TokenStream) -> TokenStream,
584584
attributes: &[&'static str]) {
585-
let attrs = attributes.iter().map(|s| InternedString::new(s)).collect();
585+
let attrs = attributes.iter().cloned().map(token::intern).collect();
586586
let derive = SyntaxExtension::CustomDerive(
587587
Box::new(CustomDerive::new(expand, attrs))
588588
);
589-
self.0.push((intern(trait_name), Rc::new(derive)));
589+
self.0.push((token::intern(trait_name), Rc::new(derive)));
590590
}
591591
}
592592

src/librustc_plugin/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ pub fn load_plugins(sess: &Session,
6969
for plugin in plugins {
7070
// plugins must have a name and can't be key = value
7171
match plugin.name() {
72-
Some(ref name) if !plugin.is_value_str() => {
72+
Some(name) if !plugin.is_value_str() => {
7373
let args = plugin.meta_item_list().map(ToOwned::to_owned);
74-
loader.load_plugin(plugin.span, name, args.unwrap_or_default());
74+
loader.load_plugin(plugin.span, &name.as_str(), args.unwrap_or_default());
7575
},
7676
_ => call_malformed_plugin_attribute(sess, attr.span),
7777
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use std::rc::Rc;
3131

3232
use syntax::ast::Name;
3333
use syntax::attr;
34-
use syntax::parse::token;
3534

3635
use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind};
3736
use syntax::ast::{Mutability, StmtKind, TraitItem, TraitItemKind};
@@ -632,7 +631,7 @@ impl<'b> Resolver<'b> {
632631
match attr.meta_item_list() {
633632
Some(names) => for attr in names {
634633
if let Some(word) = attr.word() {
635-
imports.imports.push((token::intern(&word.name()), attr.span()));
634+
imports.imports.push((word.name(), attr.span()));
636635
} else {
637636
span_err!(self.session, attr.span(), E0466, "bad macro import");
638637
}
@@ -646,7 +645,7 @@ impl<'b> Resolver<'b> {
646645
if let Some(names) = attr.meta_item_list() {
647646
for attr in names {
648647
if let Some(word) = attr.word() {
649-
imports.reexports.push((token::intern(&word.name()), attr.span()));
648+
imports.reexports.push((word.name(), attr.span()));
650649
} else {
651650
bad_macro_reexport(self, attr.span());
652651
}

src/librustc_resolve/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use syntax::ext::expand::Expansion;
2727
use syntax::ext::hygiene::Mark;
2828
use syntax::ext::tt::macro_rules;
2929
use syntax::fold::Folder;
30-
use syntax::parse::token::intern;
3130
use syntax::ptr::P;
3231
use syntax::util::lev_distance::find_best_match_for_name;
3332
use syntax::visit::Visitor;
@@ -207,8 +206,7 @@ impl<'a> base::Resolver for Resolver<'a> {
207206

208207
fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
209208
for i in 0..attrs.len() {
210-
let name = intern(&attrs[i].name());
211-
match self.builtin_macros.get(&name).cloned() {
209+
match self.builtin_macros.get(&attrs[i].name()).cloned() {
212210
Some(binding) => match *self.get_macro(binding) {
213211
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
214212
return Some(attrs.remove(i))

src/librustc_save_analysis/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use std::path::{Path, PathBuf};
5454

5555
use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID};
5656
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
57-
use syntax::parse::token::{self, keywords, InternedString};
57+
use syntax::parse::token::{self, keywords};
5858
use syntax::visit::{self, Visitor};
5959
use syntax::print::pprust::{ty_to_string, arg_to_string};
6060
use syntax::codemap::MacroAttribute;
@@ -728,7 +728,7 @@ impl Visitor for PathCollector {
728728
}
729729

730730
fn docs_for_attrs(attrs: &[Attribute]) -> String {
731-
let doc = InternedString::new("doc");
731+
let doc = token::intern("doc");
732732
let mut result = String::new();
733733

734734
for attr in attrs {

0 commit comments

Comments
 (0)