Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use syntax::ast;
use syntax::symbol::InternedString;
use syntax_pos::Span;
use ty::{self, Ty};

Expand Down Expand Up @@ -53,7 +53,7 @@ pub enum TypeVariableOrigin {
MiscVariable(Span),
NormalizeProjectionType(Span),
TypeInference(Span),
TypeParameterDefinition(Span, ast::Name),
TypeParameterDefinition(Span, InternedString),

/// one of the upvars or closure kind parameters in a `ClosureSubsts`
/// (before it has been determined)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

for param in generics.types.iter() {
let name = param.name.as_str().to_string();
let name = param.name.to_string();
let ty = trait_ref.substs.type_for_def(param);
let ty_str = ty.to_string();
flags.push((name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
let trait_str = tcx.item_path_str(trait_ref.def_id);
let generics = tcx.generics_of(trait_ref.def_id);
let generic_map = generics.types.iter().map(|param| {
(param.name.as_str().to_string(),
(param.name.to_string(),
trait_ref.substs.type_for_def(param).to_string())
}).collect::<FxHashMap<String, String>>();

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ use std::iter;
use std::sync::mpsc;
use std::sync::Arc;
use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::ast::{self, NodeId};
use syntax::attr;
use syntax::codemap::MultiSpan;
use syntax::feature_gate;
use syntax::symbol::{Symbol, keywords};
use syntax::symbol::{Symbol, keywords, InternedString};
use syntax_pos::Span;

use hir;
Expand Down Expand Up @@ -2221,12 +2221,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn mk_param(self,
index: u32,
name: Name) -> Ty<'tcx> {
name: InternedString) -> Ty<'tcx> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change seems fine to me (as discussed on IRC); name should only be used for debug print-outs etc

self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
}

pub fn mk_self_type(self) -> Ty<'tcx> {
self.mk_param(0, keywords::SelfType.name())
self.mk_param(0, keywords::SelfType.name().as_str())
}

pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ pub struct FloatVarValue(pub ast::FloatTy);

#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct TypeParameterDef {
pub name: Name,
pub name: InternedString,
pub def_id: DefId,
pub index: u32,
pub has_default: bool,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::iter;
use std::cmp::Ordering;
use syntax::abi;
use syntax::ast::{self, Name};
use syntax::symbol::keywords;
use syntax::symbol::{keywords, InternedString};

use serialize;

Expand Down Expand Up @@ -861,16 +861,16 @@ impl<'tcx> PolyFnSig<'tcx> {
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct ParamTy {
pub idx: u32,
pub name: Name,
pub name: InternedString,
}

impl<'a, 'gcx, 'tcx> ParamTy {
pub fn new(index: u32, name: Name) -> ParamTy {
pub fn new(index: u32, name: InternedString) -> ParamTy {
ParamTy { idx: index, name: name }
}

pub fn for_self() -> ParamTy {
ParamTy::new(0, keywords::SelfType.name())
ParamTy::new(0, keywords::SelfType.name().as_str())
}

pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
Expand All @@ -882,7 +882,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
}

pub fn is_self(&self) -> bool {
if self.name == keywords::SelfType.name() {
if self.name == keywords::SelfType.name().as_str() {
assert_eq!(self.idx, 0);
true
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
}
TyParam(p) => {
self.hash(p.idx);
self.hash(p.name.as_str());
self.hash(p.name);
}
TyProjection(ref data) => {
self.def_id(data.item_def_id);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use std::ptr;

use syntax_pos::{self, Span, Pos};
use syntax::ast;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, InternedString};
use rustc::ty::layout::{self, LayoutOf};

pub mod gdb;
Expand Down Expand Up @@ -393,7 +393,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
substs.types().zip(names).map(|(ty, name)| {
let actual_type = cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(name.as_str().as_bytes()).unwrap();
let name = CString::new(name.as_bytes()).unwrap();
unsafe {
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
DIB(cx),
Expand All @@ -412,7 +412,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
return create_DIArray(DIB(cx), &template_params[..]);
}

fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<ast::Name> {
fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<InternedString> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_type_parameter_names(cx, cx.tcx.generics_of(def_id))
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let item_def_id = tcx.hir.local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
tcx.mk_param(index, tcx.hir.name(node_id))
tcx.mk_param(index, tcx.hir.name(node_id).as_str())
}
Def::SelfTy(_, Some(def_id)) => {
// Self in impl (we know the concrete type).
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// and in libcore/intrinsics.rs
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
it: &hir::ForeignItem) {
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)));
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)).as_str());
let name = it.name.as_str();
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
let split : Vec<&str> = name.split('_').collect();
Expand Down Expand Up @@ -341,7 +341,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
it: &hir::ForeignItem) {
let param = |n| {
let name = Symbol::intern(&format!("P{}", n));
let name = Symbol::intern(&format!("P{}", n)).as_str();
tcx.mk_param(n, name)
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
// local so it should be okay to just unwrap everything.
let trait_def_id = impl_params[&method_param.name];
let trait_decl_span = tcx.def_span(trait_def_id);
error_194(tcx, type_span, trait_decl_span, method_param.name);
error_194(tcx, type_span, trait_decl_span, &method_param.name[..]);
}
}
}
Expand Down Expand Up @@ -739,7 +739,7 @@ fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast:
err
}

fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: &str) {
struct_span_err!(tcx.sess, span, E0194,
"type parameter `{}` shadows another type parameter of the same name",
name)
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id);
let index = generics.type_param_to_index[&def_id];
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id).as_str());

// Don't look for bounds where the type parameter isn't in scope.
let parent = if item_def_id == param_owner_def_id {
Expand Down Expand Up @@ -838,7 +838,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

opt_self = Some(ty::TypeParameterDef {
index: 0,
name: keywords::SelfType.name(),
name: keywords::SelfType.name().as_str(),
def_id: tcx.hir.local_def_id(param_id),
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand Down Expand Up @@ -914,7 +914,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

ty::TypeParameterDef {
index: type_start + i as u32,
name: p.name,
name: p.name.as_str(),
def_id: tcx.hir.local_def_id(p.id),
has_default: p.default.is_some(),
object_lifetime_default:
Expand All @@ -933,7 +933,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// add a dummy parameter for the closure kind
types.push(ty::TypeParameterDef {
index: type_start,
name: Symbol::intern("<closure_kind>"),
name: Symbol::intern("<closure_kind>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand All @@ -944,7 +944,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// add a dummy parameter for the closure signature
types.push(ty::TypeParameterDef {
index: type_start + 1,
name: Symbol::intern("<closure_signature>"),
name: Symbol::intern("<closure_signature>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand All @@ -955,7 +955,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.with_freevars(node_id, |fv| {
types.extend(fv.iter().zip(2..).map(|(_, i)| ty::TypeParameterDef {
index: type_start + i,
name: Symbol::intern("<upvar>"),
name: Symbol::intern("<upvar>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand Down Expand Up @@ -1435,7 +1435,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Collect the predicates that were written inline by the user on each
// type parameter (e.g., `<T:Foo>`).
for param in ast_generics.ty_params() {
let param_ty = ty::ParamTy::new(index, param.name).to_ty(tcx);
let param_ty = ty::ParamTy::new(index, param.name.as_str()).to_ty(tcx);
index += 1;

let bounds = compute_bounds(&icx,
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#![feature(optin_builtin_traits)]
#![allow(unused_attributes)]
#![feature(specialization)]
#![feature(macro_lifetime_matcher)]

use std::borrow::Cow;
use std::cell::Cell;
Expand Down
65 changes: 40 additions & 25 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use GLOBALS;
use serialize::{Decodable, Decoder, Encodable, Encoder};
use std::collections::HashMap;
use std::fmt;
use std::ops::Deref;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just efficiency, I guess?)


#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Ident {
Expand Down Expand Up @@ -154,9 +155,10 @@ impl Decodable for Symbol {
}
}

impl<T: ::std::ops::Deref<Target=str>> PartialEq<T> for Symbol {
fn eq(&self, other: &T) -> bool {
self.as_str() == other.deref()
impl PartialEq<InternedString> for Symbol {
fn eq(&self, other: &InternedString) -> bool {
// Compare pointers
self.as_str() == *other
}
}

Expand Down Expand Up @@ -360,36 +362,49 @@ impl<U: ?Sized> ::std::convert::AsRef<U> for InternedString where str: ::std::co
}
}

impl<T: ::std::ops::Deref<Target = str>> ::std::cmp::PartialEq<T> for InternedString {
fn eq(&self, other: &T) -> bool {
self.string == other.deref()
}
}

impl ::std::cmp::PartialEq<InternedString> for str {
impl ::std::cmp::PartialEq<InternedString> for InternedString {
fn eq(&self, other: &InternedString) -> bool {
self == other.string
self.as_ptr() == other.as_ptr()
}
}

impl<'a> ::std::cmp::PartialEq<InternedString> for &'a str {
fn eq(&self, other: &InternedString) -> bool {
*self == other.string
}
}
macro_rules! impl_partial_eq_for_symbol_and_interned_string {
($(impl $(<$impl_lt:lifetime>)* for $t:ty;)*) => ($(
impl<$($impl_lt),*> ::std::cmp::PartialEq<$t> for InternedString {
fn eq(&self, other: &$t) -> bool {
let s: &str = other.deref();
self.string == s
}
}

impl ::std::cmp::PartialEq<InternedString> for String {
fn eq(&self, other: &InternedString) -> bool {
self == other.string
}
}
impl<$($impl_lt),*> ::std::cmp::PartialEq<InternedString> for $t {
fn eq(&self, other: &InternedString) -> bool {
let s: &str = self.deref();
s == other.string
}
}

impl<'a> ::std::cmp::PartialEq<InternedString> for &'a String {
fn eq(&self, other: &InternedString) -> bool {
*self == other.string
}
impl<$($impl_lt),*> ::std::cmp::PartialEq<$t> for Symbol {
fn eq(&self, other: &$t) -> bool {
self.as_str() == *other
}
}

impl<$($impl_lt),*> ::std::cmp::PartialEq<Symbol> for $t {
fn eq(&self, other: &Symbol) -> bool {
*self == other.as_str()
}
}
)*)
}

impl_partial_eq_for_symbol_and_interned_string!(
impl for str;
impl for String;
impl<'a> for &'a str;
impl<'a> for &'a String;
);

impl !Send for InternedString { }

impl ::std::ops::Deref for InternedString {
Expand Down