Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In librustc*, convert many uses of ast::Ident to ast::Name, fixing much ... #23655

Merged
merged 1 commit into from
Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
.iter()
.map(|field_ty| {
arg_names.push(ast::Ident::new(field_ty.name));
arg_names.push(field_ty.name);
get_type(cdata, field_ty.id.node, tcx).ty
})
.collect();
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
rbml_w.wr_tagged_str(tag_paths_data_name, &token::get_name(name));
}

fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) {
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_ident(name));
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));
}

pub fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
Expand Down Expand Up @@ -519,12 +519,12 @@ fn encode_info_for_mod(ecx: &EncodeContext,
attrs: &[ast::Attribute],
id: NodeId,
path: PathElems,
name: ast::Ident,
name: ast::Name,
vis: ast::Visibility) {
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, local_def(id));
encode_family(rbml_w, 'm');
encode_name(rbml_w, name.name);
encode_name(rbml_w, name);
debug!("(encoding info for module) encoding info for module ID {}", id);

// Encode info about all the module children.
Expand Down Expand Up @@ -666,7 +666,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,

fn encode_info_for_struct_ctor(ecx: &EncodeContext,
rbml_w: &mut Encoder,
name: ast::Ident,
name: ast::Name,
ctor_id: NodeId,
index: &mut Vec<entry<i64>>,
struct_id: NodeId) {
Expand All @@ -679,7 +679,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
encode_def_id(rbml_w, local_def(ctor_id));
encode_family(rbml_w, 'o');
encode_bounds_and_type_for_item(rbml_w, ecx, ctor_id);
encode_name(rbml_w, name.name);
encode_name(rbml_w, name);
ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path));
encode_parent_item(rbml_w, local_def(struct_id));

