1
Fork 0

Cleanup InternedString.

This commit is contained in:
Jeffrey Seyfried 2016-11-17 14:04:20 +00:00
parent e85a0d70b8
commit 36c8f6b0d3
26 changed files with 62 additions and 127 deletions

View file

@ -343,7 +343,7 @@ impl DefPathData {
pub fn as_interned_str(&self) -> InternedString { pub fn as_interned_str(&self) -> InternedString {
use self::DefPathData::*; use self::DefPathData::*;
match *self { let s = match *self {
TypeNs(ref name) | TypeNs(ref name) |
ValueNs(ref name) | ValueNs(ref name) |
Module(ref name) | Module(ref name) |
@ -353,43 +353,24 @@ impl DefPathData {
EnumVariant(ref name) | EnumVariant(ref name) |
Binding(ref name) | Binding(ref name) |
Field(ref name) => { Field(ref name) => {
name.clone() return name.clone();
}
Impl => {
InternedString::new("{{impl}}")
} }
// note that this does not show up in user printouts // note that this does not show up in user printouts
CrateRoot => { CrateRoot => "{{root}}",
InternedString::new("{{root}}")
}
// note that this does not show up in user printouts // note that this does not show up in user printouts
InlinedRoot(_) => { InlinedRoot(_) => "{{inlined-root}}",
InternedString::new("{{inlined-root}}")
}
Misc => { Impl => "{{impl}}",
InternedString::new("{{?}}") Misc => "{{?}}",
} ClosureExpr => "{{closure}}",
StructCtor => "{{constructor}}",
Initializer => "{{initializer}}",
ImplTrait => "{{impl-Trait}}",
};
ClosureExpr => { Symbol::intern(s).as_str()
InternedString::new("{{closure}}")
}
StructCtor => {
InternedString::new("{{constructor}}")
}
Initializer => {
InternedString::new("{{initializer}}")
}
ImplTrait => {
InternedString::new("{{impl-Trait}}")
}
}
} }
pub fn to_string(&self) -> String { pub fn to_string(&self) -> String {

View file

@ -765,7 +765,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
None => return false, None => return false,
Some((node_id, name)) => (node_id, name), Some((node_id, name)) => (node_id, name),
}; };
if &part[..] != mod_name.as_str() { if mod_name != &**part {
return false; return false;
} }
cursor = self.map.get_parent(mod_id); cursor = self.map.get_parent(mod_id);
@ -803,8 +803,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
// We are looking at some node `n` with a given name and parent // We are looking at some node `n` with a given name and parent
// id; do their names match what I am seeking? // id; do their names match what I am seeking?
fn matches_names(&self, parent_of_n: NodeId, name: Name) -> bool { fn matches_names(&self, parent_of_n: NodeId, name: Name) -> bool {
name.as_str() == &self.item_name[..] && name == &**self.item_name && self.suffix_matches(parent_of_n)
self.suffix_matches(parent_of_n)
} }
} }

View file

