Skip to content

Commit b2f379c

Browse files
committed
Auto merge of #28535 - petrochenkov:name, r=nrc
Part of #6993 This patch replaces `Ident`s with `Name`s in data structures of HIR and updates the dependent crates to compile and pass `make check`. Some HIR structures still use `Ident`s, namely `PathSegment`, `PatIdent`, `ExprWhile`, `ExprLoop`, `ExprBreak` and `ExprAgain`, they need them for resolve (but `PathSegment` is special, see #6993 (comment)). r? @nrc
2 parents ad82e0a + 0af8e47 commit b2f379c

Some content is hidden

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

56 files changed

+485
-473
lines changed

src/librustc/front/map/blocks.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use self::Code::*;
2626
use front::map::{self, Node};
2727
use syntax::abi;
2828
use rustc_front::hir::{Block, FnDecl};
29-
use syntax::ast::{NodeId, Ident};
29+
use syntax::ast::{Name, NodeId};
3030
use rustc_front::hir as ast;
3131
use syntax::codemap::Span;
3232
use rustc_front::visit::FnKind;
@@ -107,7 +107,7 @@ impl<'a> Code<'a> {
107107
/// These are all the components one can extract from a fn item for
108108
/// use when implementing FnLikeNode operations.
109109
struct ItemFnParts<'a> {
110-
ident: Ident,
110+
name: Name,
111111
decl: &'a ast::FnDecl,
112112
unsafety: ast::Unsafety,
113113
constness: ast::Constness,
@@ -189,21 +189,21 @@ impl<'a> FnLikeNode<'a> {
189189

190190
pub fn kind(self) -> FnKind<'a> {
191191
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
192-
FnKind::ItemFn(p.ident, p.generics, p.unsafety, p.constness, p.abi, p.vis)
192+
FnKind::ItemFn(p.name, p.generics, p.unsafety, p.constness, p.abi, p.vis)
193193
};
194194
let closure = |_: ClosureParts| {
195195
FnKind::Closure
196196
};
197-
let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| {
198-
FnKind::Method(ident, sig, vis)
197+
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _| {
198+
FnKind::Method(name, sig, vis)
199199
};
200200
self.handle(item, method, closure)
201201
}
202202

203203
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
204204
I: FnOnce(ItemFnParts<'a>) -> A,
205205
M: FnOnce(NodeId,
206-
Ident,
206+
Name,
207207
&'a ast::MethodSig,
208208
Option<ast::Visibility>,
209209
&'a ast::Block,
@@ -216,7 +216,7 @@ impl<'a> FnLikeNode<'a> {
216216
ast::ItemFn(ref decl, unsafety, constness, abi, ref generics, ref block) =>
217217
item_fn(ItemFnParts {
218218
id: i.id,
219-
ident: i.ident,
219+
name: i.name,
220220
decl: &**decl,
221221
unsafety: unsafety,
222222
body: &**block,
@@ -230,14 +230,14 @@ impl<'a> FnLikeNode<'a> {
230230
},
231231
map::NodeTraitItem(ti) => match ti.node {
232232
ast::MethodTraitItem(ref sig, Some(ref body)) => {
233-
method(ti.id, ti.ident, sig, None, body, ti.span)
233+
method(ti.id, ti.name, sig, None, body, ti.span)
234234
}
235235
_ => panic!("trait method FnLikeNode that is not fn-like"),
236236
},
237237
map::NodeImplItem(ii) => {
238238
match ii.node {
239239
ast::MethodImplItem(ref sig, ref body) => {
240-
method(ii.id, ii.ident, sig, Some(ii.vis), body, ii.span)
240+
method(ii.id, ii.name, sig, Some(ii.vis), body, ii.span)
241241
}
242242
_ => {
243243
panic!("impl method FnLikeNode that is not fn-like")

src/librustc/front/map/mod.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
1717
use middle::def_id::DefId;
1818

1919
use syntax::abi;
20-
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
20+
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
2121
use syntax::codemap::{Span, Spanned};
2222
use syntax::parse::token;
2323

@@ -475,15 +475,15 @@ impl<'ast> Map<'ast> {
475475
NodeItem(item) => {
476476
match item.node {
477477
ItemMod(_) | ItemForeignMod(_) => {
478-
PathMod(item.ident.name)
478+
PathMod(item.name)
479479
}
480-
_ => PathName(item.ident.name)
480+
_ => PathName(item.name)
481481
}
482482
}
483-
NodeForeignItem(i) => PathName(i.ident.name),
484-
NodeImplItem(ii) => PathName(ii.ident.name),
485-
NodeTraitItem(ti) => PathName(ti.ident.name),
486-
NodeVariant(v) => PathName(v.node.name.name),
483+
NodeForeignItem(i) => PathName(i.name),
484+
NodeImplItem(ii) => PathName(ii.name),
485+
NodeTraitItem(ti) => PathName(ti.name),
486+
NodeVariant(v) => PathName(v.node.name),
487487
NodeLifetime(lt) => PathName(lt.name),
488488
_ => panic!("no path elem for {:?}", node)
489489
}
@@ -499,9 +499,9 @@ impl<'ast> Map<'ast> {
499499
self.with_path(id, |path| path_to_string(path))
500500
}
501501

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

@@ -652,7 +652,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
652652
match map.find(id) {
653653
None => return None,
654654
Some(NodeItem(item)) if item_is_mod(&*item) =>
655-
return Some((id, item.ident.name)),
655+
return Some((id, item.name)),
656656
_ => {}
657657
}
658658
let parent = map.get_parent(id);
@@ -708,11 +708,11 @@ trait Named {
708708

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

711-
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
712-
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
713-
impl Named for Variant_ { fn name(&self) -> Name { self.name.name } }
714-
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
715-
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
711+
impl Named for Item { fn name(&self) -> Name { self.name } }
712+
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
713+
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
714+
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
715+
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
716716

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

10411041
match map.find(id) {
10421042
Some(NodeItem(item)) => {
1043-
let path_str = map.path_to_str_with_ident(id, item.ident);
1043+
let path_str = map.path_to_str_with_name(id, item.name);
10441044
let item_str = match item.node {
10451045
ItemExternCrate(..) => "extern crate",
10461046
ItemUse(..) => "use",
@@ -1059,25 +1059,25 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10591059
format!("{} {}{}", item_str, path_str, id_str)
10601060
}
10611061
Some(NodeForeignItem(item)) => {
1062-
let path_str = map.path_to_str_with_ident(id, item.ident);
1062+
let path_str = map.path_to_str_with_name(id, item.name);
10631063
format!("foreign item {}{}", path_str, id_str)
10641064
}
10651065
Some(NodeImplItem(ii)) => {
10661066
match ii.node {
10671067
ConstImplItem(..) => {
10681068
format!("assoc const {} in {}{}",
1069-
ii.ident,
1069+
ii.name,
10701070
map.path_to_string(id),
10711071
id_str)
10721072
}
10731073
MethodImplItem(..) => {
10741074
format!("method {} in {}{}",
1075-
ii.ident,
1075+
ii.name,
10761076
map.path_to_string(id), id_str)
10771077
}
10781078
TypeImplItem(_) => {
10791079
format!("assoc type {} in {}{}",
1080-
ii.ident,
1080+
ii.name,
10811081
map.path_to_string(id),
10821082
id_str)
10831083
}
@@ -1092,7 +1092,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10921092

10931093
format!("{} {} in {}{}",
10941094
kind,
1095-
ti.ident,
1095+
ti.name,
10961096
map.path_to_string(id),
10971097
id_str)
10981098
}

src/librustc/lint/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,12 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
663663

664664
fn visit_struct_def(&mut self,
665665
s: &hir::StructDef,
666-
ident: ast::Ident,
666+
name: ast::Name,
667667
g: &hir::Generics,
668668
id: ast::NodeId) {
669-
run_lints!(self, check_struct_def, late_passes, s, ident, g, id);
669+
run_lints!(self, check_struct_def, late_passes, s, name, g, id);
670670
hir_visit::walk_struct_def(self, s);
671-
run_lints!(self, check_struct_def_post, late_passes, s, ident, g, id);
671+
run_lints!(self, check_struct_def_post, late_passes, s, name, g, id);
672672
}
673673

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

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

698698
fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {

src/librustc/lint/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait LintPass {
130130
// FIXME: eliminate the duplication with `Visitor`. But this also
131131
// contains a few lint-specific methods with no equivalent in `Visitor`.
132132
pub trait LateLintPass: LintPass {
133-
fn check_ident(&mut self, _: &LateContext, _: Span, _: ast::Ident) { }
133+
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
134134
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
135135
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
136136
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
@@ -150,9 +150,9 @@ pub trait LateLintPass: LintPass {
150150
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
151151
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
152152
fn check_struct_def(&mut self, _: &LateContext,
153-
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
153+
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
154154
fn check_struct_def_post(&mut self, _: &LateContext,
155-
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
155+
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
156156
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
157157
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
158158
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }

src/librustc/metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,17 @@ impl<'a> CrateReader<'a> {
201201
match i.node {
202202
hir::ItemExternCrate(ref path_opt) => {
203203
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
204-
i.ident, path_opt);
204+
i.name, path_opt);
205205
let name = match *path_opt {
206206
Some(name) => {
207207
validate_crate_name(Some(self.sess), &name.as_str(),
208208
Some(i.span));
209209
name.to_string()
210210
}
211-
None => i.ident.to_string(),
211+
None => i.name.to_string(),
212212
};
213213
Some(CrateInfo {
214-
ident: i.ident.to_string(),
214+
ident: i.name.to_string(),
215215
name: name,
216216
id: i.id,
217217
should_link: should_link_hir(i),

0 commit comments

Comments
 (0)