Skip to content

Commit 36c8f6b

Browse files
committed
Cleanup InternedString.
1 parent e85a0d7 commit 36c8f6b

File tree

26 files changed

+63
-128
lines changed

26 files changed

+63
-128
lines changed

src/librustc/hir/map/definitions.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl DefPathData {
343343

344344
pub fn as_interned_str(&self) -> InternedString {
345345
use self::DefPathData::*;
346-
match *self {
346+
let s = match *self {
347347
TypeNs(ref name) |
348348
ValueNs(ref name) |
349349
Module(ref name) |
@@ -353,43 +353,24 @@ impl DefPathData {
353353
EnumVariant(ref name) |
354354
Binding(ref name) |
355355
Field(ref name) => {
356-
name.clone()
357-
}
358-
359-
Impl => {
360-
InternedString::new("{{impl}}")
356+
return name.clone();
361357
}
362358

363359
// note that this does not show up in user printouts
364-
CrateRoot => {
365-
InternedString::new("{{root}}")
366-
}
360+
CrateRoot => "{{root}}",
367361

368362
// note that this does not show up in user printouts
369-
InlinedRoot(_) => {
370-
InternedString::new("{{inlined-root}}")
371-
}
372-
373-
Misc => {
374-
InternedString::new("{{?}}")
375-
}
376-
377-
ClosureExpr => {
378-
InternedString::new("{{closure}}")
379-
}
380-
381-
StructCtor => {
382-
InternedString::new("{{constructor}}")
383-
}
384-
385-
Initializer => {
386-
InternedString::new("{{initializer}}")
387-
}
363+
InlinedRoot(_) => "{{inlined-root}}",
364+
365+
Impl => "{{impl}}",
366+
Misc => "{{?}}",
367+
ClosureExpr => "{{closure}}",
368+
StructCtor => "{{constructor}}",
369+
Initializer => "{{initializer}}",
370+
ImplTrait => "{{impl-Trait}}",
371+
};
388372

389-
ImplTrait => {
390-
InternedString::new("{{impl-Trait}}")
391-
}
392-
}
373+
Symbol::intern(s).as_str()
393374
}
394375

395376
pub fn to_string(&self) -> String {

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
765765
None => return false,
766766
Some((node_id, name)) => (node_id, name),
767767
};
768-
if &part[..] != mod_name.as_str() {
768+
if mod_name != &**part {
769769
return false;
770770
}
771771
cursor = self.map.get_parent(mod_id);
@@ -803,8 +803,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
803803
// We are looking at some node `n` with a given name and parent
804804
// id; do their names match what I am seeking?
805805
fn matches_names(&self, parent_of_n: NodeId, name: Name) -> bool {
806-
name.as_str() == &self.item_name[..] &&
807-
self.suffix_matches(parent_of_n)
806+
name == &**self.item_name && self.suffix_matches(parent_of_n)
808807
}
809808
}
810809

src/librustc/middle/dead.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
498498
span: syntax_pos::Span,
499499
name: ast::Name,
500500
node_type: &str) {
501-
let name = name.as_str();
502-
if !name.starts_with("_") {
501+
if !name.as_str().starts_with("_") {
503502
self.tcx
504503
.sess
505504
.add_lint(lint::builtin::DEAD_CODE,

src/librustc/middle/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
9292
EntryPointType::Start
9393
} else if attr::contains_name(&item.attrs, "main") {
9494
EntryPointType::MainAttr
95-
} else if item.name.as_str() == "main" {
95+
} else if item.name == "main" {
9696
if at_root {
9797
// This is a top-level function so can be 'main'
9898
EntryPointType::MainNamed

src/librustc/middle/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
5555
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
5656
_ => return false
5757
};
58-
intrinsic && self.infcx.tcx.item_name(def_id).as_str() == "transmute"
58+
intrinsic && self.infcx.tcx.item_name(def_id) == "transmute"
5959
}
6060

6161
fn check_transmute(&self, span: Span, from: Ty<'gcx>, to: Ty<'gcx>, id: ast::NodeId) {

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
455455
// When compiling with --test we don't enforce stability on the
456456
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
457457
// name `__test`
458-
if item.span == DUMMY_SP && item.name.as_str() == "__test" { return }
458+
if item.span == DUMMY_SP && item.name == "__test" { return }
459459

460460
check_item(self.tcx, item, true,
461461
&mut |id, sp, stab, depr| self.check(id, sp, stab, depr));

src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
169169
{
170170
let name = tcx.item_name(def_id);
171171
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
172-
if name.as_str() == "rustc_peek" {
172+
if name == "rustc_peek" {
173173
return Some((args, source_info.span));
174174
}
175175
}

src/librustc_lint/bad_style.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,12 @@ impl NonCamelCaseTypes {
8181
.concat()
8282
}
8383

84-
let s = name.as_str();
85-
8684
if !is_camel_case(name) {
87-
let c = to_camel_case(&s);
85+
let c = to_camel_case(&name.as_str());
8886
let m = if c.is_empty() {
89-
format!("{} `{}` should have a camel case name such as `CamelCase`",
90-
sort,
91-
s)
87+
format!("{} `{}` should have a camel case name such as `CamelCase`", sort, name)
9288
} else {
93-
format!("{} `{}` should have a camel case name such as `{}`",
94-
sort,
95-
s,
96-
c)
89+
format!("{} `{}` should have a camel case name such as `{}`", sort, name, c)
9790
};
9891
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]);
9992
}
@@ -326,21 +319,19 @@ pub struct NonUpperCaseGlobals;
326319

327320
impl NonUpperCaseGlobals {
328321
fn check_upper_case(cx: &LateContext, sort: &str, name: ast::Name, span: Span) {
329-
let s = name.as_str();
330-
331-
if s.chars().any(|c| c.is_lowercase()) {
332-
let uc = NonSnakeCase::to_snake_case(&s).to_uppercase();
333-
if uc != &s[..] {
322+
if name.as_str().chars().any(|c| c.is_lowercase()) {
323+
let uc = NonSnakeCase::to_snake_case(&name.as_str()).to_uppercase();
324+
if name != &*uc {
334325
cx.span_lint(NON_UPPER_CASE_GLOBALS,
335326
span,
336327
&format!("{} `{}` should have an upper case name such as `{}`",
337328
sort,
338-
s,
329+
name,
339330
uc));
340331
} else {
341332
cx.span_lint(NON_UPPER_CASE_GLOBALS,
342333
span,
343-
&format!("{} `{}` should have an upper case name", sort, s));
334+
&format!("{} `{}` should have an upper case name", sort, name));
344335
}
345336
}
346337
}

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ impl LateLintPass for MutableTransmutes {
12291229
ty::TyFnDef(.., ref bfty) if bfty.abi == RustIntrinsic => (),
12301230
_ => return false,
12311231
}
1232-
cx.tcx.item_name(def_id).as_str() == "transmute"
1232+
cx.tcx.item_name(def_id) == "transmute"
12331233
}
12341234
}
12351235
}

src/librustc_passes/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a> AstValidator<'a> {
4040
if label.name == keywords::StaticLifetime.name() {
4141
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
4242
}
43-
if label.name.as_str() == "'_" {
43+
if label.name == "'_" {
4444
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
4545
id,
4646
span,
@@ -90,7 +90,7 @@ impl<'a> AstValidator<'a> {
9090

9191
impl<'a> Visitor for AstValidator<'a> {
9292
fn visit_lifetime(&mut self, lt: &Lifetime) {
93-
if lt.name.as_str() == "'_" {
93+
if lt.name == "'_" {
9494
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
9595
lt.id,
9696
lt.span,

0 commit comments

Comments
 (0)