@ -498,8 +498,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
span: syntax_pos::Span, span: syntax_pos::Span,
name: ast::Name, name: ast::Name,
node_type: &str) { node_type: &str) {
let name = name.as_str(); if !name.as_str().starts_with("_") {
if !name.starts_with("_") {
self.tcx self.tcx
.sess .sess
.add_lint(lint::builtin::DEAD_CODE, .add_lint(lint::builtin::DEAD_CODE,

View file

@ -92,7 +92,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
EntryPointType::Start EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") { } else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr EntryPointType::MainAttr
} else if item.name.as_str() == "main" { } else if item.name == "main" {
if at_root { if at_root {
// This is a top-level function so can be 'main' // This is a top-level function so can be 'main'
EntryPointType::MainNamed EntryPointType::MainNamed

View file

@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic, ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
_ => return false _ => return false
}; };
intrinsic && self.infcx.tcx.item_name(def_id).as_str() == "transmute" intrinsic && self.infcx.tcx.item_name(def_id) == "transmute"
} }
fn check_transmute(&self, span: Span, from: Ty<'gcx>, to: Ty<'gcx>, id: ast::NodeId) { fn check_transmute(&self, span: Span, from: Ty<'gcx>, to: Ty<'gcx>, id: ast::NodeId) {

View file

@ -455,7 +455,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
// When compiling with --test we don't enforce stability on the // When compiling with --test we don't enforce stability on the
// compiler-generated test module, demarcated with `DUMMY_SP` plus the // compiler-generated test module, demarcated with `DUMMY_SP` plus the
// name `__test` // name `__test`
if item.span == DUMMY_SP && item.name.as_str() == "__test" { return } if item.span == DUMMY_SP && item.name == "__test" { return }
check_item(self.tcx, item, true, check_item(self.tcx, item, true,
&mut |id, sp, stab, depr| self.check(id, sp, stab, depr)); &mut |id, sp, stab, depr| self.check(id, sp, stab, depr));

View file

@ -169,7 +169,7 @@ fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
{ {
let name = tcx.item_name(def_id); let name = tcx.item_name(def_id);
if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic { if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
if name.as_str() == "rustc_peek" { if name == "rustc_peek" {
return Some((args, source_info.span)); return Some((args, source_info.span));
} }
} }

View file

@ -81,19 +81,12 @@ impl NonCamelCaseTypes {
.concat() .concat()
} }
let s = name.as_str();
if !is_camel_case(name) { if !is_camel_case(name) {
let c = to_camel_case(&s); let c = to_camel_case(&name.as_str());
let m = if c.is_empty() { let m = if c.is_empty() {
format!("{} `{}` should have a camel case name such as `CamelCase`", format!("{} `{}` should have a camel case name such as `CamelCase`", sort, name)
sort,
s)
} else { } else {
format!("{} `{}` should have a camel case name such as `{}`", format!("{} `{}` should have a camel case name such as `{}`", sort, name, c)
sort,
s,
c)
}; };
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]); cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]);
} }
@ -326,21 +319,19 @@ pub struct NonUpperCaseGlobals;
impl NonUpperCaseGlobals { impl NonUpperCaseGlobals {
fn check_upper_case(cx: &LateContext, sort: &str, name: ast::Name, span: Span) { fn check_upper_case(cx: &LateContext, sort: &str, name: ast::Name, span: Span) {
let s = name.as_str(); if name.as_str().chars().any(|c| c.is_lowercase()) {
let uc = NonSnakeCase::to_snake_case(&name.as_str()).to_uppercase();
if s.chars().any(|c| c.is_lowercase()) { if name != &*uc {
let uc = NonSnakeCase::to_snake_case(&s).to_uppercase();
if uc != &s[..] {
cx.span_lint(NON_UPPER_CASE_GLOBALS, cx.span_lint(NON_UPPER_CASE_GLOBALS,
span, span,
&format!("{} `{}` should have an upper case name such as `{}`", &format!("{} `{}` should have an upper case name such as `{}`",
sort, sort,
s, name,
uc)); uc));
} else { } else {
cx.span_lint(NON_UPPER_CASE_GLOBALS, cx.span_lint(NON_UPPER_CASE_GLOBALS,
span, span,
&format!("{} `{}` should have an upper case name", sort, s)); &format!("{} `{}` should have an upper case name", sort, name));
} }
} }
} }

View file

@ -1229,7 +1229,7 @@ impl LateLintPass for MutableTransmutes {
ty::TyFnDef(.., ref bfty) if bfty.abi == RustIntrinsic => (), ty::TyFnDef(.., ref bfty) if bfty.abi == RustIntrinsic => (),
_ => return false, _ => return false,
} }
cx.tcx.item_name(def_id).as_str() == "transmute" cx.tcx.item_name(def_id) == "transmute"
} }
} }
} }

View file

