Skip to content

Commit 3cbc345

Browse files
committed
In librustc*, convert many uses of ast::Ident to ast::Name, fixing much of #6993.
1 parent c1b8eb5 commit 3cbc345

File tree

14 files changed

+117
-121
lines changed

14 files changed

+117
-121
lines changed

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
763763
let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
764764
.iter()
765765
.map(|field_ty| {
766-
arg_names.push(ast::Ident::new(field_ty.name));
766+
arg_names.push(field_ty.name);
767767
get_type(cdata, field_ty.id.node, tcx).ty
768768
})
769769
.collect();

src/librustc/metadata/encoder.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
8787
rbml_w.wr_tagged_str(tag_paths_data_name, &token::get_name(name));
8888
}
8989

90-
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) {
91-
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_ident(name));
90+
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Name) {
91+
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_name(name));
9292
}
9393

9494
pub fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
@@ -519,12 +519,12 @@ fn encode_info_for_mod(ecx: &EncodeContext,
519519
attrs: &[ast::Attribute],
520520
id: NodeId,
521521
path: PathElems,
522-
name: ast::Ident,
522+
name: ast::Name,
523523
vis: ast::Visibility) {
524524
rbml_w.start_tag(tag_items_data_item);
525525
encode_def_id(rbml_w, local_def(id));
526526
encode_family(rbml_w, 'm');
527-
encode_name(rbml_w, name.name);
527+
encode_name(rbml_w, name);
528528
debug!("(encoding info for module) encoding info for module ID {}", id);
529529

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

667667
fn encode_info_for_struct_ctor(ecx: &EncodeContext,
668668
rbml_w: &mut Encoder,
669-
name: ast::Ident,
669+
name: ast::Name,
670670
ctor_id: NodeId,
671671
index: &mut Vec<entry<i64>>,
672672
struct_id: NodeId) {
@@ -679,7 +679,7 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
679679
encode_def_id(rbml_w, local_def(ctor_id));
680680
encode_family(rbml_w, 'o');
681681
encode_bounds_and_type_for_item(rbml_w, ecx, ctor_id);
682-
encode_name(rbml_w, name.name);
682+
encode_name(rbml_w, name);
683683
ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path));
684684
encode_parent_item(rbml_w, local_def(struct_id));
685685

