Skip to content

Commit e85a0d7

Browse files
committed
Use Symbol instead of InternedString in the AST, HIR, and various other places.
1 parent d2f8fb0 commit e85a0d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+399
-453
lines changed

src/librustc/hir/map/definitions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ impl DefPath {
115115
pub fn to_string(&self, tcx: TyCtxt) -> String {
116116
let mut s = String::with_capacity(self.data.len() * 16);
117117

118-
s.push_str(&tcx.original_crate_name(self.krate));
118+
s.push_str(&tcx.original_crate_name(self.krate).as_str());
119119
s.push_str("/");
120-
s.push_str(&tcx.crate_disambiguator(self.krate));
120+
s.push_str(&tcx.crate_disambiguator(self.krate).as_str());
121121

122122
for component in &self.data {
123123
write!(s,
@@ -137,8 +137,8 @@ impl DefPath {
137137
}
138138

139139
pub fn deterministic_hash_to<H: Hasher>(&self, tcx: TyCtxt, state: &mut H) {
140-
tcx.original_crate_name(self.krate).hash(state);
141-
tcx.crate_disambiguator(self.krate).hash(state);
140+
tcx.original_crate_name(self.krate).as_str().hash(state);
141+
tcx.crate_disambiguator(self.krate).as_str().hash(state);
142142
self.data.hash(state);
143143
}
144144
}

src/librustc/hir/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use syntax::abi::Abi;
4141
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
4242
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
4343
use syntax::ptr::P;
44-
use syntax::symbol::{keywords, InternedString};
44+
use syntax::symbol::{Symbol, keywords};
4545
use syntax::tokenstream::TokenTree;
4646
use syntax::util::ThinVec;
4747

@@ -1163,18 +1163,18 @@ pub enum Ty_ {
11631163

11641164
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
11651165
pub struct InlineAsmOutput {
1166-
pub constraint: InternedString,
1166+
pub constraint: Symbol,
11671167
pub is_rw: bool,
11681168
pub is_indirect: bool,
11691169
}
11701170

11711171
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
11721172
pub struct InlineAsm {
1173-
pub asm: InternedString,
1173+
pub asm: Symbol,
11741174
pub asm_str_style: StrStyle,
11751175
pub outputs: HirVec<InlineAsmOutput>,
1176-
pub inputs: HirVec<InternedString>,
1177-
pub clobbers: HirVec<InternedString>,
1176+
pub inputs: HirVec<Symbol>,
1177+
pub clobbers: HirVec<Symbol>,
11781178
pub volatile: bool,
11791179
pub alignstack: bool,
11801180
pub dialect: AsmDialect,

src/librustc/hir/print.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1500,19 +1500,19 @@ impl<'a> State<'a> {
15001500
hir::ExprInlineAsm(ref a, ref outputs, ref inputs) => {
15011501
word(&mut self.s, "asm!")?;
15021502
self.popen()?;
1503-
self.print_string(&a.asm, a.asm_str_style)?;
1503+
self.print_string(&a.asm.as_str(), a.asm_str_style)?;
15041504
self.word_space(":")?;
15051505

15061506
let mut out_idx = 0;
15071507
self.commasep(Inconsistent, &a.outputs, |s, out| {
1508-
let mut ch = out.constraint.chars();
1508+
let constraint = out.constraint.as_str();
1509+
let mut ch = constraint.chars();
15091510
match ch.next() {
15101511
Some('=') if out.is_rw => {
15111512
s.print_string(&format!("+{}", ch.as_str()),
15121513
ast::StrStyle::Cooked)?
15131514
}
1514-
_ => s.print_string(&out.constraint,
1515-
ast::StrStyle::Cooked)?,
1515+
_ => s.print_string(&constraint, ast::StrStyle::Cooked)?,
15161516
}
15171517
s.popen()?;
15181518
s.print_expr(&outputs[out_idx])?;
@@ -1525,7 +1525,7 @@ impl<'a> State<'a> {
15251525

15261526
let mut in_idx = 0;
15271527
self.commasep(Inconsistent, &a.inputs, |s, co| {
1528-
s.print_string(&co, ast::StrStyle::Cooked)?;
1528+
s.print_string(&co.as_str(), ast::StrStyle::Cooked)?;
15291529
s.popen()?;
15301530
s.print_expr(&inputs[in_idx])?;
15311531
s.pclose()?;
@@ -1536,7 +1536,7 @@ impl<'a> State<'a> {
15361536
self.word_space(":")?;
15371537

15381538
self.commasep(Inconsistent, &a.clobbers, |s, co| {
1539-
s.print_string(&co, ast::StrStyle::Cooked)?;
1539+
s.print_string(&co.as_str(), ast::StrStyle::Cooked)?;
15401540
Ok(())
15411541
})?;
15421542

src/librustc/middle/cstore.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use syntax::ast;
3939
use syntax::attr;
4040
use syntax::ext::base::SyntaxExtension;
4141
use syntax::ptr::P;
42-
use syntax::symbol::InternedString;
42+
use syntax::symbol::Symbol;
4343
use syntax_pos::Span;
4444
use rustc_back::target::Target;
4545
use hir;
@@ -52,7 +52,7 @@ pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
5252

5353
#[derive(Clone, Debug)]
5454
pub struct LinkMeta {
55-
pub crate_name: String,
55+
pub crate_name: Symbol,
5656
pub crate_hash: Svh,
5757
}
5858

@@ -92,7 +92,7 @@ pub enum NativeLibraryKind {
9292
#[derive(Clone, Hash, RustcEncodable, RustcDecodable)]
9393
pub struct NativeLibrary {
9494
pub kind: NativeLibraryKind,
95-
pub name: String,
95+
pub name: Symbol,
9696
pub cfg: Option<ast::MetaItem>,
9797
}
9898

@@ -205,11 +205,11 @@ pub trait CrateStore<'tcx> {
205205
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>;
206206
/// The name of the crate as it is referred to in source code of the current
207207
/// crate.
208-
fn crate_name(&self, cnum: CrateNum) -> InternedString;
208+
fn crate_name(&self, cnum: CrateNum) -> Symbol;
209209
/// The name of the crate as it is stored in the crate's metadata.
210-
fn original_crate_name(&self, cnum: CrateNum) -> InternedString;
210+
fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
211211
fn crate_hash(&self, cnum: CrateNum) -> Svh;
212-
fn crate_disambiguator(&self, cnum: CrateNum) -> InternedString;
212+
fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
213213
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
214214
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
215215
fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId>;
@@ -375,13 +375,13 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
375375
bug!("panic_strategy")
376376
}
377377
fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate> { bug!("extern_crate") }
378-
fn crate_name(&self, cnum: CrateNum) -> InternedString { bug!("crate_name") }
379-
fn original_crate_name(&self, cnum: CrateNum) -> InternedString {
378+
fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
379+
fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
380380
bug!("original_crate_name")
381381
}
382382
fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
383383
fn crate_disambiguator(&self, cnum: CrateNum)
384-
-> InternedString { bug!("crate_disambiguator") }
384+
-> Symbol { bug!("crate_disambiguator") }
385385
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
386386
{ bug!("plugin_registrar_fn") }
387387
fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>

src/librustc/middle/lang_items.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::weak_lang_items;
3030
use util::nodemap::FxHashMap;
3131

3232
use syntax::ast;
33-
use syntax::symbol::InternedString;
33+
use syntax::symbol::Symbol;
3434
use hir::itemlikevisit::ItemLikeVisitor;
3535
use hir;
3636

@@ -152,15 +152,15 @@ struct LanguageItemCollector<'a, 'tcx: 'a> {
152152
impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> {
153153
fn visit_item(&mut self, item: &hir::Item) {
154154
if let Some(value) = extract(&item.attrs) {
155-
let item_index = self.item_refs.get(&value[..]).cloned();
155+
let item_index = self.item_refs.get(&*value.as_str()).cloned();
156156

157157
if let Some(item_index) = item_index {
158158
self.collect_item(item_index, self.ast_map.local_def_id(item.id))
159159
} else {
160160
let span = self.ast_map.span(item.id);
161161
span_err!(self.session, span, E0522,
162162
"definition of an unknown language item: `{}`.",
163-
&value[..]);
163+
value);
164164
}
165165
}
166166
}
@@ -243,12 +243,10 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
243243
}
244244
}
245245

246-
pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
246+
pub fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
247247
for attribute in attrs {
248248
match attribute.value_str() {
249-
Some(ref value) if attribute.check_name("lang") => {
250-
return Some(value.clone());
251-
}
249+
Some(value) if attribute.check_name("lang") => return Some(value),
252250
_ => {}
253251
}
254252
}

src/librustc/middle/recursion_limit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
2525
}
2626

2727
if let Some(s) = attr.value_str() {
28-
if let Some(n) = s.parse().ok() {
28+
if let Some(n) = s.as_str().parse().ok() {
2929
sess.recursion_limit.set(n);
3030
return;
3131
}

src/librustc/middle/stability.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use hir::def::Def;
2121
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, DefIndex, LOCAL_CRATE};
2222
use ty::{self, TyCtxt, AdtKind};
2323
use middle::privacy::AccessLevels;
24-
use syntax::symbol::InternedString;
24+
use syntax::symbol::Symbol;
2525
use syntax_pos::{Span, DUMMY_SP};
2626
use syntax::ast;
2727
use syntax::ast::{NodeId, Attribute};
@@ -36,7 +36,6 @@ use hir::pat_util::EnumerateAndAdjustIterator;
3636

3737
use std::mem::replace;
3838
use std::cmp::Ordering;
39-
use std::ops::Deref;
4039

4140
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Copy, Debug, Eq, Hash)]
4241
pub enum StabilityLevel {
@@ -151,10 +150,11 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
151150

152151
// Check if deprecated_since < stable_since. If it is,
153152
// this is *almost surely* an accident.
154-
if let (&Some(attr::RustcDeprecation {since: ref dep_since, ..}),
155-
&attr::Stable {since: ref stab_since}) = (&stab.rustc_depr, &stab.level) {
153+
if let (&Some(attr::RustcDeprecation {since: dep_since, ..}),
154+
&attr::Stable {since: stab_since}) = (&stab.rustc_depr, &stab.level) {
156155
// Explicit version of iter::order::lt to handle parse errors properly
157-
for (dep_v, stab_v) in dep_since.split(".").zip(stab_since.split(".")) {
156+
for (dep_v, stab_v) in
157+
dep_since.as_str().split(".").zip(stab_since.as_str().split(".")) {
158158
if let (Ok(dep_v), Ok(stab_v)) = (dep_v.parse::<u64>(), stab_v.parse()) {
159159
match dep_v.cmp(&stab_v) {
160160
Ordering::Less => {
@@ -356,7 +356,7 @@ impl<'a, 'tcx> Index<'tcx> {
356356
/// features and possibly prints errors. Returns a list of all
357357
/// features used.
358358
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
359-
-> FxHashMap<InternedString, attr::StabilityLevel> {
359+
-> FxHashMap<Symbol, attr::StabilityLevel> {
360360
let _task = tcx.dep_graph.in_task(DepNode::StabilityCheck);
361361
let ref active_lib_features = tcx.sess.features.borrow().declared_lib_features;
362362

@@ -376,8 +376,8 @@ pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
376376

377377
struct Checker<'a, 'tcx: 'a> {
378378
tcx: TyCtxt<'a, 'tcx, 'tcx>,
379-
active_features: FxHashSet<InternedString>,
380-
used_features: FxHashMap<InternedString, attr::StabilityLevel>,
379+
active_features: FxHashSet<Symbol>,
380+
used_features: FxHashMap<Symbol, attr::StabilityLevel>,
381381
// Within a block where feature gate checking can be skipped.
382382
in_skip_block: u32,
383383
}
@@ -407,10 +407,10 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
407407
if !self.active_features.contains(feature) {
408408
let msg = match *reason {
409409
Some(ref r) => format!("use of unstable library feature '{}': {}",
410-
&feature, &r),
410+
&feature.as_str(), &r),
411411
None => format!("use of unstable library feature '{}'", &feature)
412412
};
413-
emit_feature_err(&self.tcx.sess.parse_sess, &feature, span,
413+
emit_feature_err(&self.tcx.sess.parse_sess, &feature.as_str(), span,
414414
GateIssue::Library(Some(issue)), &msg);
415415
}
416416
}
@@ -735,18 +735,18 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
735735
/// were expected to be library features), and the list of features used from
736736
/// libraries, identify activated features that don't exist and error about them.
737737
pub fn check_unused_or_stable_features(sess: &Session,
738-
lib_features_used: &FxHashMap<InternedString,
738+
lib_features_used: &FxHashMap<Symbol,
739739
attr::StabilityLevel>) {
740740
let ref declared_lib_features = sess.features.borrow().declared_lib_features;
741-
let mut remaining_lib_features: FxHashMap<InternedString, Span>
741+
let mut remaining_lib_features: FxHashMap<Symbol, Span>
742742
= declared_lib_features.clone().into_iter().collect();
743743

744744
fn format_stable_since_msg(version: &str) -> String {
745745
format!("this feature has been stable since {}. Attribute no longer needed", version)
746746
}
747747

748748
for &(ref stable_lang_feature, span) in &sess.features.borrow().declared_stable_lang_features {
749-
let version = find_lang_feature_accepted_version(stable_lang_feature.deref())
749+
let version = find_lang_feature_accepted_version(&stable_lang_feature.as_str())
750750
.expect("unexpectedly couldn't find version feature was stabilized");
751751
sess.add_lint(lint::builtin::STABLE_FEATURES,
752752
ast::CRATE_NODE_ID,
@@ -761,7 +761,7 @@ pub fn check_unused_or_stable_features(sess: &Session,
761761
sess.add_lint(lint::builtin::STABLE_FEATURES,
762762
ast::CRATE_NODE_ID,
763763
span,
764-
format_stable_since_msg(version.deref()));
764+
format_stable_since_msg(&version.as_str()));
765765
}
766766
}
767767
None => ( /* used but undeclared, handled during the previous ast visit */ )

src/librustc/middle/weak_lang_items.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use middle::lang_items;
1616

1717
use rustc_back::PanicStrategy;
1818
use syntax::ast;
19-
use syntax::symbol::InternedString;
19+
use syntax::symbol::Symbol;
2020
use syntax_pos::Span;
2121
use hir::intravisit::Visitor;
2222
use hir::intravisit;
@@ -55,10 +55,10 @@ pub fn check_crate(krate: &hir::Crate,
5555
verify(sess, items);
5656
}
5757

58-
pub fn link_name(attrs: &[ast::Attribute]) -> Option<InternedString> {
58+
pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> {
5959
lang_items::extract(attrs).and_then(|name| {
60-
$(if &name[..] == stringify!($name) {
61-
Some(InternedString::new(stringify!($sym)))
60+
$(if name == stringify!($name) {
61+
Some(Symbol::intern(stringify!($sym)))
6262
} else)* {
6363
None
6464
}
@@ -126,7 +126,7 @@ impl<'a> Context<'a> {
126126
impl<'a, 'v> Visitor<'v> for Context<'a> {
127127
fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
128128
if let Some(lang_item) = lang_items::extract(&i.attrs) {
129-
self.register(&lang_item, i.span);
129+
self.register(&lang_item.as_str(), i.span);
130130
}
131131
intravisit::walk_foreign_item(self, i)
132132
}

0 commit comments

Comments
 (0)