Skip to content

Commit

Permalink
remove get_ident and get_name, make as_str sound
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jul 28, 2015
1 parent 9ca511c commit 00a5e66
Show file tree
Hide file tree
Showing 68 changed files with 433 additions and 534 deletions.
5 changes: 2 additions & 3 deletions src/doc/trpl/compiler-plugins.md
Expand Up @@ -61,7 +61,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
("I", 1)];
let text = match args {
[TtToken(_, token::Ident(s, _))] => token::get_ident(s).to_string(),
[TtToken(_, token::Ident(s, _))] => s.to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
Expand Down Expand Up @@ -186,8 +186,7 @@ impl LintPass for Pass {
}
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
let name = token::get_ident(it.ident);
if name.get() == "lintme" {
if it.ident.name == "lintme" {
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/librustc/ast_map/mod.rs
Expand Up @@ -47,8 +47,7 @@ impl PathElem {

impl fmt::Display for PathElem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let slot = token::get_name(self.name());
write!(f, "{}", slot)
write!(f, "{}", self.name())
}
}

Expand Down Expand Up @@ -1073,18 +1072,18 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
match ii.node {
ConstImplItem(..) => {
format!("assoc const {} in {}{}",
token::get_ident(ii.ident),
ii.ident,
map.path_to_string(id),
id_str)
}
MethodImplItem(..) => {
format!("method {} in {}{}",
token::get_ident(ii.ident),
ii.ident,
map.path_to_string(id), id_str)
}
TypeImplItem(_) => {
format!("assoc type {} in {}{}",
token::get_ident(ii.ident),
ii.ident,
map.path_to_string(id),
id_str)
}
Expand All @@ -1103,13 +1102,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {

format!("{} {} in {}{}",
kind,
token::get_ident(ti.ident),
ti.ident,
map.path_to_string(id),
id_str)
}
Some(NodeVariant(ref variant)) => {
format!("variant {} in {}{}",
token::get_ident(variant.node.name),
variant.node.name,
map.path_to_string(id), id_str)
}
Some(NodeExpr(ref expr)) => {
Expand Down
12 changes: 5 additions & 7 deletions src/librustc/metadata/creader.rs
Expand Up @@ -33,7 +33,6 @@ use syntax::attr::AttrMetaMethods;
use syntax::codemap::{self, Span, mk_sp, Pos};
use syntax::parse;
use syntax::parse::token::InternedString;
use syntax::parse::token;
use syntax::visit;
use log;

Expand Down Expand Up @@ -181,19 +180,18 @@ impl<'a> CrateReader<'a> {
fn extract_crate_info(&self, i: &ast::Item) -> Option<CrateInfo> {
match i.node {
ast::ItemExternCrate(ref path_opt) => {
let ident = token::get_ident(i.ident);
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
ident, path_opt);
i.ident, path_opt);
let name = match *path_opt {
Some(name) => {
validate_crate_name(Some(self.sess), name.as_str(),
validate_crate_name(Some(self.sess), &name.as_str(),
Some(i.span));
name.as_str().to_string()
name.to_string()
}
None => ident.to_string(),
None => i.ident.to_string(),
};
Some(CrateInfo {
ident: ident.to_string(),
ident: i.ident.to_string(),
name: name,
id: i.id,
should_link: should_link(i),
Expand Down
36 changes: 16 additions & 20 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -40,7 +40,6 @@ use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::diagnostic::SpanHandler;
use syntax::parse::token::special_idents;
use syntax::parse::token;
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::visit::Visitor;
Expand Down Expand Up @@ -83,11 +82,11 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
}

fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
rbml_w.wr_tagged_str(tag_paths_data_name, &token::get_name(name));
rbml_w.wr_tagged_str(tag_paths_data_name, &name.as_str());
}

fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Name) {
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_name(name));
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &name.as_str());
}

fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
Expand Down Expand Up @@ -349,7 +348,7 @@ fn encode_path<PI: Iterator<Item=PathElem>>(rbml_w: &mut Encoder, path: PI) {
ast_map::PathMod(_) => tag_path_elem_mod,
ast_map::PathName(_) => tag_path_elem_name
};
rbml_w.wr_tagged_str(tag, &token::get_name(pe.name()));
rbml_w.wr_tagged_str(tag, &pe.name().as_str());
}
rbml_w.end_tag();
}
Expand All @@ -359,13 +358,13 @@ fn encode_reexported_static_method(rbml_w: &mut Encoder,
method_def_id: DefId,
method_name: ast::Name) {
debug!("(encode reexported static method) {}::{}",
exp.name, token::get_name(method_name));
exp.name, method_name);
rbml_w.start_tag(tag_items_data_item_reexport);
rbml_w.wr_tagged_u64(tag_items_data_item_reexport_def_id,
def_to_u64(method_def_id));
rbml_w.wr_tagged_str(tag_items_data_item_reexport_name,
&format!("{}::{}", exp.name,
token::get_name(method_name)));
method_name));
rbml_w.end_tag();
}

