Skip to content

Commit 40ce804

Browse files
committed
Remove random Idents outside of libsyntax
1 parent 07ca1ab commit 40ce804

File tree

41 files changed

+147
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+147
-152
lines changed

src/librustc/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ fn encode_info_for_mod(ecx: &EncodeContext,
520520
});
521521

522522
if let hir::ItemImpl(..) = item.node {
523-
let (ident, did) = (item.name, item.id);
523+
let (name, did) = (item.name, item.id);
524524
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
525-
ident,
525+
name,
526526
did, ecx.tcx.map.node_to_string(did));
527527

528528
rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(DefId::local(did)));

src/librustc/metadata/tydecode.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
184184
}
185185
'[' => {
186186
let def = self.parse_def(RegionParameter);
187-
let ident = token::str_to_ident(&self.parse_str(']'));
188-
ty::BrNamed(def, ident.name)
187+
let name = token::intern(&self.parse_str(']'));
188+
ty::BrNamed(def, name)
189189
}
190190
'f' => {
191191
let id = self.parse_u32();
@@ -219,12 +219,12 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
219219
assert_eq!(self.next(), '|');
220220
let index = self.parse_u32();
221221
assert_eq!(self.next(), '|');
222-
let nm = token::str_to_ident(&self.parse_str(']'));
222+
let name = token::intern(&self.parse_str(']'));
223223
ty::ReEarlyBound(ty::EarlyBoundRegion {
224224
param_id: node_id,
225225
space: space,
226226
index: index,
227-
name: nm.name
227+
name: name
228228
})
229229
}
230230
'f' => {
@@ -598,7 +598,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
598598
ty::ProjectionPredicate {
599599
projection_ty: ty::ProjectionTy {
600600
trait_ref: self.parse_trait_ref(),
601-
item_name: token::str_to_ident(&self.parse_str('|')).name,
601+
item_name: token::intern(&self.parse_str('|')),
602602
},
603603
ty: self.parse_ty(),
604604
}

src/librustc/middle/cfg/construct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
284284
}
285285

286286
hir::ExprBreak(label) => {
287-
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
287+
let loop_scope = self.find_scope(expr, label.map(|l| l.node.name));
288288
let b = self.add_ast_node(expr.id, &[pred]);
289289
self.add_exiting_edge(expr, b,
290290
loop_scope, loop_scope.break_index);
291291
self.add_unreachable_node()
292292
}
293293

