Skip to content

Replace Idents with Names outside of libsyntax + Idents/Names cleanup (Part 2) #28642

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

Merged
merged 2 commits into from
Sep 26, 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
8 changes: 4 additions & 4 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use syntax::parse::lexer::TokenAndSpan;

fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
fn id() -> token::Token {
token::Ident(ast::Ident { name: Name(0), ctxt: 0, }, token::Plain)
token::Ident(ast::Ident::with_empty_ctxt(Name(0))), token::Plain)
}

let mut res = HashMap::new();
Expand Down Expand Up @@ -75,7 +75,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"RPAREN" => token::CloseDelim(token::Paren),
"SLASH" => token::BinOp(token::Slash),
"COMMA" => token::Comma,
"LIFETIME" => token::Lifetime(ast::Ident { name: Name(0), ctxt: 0 }),
"LIFETIME" => token::Lifetime(ast::Ident::with_empty_ctxt(Name(0))),
"CARET" => token::BinOp(token::Caret),
"TILDE" => token::Tilde,
"IDENT" => id(),
Expand Down Expand Up @@ -208,9 +208,9 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n),
token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content),
count(content)), n),
token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 },
token::Ident(..) => token::Ident(ast::Ident::with_empty_ctxt(nm)),
token::ModName),
token::Lifetime(..) => token::Lifetime(ast::Ident { name: nm, ctxt: 0 }),
token::Lifetime(..) => token::Lifetime(ast::Ident::with_empty_ctxt(nm)),
ref t => t.clone()
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl<'a> CrateReader<'a> {
let span = mk_sp(lo, p.last_span.hi);
p.abort_if_errors();
macros.push(ast::MacroDef {
ident: name.ident(),
ident: ast::Ident::with_empty_ctxt(name),
attrs: attrs,
id: ast::DUMMY_NODE_ID,
span: span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn entry_point_type(item: &Item, depth: usize) -> EntryPointType {
EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr
} else if item.name == "main" {
} else if item.name.as_str() == "main" {
if depth == 1 {
// This is a top-level function so can be 'main'
EntryPointType::MainNamed
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
_ => return false
};
intrinsic && self.tcx.item_name(def_id) == "transmute"
intrinsic && self.tcx.item_name(def_id).as_str() == "transmute"
}

fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>, id: ast::NodeId) {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
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
26 changes: 20 additions & 6 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
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 All @@ -197,7 +211,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
tcx.with_path(id, |path| hir::Path {
global: false,
segments: path.last().map(|elem| hir::PathSegment {
identifier: ast::Ident::new(elem.name()),
identifier: ast::Ident::with_empty_ctxt(elem.name()),
parameters: hir::PathParameters::none(),
}).into_iter().collect(),
span: DUMMY_SP,
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
// When compiling with --test we don't enforce stability on the
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
// name `__test`
if item.span == DUMMY_SP && item.name == "__test" { return }
if item.span == DUMMY_SP && item.name.as_str() == "__test" { return }

check_item(self.tcx, item, true,
&mut |id, sp, stab| self.check(id, sp, stab));
Expand Down
Original file line number Diff line number Diff line change
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
Loading