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

Replace Idents with Names in HIR (Part 1) #28535

Merged
merged 8 commits into from
Sep 23, 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
18 changes: 9 additions & 9 deletions src/librustc/front/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use self::Code::*;
use front::map::{self, Node};
use syntax::abi;
use rustc_front::hir::{Block, FnDecl};
use syntax::ast::{NodeId, Ident};
use syntax::ast::{Name, NodeId};
use rustc_front::hir as ast;
use syntax::codemap::Span;
use rustc_front::visit::FnKind;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'a> Code<'a> {
/// These are all the components one can extract from a fn item for
/// use when implementing FnLikeNode operations.
struct ItemFnParts<'a> {
ident: Ident,
name: Name,
decl: &'a ast::FnDecl,
unsafety: ast::Unsafety,
constness: ast::Constness,
Expand Down Expand Up @@ -189,21 +189,21 @@ impl<'a> FnLikeNode<'a> {

pub fn kind(self) -> FnKind<'a> {
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
FnKind::ItemFn(p.ident, p.generics, p.unsafety, p.constness, p.abi, p.vis)
FnKind::ItemFn(p.name, p.generics, p.unsafety, p.constness, p.abi, p.vis)
};
let closure = |_: ClosureParts| {
FnKind::Closure
};
let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(ident, sig, vis)
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(name, sig, vis)
};
self.handle(item, method, closure)
}

fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(NodeId,
Ident,
Name,
&'a ast::MethodSig,
Option<ast::Visibility>,
&'a ast::Block,
Expand All @@ -216,7 +216,7 @@ impl<'a> FnLikeNode<'a> {
ast::ItemFn(ref decl, unsafety, constness, abi, ref generics, ref block) =>
item_fn(ItemFnParts {
id: i.id,
ident: i.ident,
name: i.name,
decl: &**decl,
unsafety: unsafety,
body: &**block,
Expand All @@ -230,14 +230,14 @@ impl<'a> FnLikeNode<'a> {
},
map::NodeTraitItem(ti) => match ti.node {
ast::MethodTraitItem(ref sig, Some(ref body)) => {
method(ti.id, ti.ident, sig, None, body, ti.span)
method(ti.id, ti.name, sig, None, body, ti.span)
}
_ => panic!("trait method FnLikeNode that is not fn-like"),
},
map::NodeImplItem(ii) => {
match ii.node {
ast::MethodImplItem(ref sig, ref body) => {
method(ii.id, ii.ident, sig, Some(ii.vis), body, ii.span)
method(ii.id, ii.name, sig, Some(ii.vis), body, ii.span)
}
_ => {
panic!("impl method FnLikeNode that is not fn-like")
Expand Down
42 changes: 21 additions & 21 deletions src/librustc/front/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
use middle::def_id::DefId;

use syntax::abi;
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::codemap::{Span, Spanned};
use syntax::parse::token;

Expand Down Expand Up @@ -475,15 +475,15 @@ impl<'ast> Map<'ast> {
NodeItem(item) => {
match item.node {
ItemMod(_) | ItemForeignMod(_) => {
PathMod(item.ident.name)
PathMod(item.name)
}
_ => PathName(item.ident.name)
_ => PathName(item.name)
}
}
NodeForeignItem(i) => PathName(i.ident.name),
NodeImplItem(ii) => PathName(ii.ident.name),
NodeTraitItem(ti) => PathName(ti.ident.name),
NodeVariant(v) => PathName(v.node.name.name),
NodeForeignItem(i) => PathName(i.name),
NodeImplItem(ii) => PathName(ii.name),
NodeTraitItem(ti) => PathName(ti.name),
NodeVariant(v) => PathName(v.node.name),
NodeLifetime(lt) => PathName(lt.name),
_ => panic!("no path elem for {:?}", node)
}
Expand All @@ -499,9 +499,9 @@ impl<'ast> Map<'ast> {
self.with_path(id, |path| path_to_string(path))
}

fn path_to_str_with_ident(&self, id: NodeId, i: Ident) -> String {
fn path_to_str_with_name(&self, id: NodeId, name: Name) -> String {
self.with_path(id, |path| {
path_to_string(path.chain(Some(PathName(i.name))))
path_to_string(path.chain(Some(PathName(name))))
})
}

Expand Down Expand Up @@ -652,7 +652,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
match map.find(id) {
None => return None,
Some(NodeItem(item)) if item_is_mod(&*item) =>
return Some((id, item.ident.name)),
return Some((id, item.name)),
_ => {}
}
let parent = map.get_parent(id);
Expand Down Expand Up @@ -708,11 +708,11 @@ trait Named {

impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }

impl Named for Item { fn name(&self) -> Name { self.ident.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
impl Named for Variant_ { fn name(&self) -> Name { self.name.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
impl Named for Item { fn name(&self) -> Name { self.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.name } }

pub trait FoldOps {
fn new_id(&self, id: NodeId) -> NodeId {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {

match map.find(id) {
Some(NodeItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
let path_str = map.path_to_str_with_name(id, item.name);
let item_str = match item.node {
ItemExternCrate(..) => "extern crate",
ItemUse(..) => "use",
Expand All @@ -1059,25 +1059,25 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
format!("{} {}{}", item_str, path_str, id_str)
}
Some(NodeForeignItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
let path_str = map.path_to_str_with_name(id, item.name);
format!("foreign item {}{}", path_str, id_str)
}
Some(NodeImplItem(ii)) => {
match ii.node {
ConstImplItem(..) => {
format!("assoc const {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id),
id_str)
}
MethodImplItem(..) => {
format!("method {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id), id_str)
}
TypeImplItem(_) => {
format!("assoc type {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id),
id_str)
}
Expand All @@ -1092,7 +1092,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {

format!("{} {} in {}{}",
kind,
ti.ident,
ti.name,
map.path_to_string(id),
id_str)
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {

fn visit_struct_def(&mut self,
s: &hir::StructDef,
ident: ast::Ident,
name: ast::Name,
g: &hir::Generics,
id: ast::NodeId) {
run_lints!(self, check_struct_def, late_passes, s, ident, g, id);
run_lints!(self, check_struct_def, late_passes, s, name, g, id);
hir_visit::walk_struct_def(self, s);
run_lints!(self, check_struct_def_post, late_passes, s, ident, g, id);
run_lints!(self, check_struct_def_post, late_passes, s, name, g, id);
}

fn visit_struct_field(&mut self, s: &hir::StructField) {
Expand All @@ -691,8 +691,8 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
hir_visit::walk_ty(self, t);
}

fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
run_lints!(self, check_ident, late_passes, sp, id);
fn visit_name(&mut self, sp: Span, name: ast::Name) {
run_lints!(self, check_name, late_passes, sp, name);
}

fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub trait LintPass {
// FIXME: eliminate the duplication with `Visitor`. But this also
// contains a few lint-specific methods with no equivalent in `Visitor`.
pub trait LateLintPass: LintPass {
fn check_ident(&mut self, _: &LateContext, _: Span, _: ast::Ident) { }
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
Expand All @@ -150,9 +150,9 @@ pub trait LateLintPass: LintPass {
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
fn check_struct_def(&mut self, _: &LateContext,
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &LateContext,
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,17 @@ impl<'a> CrateReader<'a> {
match i.node {
hir::ItemExternCrate(ref path_opt) => {
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
i.ident, path_opt);
i.name, path_opt);
let name = match *path_opt {
Some(name) => {
validate_crate_name(Some(self.sess), &name.as_str(),
Some(i.span));
name.to_string()
}
None => i.ident.to_string(),
None => i.name.to_string(),
};
Some(CrateInfo {
ident: i.ident.to_string(),
ident: i.name.to_string(),
name: name,
id: i.id,
should_link: should_link_hir(i),
Expand Down
Loading