294294
hir::ExprAgain(label) => {
295-
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
295+
let loop_scope = self.find_scope(expr, label.map(|l| l.node.name));
296296
let a = self.add_ast_node(expr.id, &[pred]);
297297
self.add_exiting_edge(expr, a,
298298
loop_scope, loop_scope.continue_index);
@@ -586,7 +586,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
586586

587587
fn find_scope(&self,
588588
expr: &hir::Expr,
589-
label: Option<ast::Ident>) -> LoopScope {
589+
label: Option<ast::Name>) -> LoopScope {
590590
if label.is_none() {
591591
return *self.loop_scopes.last().unwrap();
592592
}

src/librustc/middle/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
114114
ps: &mut pprust::State,
115115
node: pprust::AnnNode) -> io::Result<()> {
116116
let id = match node {
117-
pprust::NodeIdent(_) | pprust::NodeName(_) => 0,
117+
pprust::NodeName(_) => 0,
118118
pprust::NodeExpr(expr) => expr.id,
119119
pprust::NodeBlock(blk) => blk.id,
120120
pprust::NodeItem(_) | pprust::NodeSubItem(_) => 0,

src/librustc/middle/infer/error_reporting.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,12 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
10151015
},
10161016
None => None
10171017
};
1018-
let (fn_decl, generics, unsafety, constness, ident, expl_self, span)
1018+
let (fn_decl, generics, unsafety, constness, name, expl_self, span)
10191019
= node_inner.expect("expect item fn");
10201020
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
10211021
generics, same_regions, &life_giver);
10221022
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
1023-
self.give_expl_lifetime_param(&fn_decl, unsafety, constness, ident,
1023+
self.give_expl_lifetime_param(&fn_decl, unsafety, constness, name,
10241024
expl_self.as_ref(), &generics, span);
10251025
}
10261026
}
@@ -1127,7 +1127,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11271127
names.push(lt_name);
11281128
}
11291129
names.sort();
1130-
let name = token::str_to_ident(&names[0]).name;
1130+
let name = token::intern(&names[0]);
11311131
return (name_to_dummy_lifetime(name), Kept);
11321132
}
11331133
return (self.life_giver.give_lifetime(), Fresh);
@@ -1938,8 +1938,7 @@ impl LifeGiver {
19381938
let mut s = String::from("'");
19391939
s.push_str(&num_to_string(self.counter.get()));
19401940
if !self.taken.contains(&s) {
1941-
lifetime = name_to_dummy_lifetime(
1942-
token::str_to_ident(&s[..]).name);
1941+
lifetime = name_to_dummy_lifetime(token::intern(&s[..]));
19431942
self.generated.borrow_mut().push(lifetime);
19441943
break;
19451944
}

src/librustc/middle/liveness.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn visit_fn(ir: &mut IrMaps,
383383
&*arg.pat,
384384
|_bm, arg_id, _x, path1| {
385385
debug!("adding argument {}", arg_id);
386-
let name = path1.node.name;
386+
let name = path1.node;
387387
fn_maps.add_variable(Arg(arg_id, name));
388388
})
389389
};
@@ -416,7 +416,7 @@ fn visit_fn(ir: &mut IrMaps,
416416
fn visit_local(ir: &mut IrMaps, local: &hir::Local) {
417417
pat_util::pat_bindings(&ir.tcx.def_map, &*local.pat, |_, p_id, sp, path1| {
418418
debug!("adding local variable {}", p_id);
419-
let name = path1.node.name;
419+
let name = path1.node;
420420
ir.add_live_node_for_node(p_id, VarDefNode(sp));
421421
ir.add_variable(Local(LocalInfo {
422422
id: p_id,
@@ -431,7 +431,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &hir::Arm) {
431431
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
432432
debug!("adding local variable {} from match with bm {:?}",
433433
p_id, bm);
434-
let name = path1.node.name;
434+
let name = path1.node;
435435
ir.add_live_node_for_node(p_id, VarDefNode(sp));
436436
ir.add_variable(Local(LocalInfo {
437437
id: p_id,
@@ -688,7 +688,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
688688
}
689689

690690
fn find_loop_scope(&self,
691-
opt_label: Option<ast::Ident>,
691+
opt_label: Option<ast::Name>,
692692
id: NodeId,
693693
sp: Span)
694694
-> NodeId {
@@ -1049,7 +1049,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10491049

10501050
hir::ExprBreak(opt_label) => {
10511051
// Find which label this break jumps to
1052-
let sc = self.find_loop_scope(opt_label.map(|l| l.node), expr.id, expr.span);
1052+
let sc = self.find_loop_scope(opt_label.map(|l| l.node.name), expr.id, expr.span);
10531053

10541054
// Now that we know the label we're going to,
10551055
// look it up in the break loop nodes table
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10631063

10641064
hir::ExprAgain(opt_label) => {
10651065
// Find which label this expr continues to
1066-
let sc = self.find_loop_scope(opt_label.map(|l| l.node), expr.id, expr.span);
1066+
let sc = self.find_loop_scope(opt_label.map(|l| l.node.name), expr.id, expr.span);
10671067

10681068
// Now that we know the label we're going to,
10691069
// look it up in the continue loop nodes table
@@ -1555,8 +1555,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15551555
|_bm, p_id, sp, path1| {
15561556
let var = self.variable(p_id, sp);
15571557
// Ignore unused self.
1558-
let ident = path1.node;
1559-
if ident.name != special_idents::self_.name {
1558+
let name = path1.node;
1559+
if name != special_idents::self_.name {
15601560
self.warn_about_unused(sp, p_id, entry_ln, var);
15611561
}
15621562
})

src/librustc/middle/pat_util.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use util::nodemap::FnvHashMap;
1616
use syntax::ast;
1717
use rustc_front::hir;
1818
use rustc_front::util::walk_pat;
19-
use syntax::codemap::{Span, Spanned, DUMMY_SP};
19+
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
2020

21-
pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
21+
pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
2222

2323
// This is used because same-named variables in alternative patterns need to
2424
// use the NodeId of their namesake in the first pattern.
@@ -109,12 +109,26 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
109109
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
110110
/// `match foo() { Some(a) => (), None => () }`
111111
pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
112+
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
113+
{
114+
walk_pat(pat, |p| {
115+
match p.node {
116+
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
117+
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
118+
}
119+
_ => {}
120+
}
121+
true
122+
});
123+
}
124+
125+
pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
112126
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
113127
{
114128
walk_pat(pat, |p| {
115129
match p.node {
116130
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
117-
it(binding_mode, p.id, p.span, pth);
131+
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
118132
}
119133
_ => {}
120134
}
@@ -182,10 +196,10 @@ pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
182196
contains_bindings
183197
}
184198

185-
pub fn simple_identifier<'a>(pat: &'a hir::Pat) -> Option<&'a ast::Ident> {
199+
pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option<ast::Name> {
186200
match pat.node {
187201
hir::PatIdent(hir::BindByValue(_), ref path1, None) => {
188-
Some(&path1.node)
202+
Some(path1.node.name)
189203
}
190204
_ => {
191205
None

src/librustc/middle/resolve_lifetime.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct LifetimeContext<'a> {
7373
trait_ref_hack: bool,
7474

7575
// List of labels in the function/method currently under analysis.
76-
labels_in_fn: Vec<(ast::Ident, Span)>,
76+
labels_in_fn: Vec<(ast::Name, Span)>,
7777
}
7878

7979
enum ScopeChain<'a> {
@@ -381,7 +381,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
381381
struct GatherLabels<'a> {
382382
sess: &'a Session,
383383
scope: Scope<'a>,
384-
labels_in_fn: &'a mut Vec<(ast::Ident, Span)>,
384+
labels_in_fn: &'a mut Vec<(ast::Name, Span)>,
385385
}
386386

387387
let mut gather = GatherLabels {
@@ -403,9 +403,9 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
403403
if let Some(label) = expression_label(ex) {
404404
for &(prior, prior_span) in &self.labels_in_fn[..] {
405405
// FIXME (#24278): non-hygienic comparison
406-
if label.name == prior.name {
406+
if label == prior {
407407
signal_shadowing_problem(self.sess,
408-
label.name,
408+
label,
409409
original_label(prior_span),
410410
shadower_label(ex.span));
411411
}
@@ -426,17 +426,17 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
426426
}
427427
}
428428

429-
fn expression_label(ex: &hir::Expr) -> Option<ast::Ident> {
429+
fn expression_label(ex: &hir::Expr) -> Option<ast::Name> {
430430
match ex.node {
431431
hir::ExprWhile(_, _, Some(label)) |
432-
hir::ExprLoop(_, Some(label)) => Some(label),
432+
hir::ExprLoop(_, Some(label)) => Some(label.name),
433433
_ => None,
434434
}
435435
}
436436

437437
fn check_if_label_shadows_lifetime<'a>(sess: &'a Session,
438438
mut scope: Scope<'a>,
439-
label: ast::Ident,
439+
label: ast::Name,
440440
label_span: Span) {
441441
loop {
442442
match *scope {
@@ -447,10 +447,10 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
447447
LateScope(lifetimes, s) => {
448448
for lifetime_def in lifetimes {
449449
// FIXME (#24278): non-hygienic comparison
450-
if label.name == lifetime_def.lifetime.name {
450+
if label == lifetime_def.lifetime.name {
451451
signal_shadowing_problem(
452452
sess,
453-
label.name,
453+
label,
454454
original_lifetime(&lifetime_def.lifetime),
455455
shadower_label(label_span));
456456
return;
@@ -703,7 +703,7 @@ impl<'a> LifetimeContext<'a> {
703703
{
704704
for &(label, label_span) in &self.labels_in_fn {
705705
// FIXME (#24278): non-hygienic comparison
706-
if lifetime.name == label.name {
706+
if lifetime.name == label {
707707
signal_shadowing_problem(self.sess,
708708
lifetime.name,
709709
original_label(label_span),

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn gather_move_from_pat<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
9999
let pat_span_path_opt = match move_pat.node {
100100
hir::PatIdent(_, ref path1, _) => {
101101
Some(MoveSpanAndPath{span: move_pat.span,
102-
ident: path1.node})
102+
name: path1.node.name})
103103
},
104104
_ => None,
105105
};

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> MoveError<'tcx> {
5757
#[derive(Clone)]
5858
pub struct MoveSpanAndPath {
5959
pub span: codemap::Span,
60-
pub ident: ast::Ident
60+
pub name: ast::Name,
6161
}
6262

6363
pub struct GroupedMoveErrors<'tcx> {
@@ -73,7 +73,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
7373
let mut is_first_note = true;
7474
for move_to in &error.move_to_places {
7575
note_move_destination(bccx, move_to.span,
76-
&move_to.ident, is_first_note);
76+
move_to.name, is_first_note);
7777
is_first_note = false;
7878
}
7979
}
@@ -157,9 +157,9 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
157157

158158
fn note_move_destination(bccx: &BorrowckCtxt,
159159
move_to_span: codemap::Span,
160-
pat_ident: &ast::Ident,
160+
pat_name: ast::Name,
161161
is_first_note: bool) {
162-
let pat_name = pprust::ident_to_string(pat_ident);
162+
let pat_name = pprust::name_to_string(pat_name);
163163
if is_first_note {
164164
bccx.span_note(
165165
move_to_span,

src/librustc_driver/pretty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ impl<'ast> pprust_hir::PpAnn for IdentifiedAnnotation<'ast> {
330330
s: &mut pprust_hir::State,
331331
node: pprust_hir::AnnNode) -> io::Result<()> {
332332
match node {
333-
pprust_hir::NodeIdent(_) | pprust_hir::NodeName(_) => Ok(()),
334-
333+
pprust_hir::NodeName(_) => Ok(()),
335334
pprust_hir::NodeItem(item) => {
336335
try!(pp::space(&mut s.s));
337336
s.synth_comment(item.id.to_string())

src/librustc_front/fold.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T
296296
pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<ViewPath> {
297297
view_path.map(|Spanned {node, span}| Spanned {
298298
node: match node {
299-
ViewPathSimple(ident, path) => {
300-
ViewPathSimple(ident, fld.fold_path(path))
299+
ViewPathSimple(name, path) => {
300+
ViewPathSimple(name, fld.fold_path(path))
301301
}
302302
ViewPathGlob(path) => {
303303
ViewPathGlob(fld.fold_path(path))
@@ -520,11 +520,11 @@ pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mu
520520
-> ExplicitSelf_ {
521521
match es {
522522
SelfStatic | SelfValue(_) => es,
523-
SelfRegion(lifetime, m, ident) => {
524-
SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident)
523+
SelfRegion(lifetime, m, name) => {
524+
SelfRegion(fld.fold_opt_lifetime(lifetime), m, name)
525525
}
526-
SelfExplicit(typ, ident) => {
527-
SelfExplicit(fld.fold_ty(typ), ident)
526+
SelfExplicit(typ, name) => {
527+
SelfExplicit(fld.fold_ty(typ), name)
528528
}
529529
}
530530
}
@@ -1111,10 +1111,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
11111111
respan(folder.new_span(name.span),
11121112
folder.fold_name(name.node)))
11131113
}
1114-
ExprTupField(el, ident) => {
1114+
ExprTupField(el, index) => {
11151115
ExprTupField(folder.fold_expr(el),
1116-
respan(folder.new_span(ident.span),
1117-
folder.fold_usize(ident.node)))
1116+
respan(folder.new_span(index.span),
1117+
folder.fold_usize(index.node)))
11181118
}
11191119
ExprIndex(el, er) => {
11201120
ExprIndex(folder.fold_expr(el), folder.fold_expr(er))

0 commit comments

Comments
 (0)