@@ -886,7 +886,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
886886
for arg in &decl.inputs {
887887
let tag = tag_method_argument_name;
888888
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
889-
let name = token::get_ident(path1.node);
889+
let name = token::get_name(path1.node.name);
890890
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
891891
} else {
892892
rbml_w.wr_tagged_bytes(tag, &[]);
@@ -1044,7 +1044,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10441044
&item.attrs,
10451045
item.id,
10461046
path,
1047-
item.ident,
1047+
item.ident.name,
10481048
item.vis);
10491049
}
10501050
ast::ItemForeignMod(ref fm) => {
@@ -1152,7 +1152,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11521152
// If this is a tuple-like struct, encode the type of the constructor.
11531153
match struct_def.ctor_id {
11541154
Some(ctor_id) => {
1155-
encode_info_for_struct_ctor(ecx, rbml_w, item.ident,
1155+
encode_info_for_struct_ctor(ecx, rbml_w, item.ident.name,
11561156
ctor_id, index, def_id.node);
11571157
}
11581158
None => {}
@@ -1187,8 +1187,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
11871187
encode_polarity(rbml_w, polarity);
11881188
match ty.node {
11891189
ast::TyPath(None, ref path) if path.segments.len() == 1 => {
1190-
let ident = path.segments.last().unwrap().identifier;
1191-
encode_impl_type_basename(rbml_w, ident);
1190+
let name = path.segments.last().unwrap().identifier.name;
1191+
encode_impl_type_basename(rbml_w, name);
11921192
}
11931193
_ => {}
11941194
}
@@ -1513,7 +1513,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
15131513
&[],
15141514
ast::CRATE_NODE_ID,
15151515
[].iter().cloned().chain(LinkedPath::empty()),
1516-
syntax::parse::token::special_idents::invalid,
1516+
syntax::parse::token::special_idents::invalid.name,
15171517
ast::Public);
15181518

15191519
visit::walk_crate(&mut EncodeVisitor {

src/librustc/metadata/tydecode.rs

-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ fn scan<R, F, G>(st: &mut PState, mut is_last: F, op: G) -> R where
101101
return op(&st.data[start_pos..end_pos]);
102102
}
103103

104-
pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
105-
ast::Ident::new(parse_name(st, last))
106-
}
107-
108104
pub fn parse_name(st: &mut PState, last: char) -> ast::Name {
109105
fn is_last(b: char, c: char) -> bool { return c == b; }
110106
parse_name_(st, |a| is_last(last, a) )

src/librustc/middle/dead.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
133133
}
134134
}
135135

136-
fn handle_field_access(&mut self, lhs: &ast::Expr, name: &ast::Ident) {
136+
fn handle_field_access(&mut self, lhs: &ast::Expr, name: ast::Name) {
137137
match ty::expr_ty_adjusted(self.tcx, lhs).sty {
138138
ty::ty_struct(id, _) => {
139139
let fields = ty::lookup_struct_fields(self.tcx, id);
140140
let field_id = fields.iter()
141-
.find(|field| field.name == name.name).unwrap().id;
141+
.find(|field| field.name == name).unwrap().id;
142142
self.live_symbols.insert(field_id.node);
143143
},
144144
_ => ()
@@ -267,7 +267,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
267267
self.lookup_and_handle_method(expr.id, expr.span);
268268
}
269269
ast::ExprField(ref lhs, ref ident) => {
270-
self.handle_field_access(&**lhs, &ident.node);
270+
self.handle_field_access(&**lhs, ident.node.name);
271271
}
272272
ast::ExprTupField(ref lhs, idx) => {
273273
self.handle_tup_field_access(&**lhs, idx.node);
@@ -511,9 +511,9 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
511511
fn warn_dead_code(&mut self,
512512
id: ast::NodeId,
513513
span: codemap::Span,
514-
ident: ast::Ident,
514+
name: ast::Name,
515515
node_type: &str) {
516-
let name = ident.as_str();
516+
let name = name.as_str();
517517
if !name.starts_with("_") {
518518
self.tcx
519519
.sess
@@ -528,14 +528,19 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
528528
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
529529
fn visit_item(&mut self, item: &ast::Item) {
530530
if self.should_warn_about_item(item) {
531-
self.warn_dead_code(item.id, item.span, item.ident, item.node.descriptive_variant());
531+
self.warn_dead_code(
532+
item.id,
533+
item.span,
534+
item.ident.name,
535+
item.node.descriptive_variant()
536+
);
532537
} else {
533538
match item.node {
534539
ast::ItemEnum(ref enum_def, _) => {
535540
for variant in &enum_def.variants {
536541
if self.should_warn_about_variant(&variant.node) {
537542
self.warn_dead_code(variant.node.id, variant.span,
538-
variant.node.name, "variant");
543+
variant.node.name.name, "variant");
539544
}
540545
}
541546
},
@@ -547,7 +552,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
547552

548553
fn visit_foreign_item(&mut self, fi: &ast::ForeignItem) {
549554
if !self.symbol_is_live(fi.id, None) {
550-
self.warn_dead_code(fi.id, fi.span, fi.ident, fi.node.descriptive_variant());
555+
self.warn_dead_code(fi.id, fi.span, fi.ident.name, fi.node.descriptive_variant());
551556
}
552557
visit::walk_foreign_item(self, fi);
553558
}
@@ -559,7 +564,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
559564
match fk {
560565
visit::FkMethod(name, _) => {
561566
if !self.symbol_is_live(id, None) {
562-
self.warn_dead_code(id, span, name, "method");
567+
self.warn_dead_code(id, span, name.name, "method");
563568
}
564569
}
565570
_ => ()
@@ -570,7 +575,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
570575
fn visit_struct_field(&mut self, field: &ast::StructField) {
571576
if self.should_warn_about_field(&field.node) {
572577
self.warn_dead_code(field.node.id, field.span,
573-
field.node.ident().unwrap(), "struct field");
578+
field.node.ident().unwrap().name, "struct field");
574579
}
575580

576581
visit::walk_struct_field(self, field);

src/librustc/middle/liveness.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ struct CaptureInfo {
248248
#[derive(Copy, Clone, Debug)]
249249
struct LocalInfo {
250250
id: NodeId,
251-
ident: ast::Ident
251+
name: ast::Name
252252
}
253253

254254
#[derive(Copy, Clone, Debug)]
255255
enum VarKind {
256-
Arg(NodeId, ast::Ident),
256+
Arg(NodeId, ast::Name),
257257
Local(LocalInfo),
258258
ImplicitRet,
259259
CleanExit
@@ -334,8 +334,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
334334

335335
fn variable_name(&self, var: Variable) -> String {
336336
match self.var_kinds[var.get()] {
337-
Local(LocalInfo { ident: nm, .. }) | Arg(_, nm) => {
338-
token::get_ident(nm).to_string()
337+
Local(LocalInfo { name, .. }) | Arg(_, name) => {
338+
token::get_name(name).to_string()
339339
},
340340
ImplicitRet => "<implicit-ret>".to_string(),
341341
CleanExit => "<clean-exit>".to_string()
@@ -385,8 +385,8 @@ fn visit_fn(ir: &mut IrMaps,
385385
&*arg.pat,
386386
|_bm, arg_id, _x, path1| {
387387
debug!("adding argument {}", arg_id);
388-
let ident = path1.node;
389-
fn_maps.add_variable(Arg(arg_id, ident));
388+
let name = path1.node.name;
389+
fn_maps.add_variable(Arg(arg_id, name));
390390
})
391391
};
392392

@@ -418,11 +418,11 @@ fn visit_fn(ir: &mut IrMaps,
418418
fn visit_local(ir: &mut IrMaps, local: &ast::Local) {
419419
pat_util::pat_bindings(&ir.tcx.def_map, &*local.pat, |_, p_id, sp, path1| {
420420
debug!("adding local variable {}", p_id);
421-
let name = path1.node;
421+
let name = path1.node.name;
422422
ir.add_live_node_for_node(p_id, VarDefNode(sp));
423423
ir.add_variable(Local(LocalInfo {
424424
id: p_id,
425-
ident: name
425+
name: name
426426
}));
427427
});
428428
visit::walk_local(ir, local);
@@ -433,11 +433,11 @@ fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) {
433433
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
434434
debug!("adding local variable {} from match with bm {:?}",
435435
p_id, bm);
436-
let name = path1.node;
436+
let name = path1.node.name;
437437
ir.add_live_node_for_node(p_id, VarDefNode(sp));
438438
ir.add_variable(Local(LocalInfo {
439439
id: p_id,
440-
ident: name
440+
name: name
441441
}));
442442
})
443443
}

src/librustc/middle/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use std::vec::IntoIter;
8080
use collections::enum_set::{EnumSet, CLike};
8181
use std::collections::{HashMap, HashSet};
8282
use syntax::abi;
83-
use syntax::ast::{CrateNum, DefId, Ident, ItemTrait, LOCAL_CRATE};
83+
use syntax::ast::{CrateNum, DefId, ItemTrait, LOCAL_CRATE};
8484
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
8585
use syntax::ast::{StmtExpr, StmtSemi, StructField, UnnamedField, Visibility};
8686
use syntax::ast_util::{self, is_local, lit_is_str, local_def};
@@ -4361,8 +4361,8 @@ pub fn named_element_ty<'tcx>(cx: &ctxt<'tcx>,
43614361
variant_info.arg_names.as_ref()
43624362
.expect("must have struct enum variant if accessing a named fields")
43634363
.iter().zip(variant_info.args.iter())
4364-
.find(|&(ident, _)| ident.name == n)
4365-
.map(|(_ident, arg_t)| arg_t.subst(cx, substs))
4364+
.find(|&(&name, _)| name == n)
4365+
.map(|(_name, arg_t)| arg_t.subst(cx, substs))
43664366
}
43674367
_ => None
43684368
}
@@ -5341,7 +5341,7 @@ pub fn ty_to_def_id(ty: Ty) -> Option<ast::DefId> {
53415341
#[derive(Clone)]
53425342
pub struct VariantInfo<'tcx> {
53435343
pub args: Vec<Ty<'tcx>>,
5344-
pub arg_names: Option<Vec<ast::Ident>>,
5344+
pub arg_names: Option<Vec<ast::Name>>,
53455345
pub ctor_ty: Option<Ty<'tcx>>,
53465346
pub name: ast::Name,
53475347
pub id: ast::DefId,
@@ -5388,7 +5388,7 @@ impl<'tcx> VariantInfo<'tcx> {
53885388
.map(|field| node_id_to_type(cx, field.node.id)).collect();
53895389
let arg_names = fields.iter().map(|field| {
53905390
match field.node.kind {
5391-
NamedField(ident, _) => ident,
5391+
NamedField(ident, _) => ident.name,
53925392
UnnamedField(..) => cx.sess.bug(
53935393
"enum_variants: all fields in struct must have a name")
53945394
}

src/librustc_borrowck/borrowck/fragments.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
396396
match *origin_field_name {
397397
mc::NamedField(ast_name) => {
398398
let variant_arg_names = variant_info.arg_names.as_ref().unwrap();
399-
for variant_arg_ident in variant_arg_names {
400-
if variant_arg_ident.name == ast_name {
399+
for &variant_arg_name in variant_arg_names {
400+
if variant_arg_name == ast_name {
401401
continue;
402402
}
403-
let field_name = mc::NamedField(variant_arg_ident.name);
403+
let field_name = mc::NamedField(variant_arg_name);
404404
add_fragment_sibling_local(field_name, Some(variant_info.id));
405405
}
406406
}

src/librustc_privacy/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
686686
fn check_static_method(&mut self,
687687
span: Span,
688688
method_id: ast::DefId,
689-
name: ast::Ident) {
689+
name: ast::Name) {
690690
// If the method is a default method, we need to use the def_id of
691691
// the default implementation.
692692
let method_id = match ty::impl_or_trait_item(self.tcx, method_id) {
@@ -696,7 +696,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
696696
ty::TypeTraitItem(_) => method_id,
697697
};
698698

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

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

801801
// Checks that a method is in scope.
802802
fn check_method(&mut self, span: Span, origin: &MethodOrigin,
803-
ident: ast::Ident) {
803+
name: ast::Name) {
804804
match *origin {
805805
MethodStatic(method_id) => {
806-
self.check_static_method(span, method_id, ident)
806+
self.check_static_method(span, method_id, name)
807807
}
808808
MethodStaticClosure(_) => {}
809809
// Trait methods are always all public. The only controlling factor
@@ -825,11 +825,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
825825
match pid.node {
826826
ast::PathListIdent { id, name } => {
827827
debug!("privacy - ident item {}", id);
828-
self.check_path(pid.span, id, name);
828+
self.check_path(pid.span, id, name.name);
829829
}
830830
ast::PathListMod { id } => {
831831
debug!("privacy - mod item {}", id);
832-
let name = prefix.segments.last().unwrap().identifier;
832+
let name = prefix.segments.last().unwrap().identifier.name;
833833
self.check_path(pid.span, id, name);
834834
}
835835
}
@@ -863,7 +863,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
863863
}
864864
Some(method) => {
865865
debug!("(privacy checking) checking impl method");
866-
self.check_method(expr.span, &method.origin, ident.node);
866+
self.check_method(expr.span, &method.origin, ident.node.name);
867867
}
868868
}
869869
}
@@ -1005,7 +1005,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
10051005
}
10061006

10071007
fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
1008-
self.check_path(path.span, id, path.segments.last().unwrap().identifier);
1008+
self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
10091009
visit::walk_path(self, path);
10101010
}
10111011
}

0 commit comments

Comments
 (0)