Expand Down Expand Up @@ -886,7 +886,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_ident(path1.node);
let name = token::get_name(path1.node.name);
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
} else {
rbml_w.wr_tagged_bytes(tag, &[]);
Expand Down Expand Up @@ -1044,7 +1044,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
&item.attrs,
item.id,
path,
item.ident,
item.ident.name,
item.vis);
}
ast::ItemForeignMod(ref fm) => {
Expand Down Expand Up @@ -1152,7 +1152,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// If this is a tuple-like struct, encode the type of the constructor.
match struct_def.ctor_id {
Some(ctor_id) => {
encode_info_for_struct_ctor(ecx, rbml_w, item.ident,
encode_info_for_struct_ctor(ecx, rbml_w, item.ident.name,
ctor_id, index, def_id.node);
}
None => {}
Expand Down Expand Up @@ -1187,8 +1187,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_polarity(rbml_w, polarity);
match ty.node {
ast::TyPath(None, ref path) if path.segments.len() == 1 => {
let ident = path.segments.last().unwrap().identifier;
encode_impl_type_basename(rbml_w, ident);
let name = path.segments.last().unwrap().identifier.name;
encode_impl_type_basename(rbml_w, name);
}
_ => {}
}
Expand Down Expand Up @@ -1513,7 +1513,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
&[],
ast::CRATE_NODE_ID,
[].iter().cloned().chain(LinkedPath::empty()),
syntax::parse::token::special_idents::invalid,
syntax::parse::token::special_idents::invalid.name,
ast::Public);

visit::walk_crate(&mut EncodeVisitor {
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ fn scan<R, F, G>(st: &mut PState, mut is_last: F, op: G) -> R where
return op(&st.data[start_pos..end_pos]);
}

pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
ast::Ident::new(parse_name(st, last))
}

pub fn parse_name(st: &mut PState, last: char) -> ast::Name {
fn is_last(b: char, c: char) -> bool { return c == b; }
parse_name_(st, |a| is_last(last, a) )
Expand Down
25 changes: 15 additions & 10 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}

fn handle_field_access(&mut self, lhs: &ast::Expr, name: &ast::Ident) {
fn handle_field_access(&mut self, lhs: &ast::Expr, name: ast::Name) {
match ty::expr_ty_adjusted(self.tcx, lhs).sty {
ty::ty_struct(id, _) => {
let fields = ty::lookup_struct_fields(self.tcx, id);
let field_id = fields.iter()
.find(|field| field.name == name.name).unwrap().id;
.find(|field| field.name == name).unwrap().id;
self.live_symbols.insert(field_id.node);
},
_ => ()
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
self.lookup_and_handle_method(expr.id, expr.span);
}
ast::ExprField(ref lhs, ref ident) => {
self.handle_field_access(&**lhs, &ident.node);
self.handle_field_access(&**lhs, ident.node.name);
}
ast::ExprTupField(ref lhs, idx) => {
self.handle_tup_field_access(&**lhs, idx.node);
Expand Down Expand Up @@ -511,9 +511,9 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
fn warn_dead_code(&mut self,
id: ast::NodeId,
span: codemap::Span,
ident: ast::Ident,
name: ast::Name,
node_type: &str) {
let name = ident.as_str();
let name = name.as_str();
if !name.starts_with("_") {
self.tcx
.sess
Expand All @@ -528,14 +528,19 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) {
if self.should_warn_about_item(item) {
self.warn_dead_code(item.id, item.span, item.ident, item.node.descriptive_variant());
self.warn_dead_code(
item.id,
item.span,
item.ident.name,
item.node.descriptive_variant()
);
} else {
match item.node {
ast::ItemEnum(ref enum_def, _) => {
for variant in &enum_def.variants {
if self.should_warn_about_variant(&variant.node) {
self.warn_dead_code(variant.node.id, variant.span,
variant.node.name, "variant");
variant.node.name.name, "variant");
}
}
},
Expand All @@ -547,7 +552,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {

fn visit_foreign_item(&mut self, fi: &ast::ForeignItem) {
if !self.symbol_is_live(fi.id, None) {
self.warn_dead_code(fi.id, fi.span, fi.ident, fi.node.descriptive_variant());
self.warn_dead_code(fi.id, fi.span, fi.ident.name, fi.node.descriptive_variant());
}
visit::walk_foreign_item(self, fi);
}
Expand All @@ -559,7 +564,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
match fk {
visit::FkMethod(name, _) => {
if !self.symbol_is_live(id, None) {
self.warn_dead_code(id, span, name, "method");
self.warn_dead_code(id, span, name.name, "method");
}
}
_ => ()
Expand All @@ -570,7 +575,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
fn visit_struct_field(&mut self, field: &ast::StructField) {
if self.should_warn_about_field(&field.node) {
self.warn_dead_code(field.node.id, field.span,
field.node.ident().unwrap(), "struct field");
field.node.ident().unwrap().name, "struct field");
}

visit::walk_struct_field(self, field);
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ struct CaptureInfo {
#[derive(Copy, Clone, Debug)]
struct LocalInfo {
id: NodeId,
ident: ast::Ident
name: ast::Name
}

#[derive(Copy, Clone, Debug)]
enum VarKind {
Arg(NodeId, ast::Ident),
Arg(NodeId, ast::Name),
Local(LocalInfo),
ImplicitRet,
CleanExit
Expand Down Expand Up @@ -334,8 +334,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {

fn variable_name(&self, var: Variable) -> String {
match self.var_kinds[var.get()] {
Local(LocalInfo { ident: nm, .. }) | Arg(_, nm) => {
token::get_ident(nm).to_string()
Local(LocalInfo { name, .. }) | Arg(_, name) => {
token::get_name(name).to_string()
},
ImplicitRet => "<implicit-ret>".to_string(),
CleanExit => "<clean-exit>".to_string()
Expand Down Expand Up @@ -385,8 +385,8 @@ fn visit_fn(ir: &mut IrMaps,
&*arg.pat,
|_bm, arg_id, _x, path1| {
debug!("adding argument {}", arg_id);
let ident = path1.node;
fn_maps.add_variable(Arg(arg_id, ident));
let name = path1.node.name;
fn_maps.add_variable(Arg(arg_id, name));
})
};

Expand Down Expand Up @@ -418,11 +418,11 @@ fn visit_fn(ir: &mut IrMaps,
fn visit_local(ir: &mut IrMaps, local: &ast::Local) {
pat_util::pat_bindings(&ir.tcx.def_map, &*local.pat, |_, p_id, sp, path1| {
debug!("adding local variable {}", p_id);
let name = path1.node;
let name = path1.node.name;
ir.add_live_node_for_node(p_id, VarDefNode(sp));
ir.add_variable(Local(LocalInfo {
id: p_id,
ident: name
name: name
}));
});
visit::walk_local(ir, local);
Expand All @@ -433,11 +433,11 @@ fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) {
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
debug!("adding local variable {} from match with bm {:?}",
p_id, bm);
let name = path1.node;
let name = path1.node.name;
ir.add_live_node_for_node(p_id, VarDefNode(sp));
ir.add_variable(Local(LocalInfo {
id: p_id,
ident: name
name: name
}));
})
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use std::vec::IntoIter;
use collections::enum_set::{EnumSet, CLike};
use std::collections::{HashMap, HashSet};
use syntax::abi;
use syntax::ast::{CrateNum, DefId, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{CrateNum, DefId, ItemTrait, LOCAL_CRATE};
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
use syntax::ast::{StmtExpr, StmtSemi, StructField, UnnamedField, Visibility};
use syntax::ast_util::{self, is_local, lit_is_str, local_def};
Expand Down Expand Up @@ -4361,8 +4361,8 @@ pub fn named_element_ty<'tcx>(cx: &ctxt<'tcx>,
variant_info.arg_names.as_ref()
.expect("must have struct enum variant if accessing a named fields")
.iter().zip(variant_info.args.iter())
.find(|&(ident, _)| ident.name == n)
.map(|(_ident, arg_t)| arg_t.subst(cx, substs))
.find(|&(&name, _)| name == n)
.map(|(_name, arg_t)| arg_t.subst(cx, substs))
}
_ => None
}
Expand Down Expand Up @@ -5341,7 +5341,7 @@ pub fn ty_to_def_id(ty: Ty) -> Option<ast::DefId> {
#[derive(Clone)]
pub struct VariantInfo<'tcx> {
pub args: Vec<Ty<'tcx>>,
pub arg_names: Option<Vec<ast::Ident>>,
pub arg_names: Option<Vec<ast::Name>>,
pub ctor_ty: Option<Ty<'tcx>>,
pub name: ast::Name,
pub id: ast::DefId,
Expand Down Expand Up @@ -5388,7 +5388,7 @@ impl<'tcx> VariantInfo<'tcx> {
.map(|field| node_id_to_type(cx, field.node.id)).collect();
let arg_names = fields.iter().map(|field| {
match field.node.kind {
NamedField(ident, _) => ident,
NamedField(ident, _) => ident.name,
UnnamedField(..) => cx.sess.bug(
"enum_variants: all fields in struct must have a name")
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/borrowck/fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
match *origin_field_name {
mc::NamedField(ast_name) => {
let variant_arg_names = variant_info.arg_names.as_ref().unwrap();
for variant_arg_ident in variant_arg_names {
if variant_arg_ident.name == ast_name {
for &variant_arg_name in variant_arg_names {
if variant_arg_name == ast_name {
continue;
}
let field_name = mc::NamedField(variant_arg_ident.name);
let field_name = mc::NamedField(variant_arg_name);
add_fragment_sibling_local(field_name, Some(variant_info.id));
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
fn check_static_method(&mut self,
span: Span,
method_id: ast::DefId,
name: ast::Ident) {
name: ast::Name) {
// If the method is a default method, we need to use the def_id of
// the default implementation.
let method_id = match ty::impl_or_trait_item(self.tcx, method_id) {
Expand All @@ -696,7 +696,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
ty::TypeTraitItem(_) => method_id,
};

let string = token::get_ident(name);
let string = token::get_name(name);
self.report_error(self.ensure_public(span,
method_id,
None,
Expand All @@ -705,13 +705,13 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
}

// Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Name) {
debug!("privacy - path {}", self.nodestr(path_id));
let path_res = *self.tcx.def_map.borrow().get(&path_id).unwrap();
let ck = |tyname: &str| {
let ck_public = |def: ast::DefId| {
debug!("privacy - ck_public {:?}", def);
let name = token::get_ident(last);
let name = token::get_name(last);
let origdid = path_res.def_id();
self.ensure_public(span,
def,
Expand Down Expand Up @@ -800,10 +800,10 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {

// Checks that a method is in scope.
fn check_method(&mut self, span: Span, origin: &MethodOrigin,
ident: ast::Ident) {
name: ast::Name) {
match *origin {
MethodStatic(method_id) => {
self.check_static_method(span, method_id, ident)
self.check_static_method(span, method_id, name)
}
MethodStaticClosure(_) => {}
// Trait methods are always all public. The only controlling factor
Expand All @@ -825,11 +825,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
match pid.node {
ast::PathListIdent { id, name } => {
debug!("privacy - ident item {}", id);
self.check_path(pid.span, id, name);
self.check_path(pid.span, id, name.name);
}
ast::PathListMod { id } => {
debug!("privacy - mod item {}", id);
let name = prefix.segments.last().unwrap().identifier;
let name = prefix.segments.last().unwrap().identifier.name;
self.check_path(pid.span, id, name);
}
}
Expand Down Expand Up @@ -863,7 +863,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}
Some(method) => {
debug!("(privacy checking) checking impl method");
self.check_method(expr.span, &method.origin, ident.node);
self.check_method(expr.span, &method.origin, ident.node.name);
}
}
}
Expand Down Expand Up @@ -1005,7 +1005,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}

fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
self.check_path(path.span, id, path.segments.last().unwrap().identifier);
self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
visit::walk_path(self, path);
}
}
Expand Down
Loading