@ -40,7 +40,7 @@ impl<'a> AstValidator<'a> {
if label.name == keywords::StaticLifetime.name() { if label.name == keywords::StaticLifetime.name() {
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name)); self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
} }
if label.name.as_str() == "'_" { if label.name == "'_" {
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
id, id,
span, span,
@ -90,7 +90,7 @@ impl<'a> AstValidator<'a> {
impl<'a> Visitor for AstValidator<'a> { impl<'a> Visitor for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &Lifetime) { fn visit_lifetime(&mut self, lt: &Lifetime) {
if lt.name.as_str() == "'_" { if lt.name == "'_" {
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
lt.id, lt.id,
lt.span, lt.span,

View file

@ -101,7 +101,7 @@ impl<'a> Registry<'a> {
/// ///
/// This is the most general hook into `libsyntax`'s expansion behavior. /// This is the most general hook into `libsyntax`'s expansion behavior.
pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) { pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
if name.as_str() == "macro_rules" { if name == "macro_rules" {
panic!("user-defined macros may not be named `macro_rules`"); panic!("user-defined macros may not be named `macro_rules`");
} }
self.syntax_exts.push((name, match extension { self.syntax_exts.push((name, match extension {

View file

@ -138,7 +138,7 @@ impl<'b> Resolver<'b> {
match view_path.node { match view_path.node {
ViewPathSimple(binding, ref full_path) => { ViewPathSimple(binding, ref full_path) => {
let mut source = full_path.segments.last().unwrap().identifier; let mut source = full_path.segments.last().unwrap().identifier;
let source_name = source.name.as_str(); let source_name = source.name;
if source_name == "mod" || source_name == "self" { if source_name == "mod" || source_name == "self" {
resolve_error(self, resolve_error(self,
view_path.span, view_path.span,

View file

@ -1462,7 +1462,6 @@ impl<'a> Resolver<'a> {
let name = module_path[index].name; let name = module_path[index].name;
match self.resolve_name_in_module(search_module, name, TypeNS, false, false, span) { match self.resolve_name_in_module(search_module, name, TypeNS, false, false, span) {
Failed(_) => { Failed(_) => {
let segment_name = name.as_str();
let module_name = module_to_string(search_module); let module_name = module_to_string(search_module);
let msg = if "???" == &module_name { let msg = if "???" == &module_name {
let current_module = self.current_module; let current_module = self.current_module;
@ -1480,10 +1479,10 @@ impl<'a> Resolver<'a> {
format!("Did you mean `{}{}`?", prefix, path_str) format!("Did you mean `{}{}`?", prefix, path_str)
} }
None => format!("Maybe a missing `extern crate {};`?", segment_name), None => format!("Maybe a missing `extern crate {};`?", name),
} }
} else { } else {
format!("Could not find `{}` in `{}`", segment_name, module_name) format!("Could not find `{}` in `{}`", name, module_name)
}; };
return Failed(span.map(|span| (span, msg))); return Failed(span.map(|span| (span, msg)));
@ -1651,7 +1650,7 @@ impl<'a> Resolver<'a> {
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) * /// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
fn resolve_module_prefix(&mut self, module_path: &[Ident], span: Option<Span>) fn resolve_module_prefix(&mut self, module_path: &[Ident], span: Option<Span>)
-> ResolveResult<ModulePrefixResult<'a>> { -> ResolveResult<ModulePrefixResult<'a>> {
if &*module_path[0].name.as_str() == "$crate" { if module_path[0].name == "$crate" {
return Success(PrefixFound(self.resolve_crate_var(module_path[0].ctxt), 1)); return Success(PrefixFound(self.resolve_crate_var(module_path[0].ctxt), 1));
} }
@ -1667,7 +1666,7 @@ impl<'a> Resolver<'a> {
self.module_map[&self.current_module.normal_ancestor_id.unwrap()]; self.module_map[&self.current_module.normal_ancestor_id.unwrap()];
// Now loop through all the `super`s we find. // Now loop through all the `super`s we find.
while i < module_path.len() && "super" == module_path[i].name.as_str() { while i < module_path.len() && module_path[i].name == "super" {
debug!("(resolving module prefix) resolving `super` at {}", debug!("(resolving module prefix) resolving `super` at {}",
module_to_string(&containing_module)); module_to_string(&containing_module));
if let Some(parent) = containing_module.parent { if let Some(parent) = containing_module.parent {
@ -2635,7 +2634,7 @@ impl<'a> Resolver<'a> {
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace); let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
match (qualified_binding, unqualified_def) { match (qualified_binding, unqualified_def) {
(Ok(binding), Some(ref ud)) if binding.def() == ud.def && (Ok(binding), Some(ref ud)) if binding.def() == ud.def &&
segments[0].identifier.name.as_str() != "$crate" => { segments[0].identifier.name != "$crate" => {
self.session self.session
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS, .add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
id, id,
@ -2881,7 +2880,7 @@ impl<'a> Resolver<'a> {
} }
fn find_best_match(&mut self, name: &str) -> SuggestionType { fn find_best_match(&mut self, name: &str) -> SuggestionType {
if let Some(macro_name) = self.macro_names.iter().find(|n| n.as_str() == name) { if let Some(macro_name) = self.macro_names.iter().find(|&n| n == &name) {
return SuggestionType::Macro(format!("{}!", macro_name)); return SuggestionType::Macro(format!("{}!", macro_name));
} }
@ -3000,8 +2999,7 @@ impl<'a> Resolver<'a> {
false // Stop advancing false // Stop advancing
}); });
if method_scope && if method_scope && keywords::SelfValue.name() == &*path_name {
&path_name[..] == keywords::SelfValue.name().as_str() {
resolve_error(self, resolve_error(self,
expr.span, expr.span,
ResolutionError::SelfNotAvailableInStaticMethod); ResolutionError::SelfNotAvailableInStaticMethod);

View file

@ -115,7 +115,7 @@ impl<'a> base::Resolver for Resolver<'a> {
impl<'a, 'b> Folder for EliminateCrateVar<'a, 'b> { impl<'a, 'b> Folder for EliminateCrateVar<'a, 'b> {
fn fold_path(&mut self, mut path: ast::Path) -> ast::Path { fn fold_path(&mut self, mut path: ast::Path) -> ast::Path {
let ident = path.segments[0].identifier; let ident = path.segments[0].identifier;
if &ident.name.as_str() == "$crate" { if ident.name == "$crate" {
path.global = true; path.global = true;
let module = self.0.resolve_crate_var(ident.ctxt); let module = self.0.resolve_crate_var(ident.ctxt);
if module.is_local() { if module.is_local() {
@ -151,7 +151,7 @@ impl<'a> base::Resolver for Resolver<'a> {
} }
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef, export: bool) { fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef, export: bool) {
if &def.ident.name.as_str() == "macro_rules" { if def.ident.name == "macro_rules" {
self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`"); self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`");
} }

View file

@ -663,7 +663,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
-> bool { -> bool {
(bare_fn_ty.abi == Abi::RustIntrinsic || (bare_fn_ty.abi == Abi::RustIntrinsic ||
bare_fn_ty.abi == Abi::PlatformIntrinsic) && bare_fn_ty.abi == Abi::PlatformIntrinsic) &&
tcx.item_name(def_id).as_str() == "drop_in_place" tcx.item_name(def_id) == "drop_in_place"
} }
} }
} }

View file

@ -107,7 +107,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let sig = tcx.erase_late_bound_regions_and_normalize(&fty.sig); let sig = tcx.erase_late_bound_regions_and_normalize(&fty.sig);
let arg_tys = sig.inputs; let arg_tys = sig.inputs;
let ret_ty = sig.output; let ret_ty = sig.output;
let name = tcx.item_name(def_id).as_str(); let name = &*tcx.item_name(def_id).as_str();
let span = match call_debug_location { let span = match call_debug_location {
DebugLoc::ScopeAt(_, span) => span, DebugLoc::ScopeAt(_, span) => span,
@ -123,15 +123,15 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
Call(bcx, llfn, &[], call_debug_location); Call(bcx, llfn, &[], call_debug_location);
Unreachable(bcx); Unreachable(bcx);
return Result::new(bcx, C_undef(Type::nil(ccx).ptr_to())); return Result::new(bcx, C_undef(Type::nil(ccx).ptr_to()));
} else if &name[..] == "unreachable" { } else if name == "unreachable" {
Unreachable(bcx); Unreachable(bcx);
return Result::new(bcx, C_nil(ccx)); return Result::new(bcx, C_nil(ccx));
} }
let llret_ty = type_of::type_of(ccx, ret_ty); let llret_ty = type_of::type_of(ccx, ret_ty);
let simple = get_simple_intrinsic(ccx, &name); let simple = get_simple_intrinsic(ccx, name);
let llval = match (simple, &name[..]) { let llval = match (simple, name) {
(Some(llfn), _) => { (Some(llfn), _) => {
Call(bcx, llfn, &llargs, call_debug_location) Call(bcx, llfn, &llargs, call_debug_location)
} }
@ -340,7 +340,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let sty = &arg_tys[0].sty; let sty = &arg_tys[0].sty;
match int_type_width_signed(sty, ccx) { match int_type_width_signed(sty, ccx) {
Some((width, signed)) => Some((width, signed)) =>
match &*name { match name {
"ctlz" => count_zeros_intrinsic(bcx, &format!("llvm.ctlz.i{}", width), "ctlz" => count_zeros_intrinsic(bcx, &format!("llvm.ctlz.i{}", width),
llargs[0], call_debug_location), llargs[0], call_debug_location),
"cttz" => count_zeros_intrinsic(bcx, &format!("llvm.cttz.i{}", width), "cttz" => count_zeros_intrinsic(bcx, &format!("llvm.cttz.i{}", width),
@ -394,7 +394,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let sty = &arg_tys[0].sty; let sty = &arg_tys[0].sty;
match float_type_width(sty) { match float_type_width(sty) {
Some(_width) => Some(_width) =>
match &*name { match name {
"fadd_fast" => FAddFast(bcx, llargs[0], llargs[1], call_debug_location), "fadd_fast" => FAddFast(bcx, llargs[0], llargs[1], call_debug_location),
"fsub_fast" => FSubFast(bcx, llargs[0], llargs[1], call_debug_location), "fsub_fast" => FSubFast(bcx, llargs[0], llargs[1], call_debug_location),
"fmul_fast" => FMulFast(bcx, llargs[0], llargs[1], call_debug_location), "fmul_fast" => FMulFast(bcx, llargs[0], llargs[1], call_debug_location),

View file

@ -320,7 +320,7 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
let codegen_unit_name = match characteristic_def_id { let codegen_unit_name = match characteristic_def_id {
Some(def_id) => compute_codegen_unit_name(tcx, def_id, is_volatile), Some(def_id) => compute_codegen_unit_name(tcx, def_id, is_volatile),
None => InternedString::new(FALLBACK_CODEGEN_UNIT), None => Symbol::intern(FALLBACK_CODEGEN_UNIT).as_str(),
}; };
let make_codegen_unit = || { let make_codegen_unit = || {
@ -365,7 +365,7 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
// always ensure we have at least one CGU; otherwise, if we have a // always ensure we have at least one CGU; otherwise, if we have a
// crate with just types (for example), we could wind up with no CGU // crate with just types (for example), we could wind up with no CGU
if codegen_units.is_empty() { if codegen_units.is_empty() {
let codegen_unit_name = InternedString::new(FALLBACK_CODEGEN_UNIT); let codegen_unit_name = Symbol::intern(FALLBACK_CODEGEN_UNIT).as_str();
codegen_units.entry(codegen_unit_name.clone()) codegen_units.entry(codegen_unit_name.clone())
.or_insert_with(|| CodegenUnit::empty(codegen_unit_name.clone())); .or_insert_with(|| CodegenUnit::empty(codegen_unit_name.clone()));
} }

View file

@ -1252,7 +1252,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
if bounds.len() > 1 { if bounds.len() > 1 {
let spans = bounds.iter().map(|b| { let spans = bounds.iter().map(|b| {
self.tcx().associated_items(b.def_id()).find(|item| { self.tcx().associated_items(b.def_id()).find(|item| {
item.kind == ty::AssociatedKind::Type && item.name.as_str() == assoc_name item.kind == ty::AssociatedKind::Type && item.name == assoc_name
}) })
.and_then(|item| self.tcx().map.as_local_node_id(item.def_id)) .and_then(|item| self.tcx().map.as_local_node_id(item.def_id))
.and_then(|node_id| self.tcx().map.opt_span(node_id)) .and_then(|node_id| self.tcx().map.opt_span(node_id))

View file

@ -342,7 +342,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let def = pick.item.def(); let def = pick.item.def();
if let probe::InherentImplPick = pick.kind { if let probe::InherentImplPick = pick.kind {
if !pick.item.vis.is_accessible_from(self.body_id, &self.tcx.map) { if !pick.item.vis.is_accessible_from(self.body_id, &self.tcx.map) {
let msg = format!("{} `{}` is private", def.kind_name(), &method_name.as_str()); let msg = format!("{} `{}` is private", def.kind_name(), method_name);
self.tcx.sess.span_err(span, &msg); self.tcx.sess.span_err(span, &msg);
} }
} }

View file

@ -943,7 +943,7 @@ fn check_on_unimplemented<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
Position::ArgumentNamed(s) if s == "Self" => (), Position::ArgumentNamed(s) if s == "Self" => (),
// So is `{A}` if A is a type parameter // So is `{A}` if A is a type parameter
Position::ArgumentNamed(s) => match types.iter().find(|t| { Position::ArgumentNamed(s) => match types.iter().find(|t| {
t.name.as_str() == s t.name == s
}) { }) {
Some(_) => (), Some(_) => (),
None => { None => {
@ -3127,7 +3127,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty::TyAdt(adt, ..) if adt.is_enum() => { ty::TyAdt(adt, ..) if adt.is_enum() => {
struct_span_err!(self.tcx.sess, field.name.span, E0559, struct_span_err!(self.tcx.sess, field.name.span, E0559,
"{} `{}::{}` has no field named `{}`", "{} `{}::{}` has no field named `{}`",
kind_name, actual, variant.name.as_str(), field.name.node) kind_name, actual, variant.name, field.name.node)
} }
_ => { _ => {
struct_span_err!(self.tcx.sess, field.name.span, E0560, struct_span_err!(self.tcx.sess, field.name.span, E0560,
@ -3147,7 +3147,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
match ty.sty { match ty.sty {
ty::TyAdt(adt, ..) if adt.is_enum() => { ty::TyAdt(adt, ..) if adt.is_enum() => {
err.span_label(field.name.span, &format!("`{}::{}` does not have this field", err.span_label(field.name.span, &format!("`{}::{}` does not have this field",
ty, variant.name.as_str())); ty, variant.name));
} }
_ => { _ => {
err.span_label(field.name.span, &format!("`{}` does not have this field", ty)); err.span_label(field.name.span, &format!("`{}` does not have this field", ty));

View file

@ -373,7 +373,7 @@ impl Generics {
} }
pub fn span_for_name(&self, name: &str) -> Option<Span> { pub fn span_for_name(&self, name: &str) -> Option<Span> {
for t in &self.ty_params { for t in &self.ty_params {
if t.ident.name.as_str() == name { if t.ident.name == name {
return Some(t.span); return Some(t.span);
} }
} }

View file

@ -28,7 +28,7 @@ pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
EntryPointType::Start EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") { } else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr EntryPointType::MainAttr
} else if item.ident.name.as_str() == "main" { } else if item.ident.name == "main" {
if depth == 1 { if depth == 1 {
// This is a top-level function so can be 'main' // This is a top-level function so can be 'main'
EntryPointType::MainNamed EntryPointType::MainNamed

View file

@ -643,7 +643,7 @@ impl<'a> ExtCtxt<'a> {
loop { loop {
if self.codemap().with_expn_info(expn_id, |info| { if self.codemap().with_expn_info(expn_id, |info| {
info.map_or(None, |i| { info.map_or(None, |i| {
if i.callee.name().as_str() == "include" { if i.callee.name() == "include" {
// Stop going up the backtrace once include! is encountered // Stop going up the backtrace once include! is encountered
return None; return None;
} }

View file

@ -791,8 +791,7 @@ fn is_in_follow(tok: &Token, frag: &str) -> Result<bool, (String, &'static str)>
"pat" => { "pat" => {
match *tok { match *tok {
FatArrow | Comma | Eq | BinOp(token::Or) => Ok(true), FatArrow | Comma | Eq | BinOp(token::Or) => Ok(true),
Ident(i) if (i.name.as_str() == "if" || Ident(i) if i.name == "if" || i.name == "in" => Ok(true),
i.name.as_str() == "in") => Ok(true),
_ => Ok(false) _ => Ok(false)
} }
}, },
@ -800,8 +799,8 @@ fn is_in_follow(tok: &Token, frag: &str) -> Result<bool, (String, &'static str)>
match *tok { match *tok {
OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) | OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) |
Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true), Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true),
MatchNt(_, ref frag) if frag.name.as_str() == "block" => Ok(true), MatchNt(_, ref frag) if frag.name == "block" => Ok(true),
Ident(i) if i.name.as_str() == "as" || i.name.as_str() == "where" => Ok(true), Ident(i) if i.name == "as" || i.name == "where" => Ok(true),
_ => Ok(false) _ => Ok(false)
} }
}, },

View file

@ -2535,7 +2535,7 @@ impl<'a> Parser<'a> {
let prev_span = self.prev_span; let prev_span = self.prev_span;
let fstr = n.as_str(); let fstr = n.as_str();
let mut err = self.diagnostic().struct_span_err(prev_span, let mut err = self.diagnostic().struct_span_err(prev_span,
&format!("unexpected token: `{}`", n.as_str())); &format!("unexpected token: `{}`", n));
if fstr.chars().all(|x| "0123456789.".contains(x)) { if fstr.chars().all(|x| "0123456789.".contains(x)) {
let float = match fstr.parse::<f64>().ok() { let float = match fstr.parse::<f64>().ok() {
Some(f) => f, Some(f) => f,

View file

@ -244,14 +244,6 @@ pub struct InternedString {
string: Rc<str>, string: Rc<str>,
} }
impl InternedString {
pub fn new(string: &'static str) -> InternedString {
InternedString {
string: Rc::__from_str(string),
}
}
}
impl ::std::ops::Deref for InternedString { impl ::std::ops::Deref for InternedString {
type Target = str; type Target = str;
fn deref(&self) -> &str { &self.string } fn deref(&self) -> &str { &self.string }
@ -269,30 +261,6 @@ impl fmt::Display for InternedString {
} }
} }
impl<'a> PartialEq<&'a str> for InternedString {
fn eq(&self, other: & &'a str) -> bool {
PartialEq::eq(&self.string[..], *other)
}
}
impl<'a> PartialEq<InternedString> for &'a str {
fn eq(&self, other: &InternedString) -> bool {
PartialEq::eq(*self, &other.string[..])
}
}
impl PartialEq<str> for InternedString {
fn eq(&self, other: &str) -> bool {
PartialEq::eq(&self.string[..], other)
}
}
impl PartialEq<InternedString> for str {
fn eq(&self, other: &InternedString) -> bool {
PartialEq::eq(self, &other.string[..])
}
}
impl Decodable for InternedString { impl Decodable for InternedString {
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> { fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
Ok(Symbol::intern(&d.read_str()?).as_str()) Ok(Symbol::intern(&d.read_str()?).as_str())