Skip to content

Commit

Permalink
Remove random Idents outside of libsyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 23, 2015
1 parent 07ca1ab commit 40ce804
Show file tree
Hide file tree
Showing 41 changed files with 147 additions and 152 deletions.
4 changes: 2 additions & 2 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -520,9 +520,9 @@ fn encode_info_for_mod(ecx: &EncodeContext,
});

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

rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(DefId::local(did)));
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/metadata/tydecode.rs
Expand Up @@ -184,8 +184,8 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
'[' => {
let def = self.parse_def(RegionParameter);
let ident = token::str_to_ident(&self.parse_str(']'));
ty::BrNamed(def, ident.name)
let name = token::intern(&self.parse_str(']'));
ty::BrNamed(def, name)
}
'f' => {
let id = self.parse_u32();
Expand Down Expand Up @@ -219,12 +219,12 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
assert_eq!(self.next(), '|');
let index = self.parse_u32();
assert_eq!(self.next(), '|');
let nm = token::str_to_ident(&self.parse_str(']'));
let name = token::intern(&self.parse_str(']'));
ty::ReEarlyBound(ty::EarlyBoundRegion {
param_id: node_id,
space: space,
index: index,
name: nm.name
name: name
})
}
'f' => {
Expand Down Expand Up @@ -598,7 +598,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy {
trait_ref: self.parse_trait_ref(),
item_name: token::str_to_ident(&self.parse_str('|')).name,
item_name: token::intern(&self.parse_str('|')),
},
ty: self.parse_ty(),
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/cfg/construct.rs
Expand Up @@ -284,15 +284,15 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprBreak(label) => {
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
let loop_scope = self.find_scope(expr, label.map(|l| l.node.name));
let b = self.add_ast_node(expr.id, &[pred]);
self.add_exiting_edge(expr, b,
loop_scope, loop_scope.break_index);
self.add_unreachable_node()
}

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

fn find_scope(&self,
expr: &hir::Expr,
label: Option<ast::Ident>) -> LoopScope {
label: Option<ast::Name>) -> LoopScope {
if label.is_none() {
return *self.loop_scopes.last().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Expand Up @@ -114,7 +114,7 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
ps: &mut pprust::State,
node: pprust::AnnNode) -> io::Result<()> {
let id = match node {
pprust::NodeIdent(_) | pprust::NodeName(_) => 0,
pprust::NodeName(_) => 0,
pprust::NodeExpr(expr) => expr.id,
pprust::NodeBlock(blk) => blk.id,
pprust::NodeItem(_) | pprust::NodeSubItem(_) => 0,
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/infer/error_reporting.rs
Expand Up @@ -1015,12 +1015,12 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
},
None => None
};
let (fn_decl, generics, unsafety, constness, ident, expl_self, span)
let (fn_decl, generics, unsafety, constness, name, expl_self, span)
= node_inner.expect("expect item fn");
let rebuilder = Rebuilder::new(self.tcx, fn_decl, expl_self,
generics, same_regions, &life_giver);
let (fn_decl, expl_self, generics) = rebuilder.rebuild();
self.give_expl_lifetime_param(&fn_decl, unsafety, constness, ident,
self.give_expl_lifetime_param(&fn_decl, unsafety, constness, name,
expl_self.as_ref(), &generics, span);
}
}
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
names.push(lt_name);
}
names.sort();
let name = token::str_to_ident(&names[0]).name;
let name = token::intern(&names[0]);
return (name_to_dummy_lifetime(name), Kept);
}
return (self.life_giver.give_lifetime(), Fresh);
Expand Down Expand Up @@ -1938,8 +1938,7 @@ impl LifeGiver {
let mut s = String::from("'");
s.push_str(&num_to_string(self.counter.get()));
if !self.taken.contains(&s) {
lifetime = name_to_dummy_lifetime(
token::str_to_ident(&s[..]).name);
lifetime = name_to_dummy_lifetime(token::intern(&s[..]));
self.generated.borrow_mut().push(lifetime);
break;
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/liveness.rs
Expand Up @@ -383,7 +383,7 @@ fn visit_fn(ir: &mut IrMaps,
&*arg.pat,
|_bm, arg_id, _x, path1| {
debug!("adding argument {}", arg_id);
let name = path1.node.name;
let name = path1.node;
fn_maps.add_variable(Arg(arg_id, name));
})
};
Expand Down Expand Up @@ -416,7 +416,7 @@ fn visit_fn(ir: &mut IrMaps,
fn visit_local(ir: &mut IrMaps, local: &hir::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.name;
let name = path1.node;
ir.add_live_node_for_node(p_id, VarDefNode(sp));
ir.add_variable(Local(LocalInfo {
id: p_id,
Expand All @@ -431,7 +431,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &hir::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.name;
let name = path1.node;
ir.add_live_node_for_node(p_id, VarDefNode(sp));
ir.add_variable(Local(LocalInfo {
id: p_id,
Expand Down Expand Up @@ -688,7 +688,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

fn find_loop_scope(&self,
opt_label: Option<ast::Ident>,
opt_label: Option<ast::Name>,
id: NodeId,
sp: Span)
-> NodeId {
Expand Down Expand Up @@ -1049,7 +1049,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

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

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

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

// Now that we know the label we're going to,
// look it up in the continue loop nodes table
Expand Down Expand Up @@ -1555,8 +1555,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|_bm, p_id, sp, path1| {
let var = self.variable(p_id, sp);
// Ignore unused self.
let ident = path1.node;
if ident.name != special_idents::self_.name {
let name = path1.node;
if name != special_idents::self_.name {
self.warn_about_unused(sp, p_id, entry_ln, var);
}
})
Expand Down
24 changes: 19 additions & 5 deletions src/librustc/middle/pat_util.rs
Expand Up @@ -16,9 +16,9 @@ use util::nodemap::FnvHashMap;
use syntax::ast;
use rustc_front::hir;
use rustc_front::util::walk_pat;
use syntax::codemap::{Span, Spanned, DUMMY_SP};
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};

pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;

// This is used because same-named variables in alternative patterns need to
// use the NodeId of their namesake in the first pattern.
Expand Down Expand Up @@ -109,12 +109,26 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
{
walk_pat(pat, |p| {
match p.node {
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
}
_ => {}
}
true
});
}

pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
{
walk_pat(pat, |p| {
match p.node {
hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
it(binding_mode, p.id, p.span, pth);
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
}
_ => {}
}
Expand Down Expand Up @@ -182,10 +196,10 @@ pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
contains_bindings
}

pub fn simple_identifier<'a>(pat: &'a hir::Pat) -> Option<&'a ast::Ident> {
pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option<ast::Name> {
match pat.node {
hir::PatIdent(hir::BindByValue(_), ref path1, None) => {
Some(&path1.node)
Some(path1.node.name)
}
_ => {
None
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -73,7 +73,7 @@ struct LifetimeContext<'a> {
trait_ref_hack: bool,

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

enum ScopeChain<'a> {
Expand Down Expand Up @@ -381,7 +381,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
struct GatherLabels<'a> {
sess: &'a Session,
scope: Scope<'a>,
labels_in_fn: &'a mut Vec<(ast::Ident, Span)>,
labels_in_fn: &'a mut Vec<(ast::Name, Span)>,
}

let mut gather = GatherLabels {
Expand All @@ -403,9 +403,9 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
if let Some(label) = expression_label(ex) {
for &(prior, prior_span) in &self.labels_in_fn[..] {
// FIXME (#24278): non-hygienic comparison
if label.name == prior.name {
if label == prior {
signal_shadowing_problem(self.sess,
label.name,
label,
original_label(prior_span),
shadower_label(ex.span));
}
Expand All @@ -426,17 +426,17 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
}
}

fn expression_label(ex: &hir::Expr) -> Option<ast::Ident> {
fn expression_label(ex: &hir::Expr) -> Option<ast::Name> {
match ex.node {
hir::ExprWhile(_, _, Some(label)) |
hir::ExprLoop(_, Some(label)) => Some(label),
hir::ExprLoop(_, Some(label)) => Some(label.name),
_ => None,
}
}

fn check_if_label_shadows_lifetime<'a>(sess: &'a Session,
mut scope: Scope<'a>,
label: ast::Ident,
label: ast::Name,
label_span: Span) {
loop {
match *scope {
Expand All @@ -447,10 +447,10 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
LateScope(lifetimes, s) => {
for lifetime_def in lifetimes {
// FIXME (#24278): non-hygienic comparison
if label.name == lifetime_def.lifetime.name {
if label == lifetime_def.lifetime.name {
signal_shadowing_problem(
sess,
label.name,
label,
original_lifetime(&lifetime_def.lifetime),
shadower_label(label_span));
return;
Expand Down Expand Up @@ -703,7 +703,7 @@ impl<'a> LifetimeContext<'a> {
{
for &(label, label_span) in &self.labels_in_fn {
// FIXME (#24278): non-hygienic comparison
if lifetime.name == label.name {
if lifetime.name == label {
signal_shadowing_problem(self.sess,
lifetime.name,
original_label(label_span),
Expand Down
Expand Up @@ -99,7 +99,7 @@ pub fn gather_move_from_pat<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
let pat_span_path_opt = match move_pat.node {
hir::PatIdent(_, ref path1, _) => {
Some(MoveSpanAndPath{span: move_pat.span,
ident: path1.node})
name: path1.node.name})
},
_ => None,
};
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Expand Up @@ -57,7 +57,7 @@ impl<'tcx> MoveError<'tcx> {
#[derive(Clone)]
pub struct MoveSpanAndPath {
pub span: codemap::Span,
pub ident: ast::Ident
pub name: ast::Name,
}

pub struct GroupedMoveErrors<'tcx> {
Expand All @@ -73,7 +73,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
let mut is_first_note = true;
for move_to in &error.move_to_places {
note_move_destination(bccx, move_to.span,
&move_to.ident, is_first_note);
move_to.name, is_first_note);
is_first_note = false;
}
}
Expand Down Expand Up @@ -157,9 +157,9 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,

fn note_move_destination(bccx: &BorrowckCtxt,
move_to_span: codemap::Span,
pat_ident: &ast::Ident,
pat_name: ast::Name,
is_first_note: bool) {
let pat_name = pprust::ident_to_string(pat_ident);
let pat_name = pprust::name_to_string(pat_name);
if is_first_note {
bccx.span_note(
move_to_span,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_driver/pretty.rs
Expand Up @@ -330,8 +330,7 @@ impl<'ast> pprust_hir::PpAnn for IdentifiedAnnotation<'ast> {
s: &mut pprust_hir::State,
node: pprust_hir::AnnNode) -> io::Result<()> {
match node {
pprust_hir::NodeIdent(_) | pprust_hir::NodeName(_) => Ok(()),

pprust_hir::NodeName(_) => Ok(()),
pprust_hir::NodeItem(item) => {
try!(pp::space(&mut s.s));
s.synth_comment(item.id.to_string())
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_front/fold.rs
Expand Up @@ -296,8 +296,8 @@ pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T
pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<ViewPath> {
view_path.map(|Spanned {node, span}| Spanned {
node: match node {
ViewPathSimple(ident, path) => {
ViewPathSimple(ident, fld.fold_path(path))
ViewPathSimple(name, path) => {
ViewPathSimple(name, fld.fold_path(path))
}
ViewPathGlob(path) => {
ViewPathGlob(fld.fold_path(path))
Expand Down Expand Up @@ -520,11 +520,11 @@ pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mu
-> ExplicitSelf_ {
match es {
SelfStatic | SelfValue(_) => es,
SelfRegion(lifetime, m, ident) => {
SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident)
SelfRegion(lifetime, m, name) => {
SelfRegion(fld.fold_opt_lifetime(lifetime), m, name)
}
SelfExplicit(typ, ident) => {
SelfExplicit(fld.fold_ty(typ), ident)
SelfExplicit(typ, name) => {
SelfExplicit(fld.fold_ty(typ), name)
}
}
}
Expand Down Expand Up @@ -1111,10 +1111,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
respan(folder.new_span(name.span),
folder.fold_name(name.node)))
}
ExprTupField(el, ident) => {
ExprTupField(el, index) => {
ExprTupField(folder.fold_expr(el),
respan(folder.new_span(ident.span),
folder.fold_usize(ident.node)))
respan(folder.new_span(index.span),
folder.fold_usize(index.node)))
}
ExprIndex(el, er) => {
ExprIndex(folder.fold_expr(el), folder.fold_expr(er))
Expand Down

0 comments on commit 40ce804

Please sign in to comment.