Expand Down Expand Up @@ -499,15 +498,12 @@ fn encode_reexports(ecx: &EncodeContext,
rbml_w.wr_tagged_u64(tag_items_data_item_reexport_def_id,
def_to_u64(exp.def_id));
rbml_w.wr_tagged_str(tag_items_data_item_reexport_name,
exp.name.as_str());
&exp.name.as_str());
rbml_w.end_tag();
encode_reexported_static_methods(ecx, rbml_w, path.clone(), exp);
}
}
None => {
debug!("(encoding info for module) found no reexports for {}",
id);
}
},
None => debug!("(encoding info for module) found no reexports for {}", id),
}
}

Expand Down Expand Up @@ -539,7 +535,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
if let ast::ItemImpl(..) = item.node {
let (ident, did) = (item.ident, item.id);
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
token::get_ident(ident),
ident,
did, ecx.tcx.map.node_to_string(did));

rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(local_def(did)));
Expand Down Expand Up @@ -656,7 +652,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
});
rbml_w.start_tag(tag_items_data_item);
debug!("encode_info_for_struct: doing {} {}",
token::get_name(nm), id);
nm, id);
encode_struct_field_family(rbml_w, field.vis);
encode_name(rbml_w, nm);
encode_bounds_and_type_for_item(rbml_w, ecx, id);
Expand Down Expand Up @@ -816,7 +812,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
impl_item_opt: Option<&ast::ImplItem>) {
debug!("encode_info_for_associated_const({:?},{:?})",
associated_const.def_id,
token::get_name(associated_const.name));
associated_const.name);

rbml_w.start_tag(tag_items_data_item);

Expand Down Expand Up @@ -854,7 +850,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
impl_item_opt: Option<&ast::ImplItem>) {

debug!("encode_info_for_method: {:?} {:?}", m.def_id,
token::get_name(m.name));
m.name);
rbml_w.start_tag(tag_items_data_item);

encode_method_ty_fields(ecx, rbml_w, m);
Expand Down Expand Up @@ -899,7 +895,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
impl_item_opt: Option<&ast::ImplItem>) {
debug!("encode_info_for_associated_type({:?},{:?})",
associated_type.def_id,
token::get_name(associated_type.name));
associated_type.name);

rbml_w.start_tag(tag_items_data_item);

Expand Down Expand Up @@ -937,7 +933,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
for arg in &decl.inputs {
let tag = tag_method_argument_name;
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
let name = token::get_name(path1.node.name);
let name = path1.node.name.as_str();
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
} else {
rbml_w.wr_tagged_bytes(tag, &[]);
Expand Down Expand Up @@ -1562,7 +1558,7 @@ fn my_visit_foreign_item(ni: &ast::ForeignItem,
index: &mut Vec<entry<i64>>) {
debug!("writing foreign item {}::{}",
ecx.tcx.map.path_to_string(ni.id),
token::get_ident(ni.ident));
ni.ident);

let abi = ecx.tcx.map.get_foreign_abi(ni.id);
ecx.tcx.map.with_path(ni.id, |path| {
Expand Down Expand Up @@ -1748,7 +1744,7 @@ fn encode_defaulted(rbml_w: &mut Encoder, is_defaulted: bool) {
fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
rbml_w.start_tag(tag_associated_type_names);
for &name in names {
rbml_w.wr_tagged_str(tag_associated_type_name, &token::get_name(name));
rbml_w.wr_tagged_str(tag_associated_type_name, &name.as_str());
}
rbml_w.end_tag();
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/metadata/macro_import.rs
Expand Up @@ -149,8 +149,7 @@ impl<'a> MacroLoader<'a> {
let mut seen = HashSet::new();

for mut def in macros {
let name = token::get_ident(def.ident);
seen.insert(name.clone());
let name = def.ident.name.as_str();

def.use_locally = match import.as_ref() {
None => true,
Expand All @@ -161,18 +160,19 @@ impl<'a> MacroLoader<'a> {
"allow_internal_unstable");
debug!("load_macros: loaded: {:?}", def);
self.macros.push(def);
seen.insert(name);
}

if let Some(sel) = import.as_ref() {
for (name, span) in sel {
if !seen.contains(name) {
if !seen.contains(&name) {
self.sess.span_err(*span, "imported macro not found");
}
}
}

for (name, span) in &reexport {
if !seen.contains(name) {
if !seen.contains(&name) {
self.sess.span_err(*span, "reexported macro not found");
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/librustc/metadata/tyencode.rs
Expand Up @@ -26,7 +26,6 @@ use util::nodemap::FnvHashMap;
use syntax::abi::Abi;
use syntax::ast;
use syntax::diagnostic::SpanHandler;
use syntax::parse::token;

use rbml::writer::Encoder;

Expand Down Expand Up @@ -136,7 +135,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
cx.diag.handler().bug("cannot encode inference variable types");
}
ty::TyParam(ParamTy {space, idx, name}) => {
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), token::get_name(name))
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), name)
}
ty::TyStruct(def, substs) => {
mywrite!(w, "a[{}|", (cx.ds)(def));
Expand All @@ -155,7 +154,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
ty::TyProjection(ref data) => {
mywrite!(w, "P[");
enc_trait_ref(w, cx, data.trait_ref);
mywrite!(w, "{}]", token::get_name(data.item_name));
mywrite!(w, "{}]", data.item_name);
}
ty::TyError => {
mywrite!(w, "e");
Expand Down Expand Up @@ -251,7 +250,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
data.param_id,
data.space.to_uint(),
data.index,
token::get_name(data.name));
data.name);
}
ty::ReFree(ref fr) => {
mywrite!(w, "f[");
Expand Down Expand Up @@ -302,7 +301,7 @@ fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
ty::BrNamed(d, name) => {
mywrite!(w, "[{}|{}]",
(cx.ds)(d),
token::get_name(name));
name);
}
ty::BrFresh(id) => {
mywrite!(w, "f{}|", id);
Expand Down Expand Up @@ -410,7 +409,7 @@ pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,
pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
v: &ty::TypeParameterDef<'tcx>) {
mywrite!(w, "{}:{}|{}|{}|{}|",
token::get_name(v.name), (cx.ds)(v.def_id),
v.name, (cx.ds)(v.def_id),
v.space.to_uint(), v.index, (cx.ds)(v.default_def_id));
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
Expand Down Expand Up @@ -465,6 +464,6 @@ fn enc_projection_predicate<'a, 'tcx>(w: &mut Encoder,
cx: &ctxt<'a, 'tcx>,
data: &ty::ProjectionPredicate<'tcx>) {
enc_trait_ref(w, cx, data.projection_ty.trait_ref);
mywrite!(w, "{}|", token::get_name(data.projection_ty.item_name));
mywrite!(w, "{}|", data.projection_ty.item_name);
enc_ty(w, cx, data.ty);
}
5 changes: 2 additions & 3 deletions src/librustc/middle/astencode.rs
Expand Up @@ -34,7 +34,6 @@ use middle::ty::{self, Ty};
use syntax::{ast, ast_util, codemap, fold};
use syntax::codemap::Span;
use syntax::fold::Folder;
use syntax::parse::token;
use syntax::ptr::P;
use syntax;

Expand Down Expand Up @@ -156,10 +155,10 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
ast::IITraitItem(_, ref ti) => ti.ident,
ast::IIImplItem(_, ref ii) => ii.ident
};
debug!("Fn named: {}", token::get_ident(ident));
debug!("Fn named: {}", ident);
debug!("< Decoded inlined fn: {}::{}",
path_as_str.unwrap(),
token::get_ident(ident));
ident);
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
decode_side_tables(dcx, ast_doc);
match *ii {
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/check_match.rs
Expand Up @@ -35,7 +35,6 @@ use syntax::ast_util;
use syntax::codemap::{Span, Spanned, DUMMY_SP};
use syntax::fold::{Folder, noop_fold_pat};
use syntax::print::pprust::pat_to_string;
use syntax::parse::token;
use syntax::ptr::P;
use syntax::visit::{self, Visitor, FnKind};
use util::nodemap::FnvHashMap;
Expand Down Expand Up @@ -239,17 +238,17 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
if let Some(DefLocal(_)) = def {
if cx.tcx.enum_variants(def_id).iter().any(|variant|
token::get_name(variant.name) == token::get_name(ident.node.name)
variant.name == ident.node.name
&& variant.args.is_empty()
) {
span_warn!(cx.tcx.sess, p.span, E0170,
"pattern binding `{}` is named the same as one \
of the variants of the type `{}`",
&token::get_ident(ident.node), pat_ty);
ident.node, pat_ty);
fileline_help!(cx.tcx.sess, p.span,
"if you meant to match on a variant, \
consider making the path in the pattern qualified: `{}::{}`",
pat_ty, &token::get_ident(ident.node));
pat_ty, ident.node);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -1036,8 +1036,9 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
if let Struct(struct_id) = c {
if let ast::ExprStruct(_, ref fields, _) = tcx.map.expect_expr(struct_id).node {
// Check that the given field exists and evaluate it
if let Some(f) = fields.iter().find(|f| f.ident.node.as_str()
== field_name.node.as_str()) {
// if the idents are compared run-pass/issue-19244 fails
if let Some(f) = fields.iter().find(|f| f.ident.node.name
== field_name.node.name) {
return eval_const_expr_partial(tcx, &*f.expr, base_hint)
} else {
signal!(e, MissingStructField);
Expand Down

0 comments on commit 00a5e66

Please sign in to comment.