Skip to content

Commit 1b150c4

Browse files
author
Alexander Regueiro
committed
Store Ident rather than just Name in HIR types Item and ForeignItem.
1 parent 79d8a0f commit 1b150c4

File tree

38 files changed

+221
-157
lines changed

38 files changed

+221
-157
lines changed

src/libproc_macro/bridge/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Serialization for client<->server communication.
1+
//! Serialization for client-server communication.
22
33
use std::any::Any;
44
use std::char;

src/librustc/hir/intravisit.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
454454

455455
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
456456
visitor.visit_vis(&item.vis);
457-
visitor.visit_name(item.span, item.name);
457+
visitor.visit_ident(item.ident);
458458
match item.node {
459459
ItemKind::ExternCrate(orig_name) => {
460460
visitor.visit_id(item.id);
@@ -472,7 +472,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
472472
visitor.visit_nested_body(body);
473473
}
474474
ItemKind::Fn(ref declaration, header, ref generics, body_id) => {
475-
visitor.visit_fn(FnKind::ItemFn(item.name,
475+
visitor.visit_fn(FnKind::ItemFn(item.ident.name,
476476
generics,
477477
header,
478478
&item.vis,
@@ -528,7 +528,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
528528
ItemKind::Union(ref struct_definition, ref generics) => {
529529
visitor.visit_generics(generics);
530530
visitor.visit_id(item.id);
531-
visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span);
531+
visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.id,
532+
item.span);
532533
}
533534
ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => {
534535
visitor.visit_id(item.id);
@@ -569,9 +570,9 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
569570
variant: &'v Variant,
570571
generics: &'v Generics,
571572
parent_item_id: NodeId) {
572-
visitor.visit_name(variant.span, variant.node.name);
573+
visitor.visit_ident(variant.node.ident);
573574
visitor.visit_variant_data(&variant.node.data,
574-
variant.node.name,
575+
variant.node.ident.name,
575576
generics,
576577
parent_item_id,
577578
variant.span);
@@ -720,7 +721,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
720721
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) {
721722
visitor.visit_id(foreign_item.id);
722723
visitor.visit_vis(&foreign_item.vis);
723-
visitor.visit_name(foreign_item.span, foreign_item.name);
724+
visitor.visit_ident(foreign_item.ident);
724725

725726
match foreign_item.node {
726727
ForeignItemKind::Fn(ref function_declaration, ref param_names, ref generics) => {

src/librustc/hir/lowering.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ impl<'a> LoweringContext<'a> {
13601360
let exist_ty_item = hir::Item {
13611361
id: exist_ty_id.node_id,
13621362
hir_id: exist_ty_id.hir_id,
1363-
name: keywords::Invalid.name(),
1363+
ident: keywords::Invalid.ident(),
13641364
attrs: Default::default(),
13651365
node: exist_ty_item_kind,
13661366
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
@@ -1563,7 +1563,7 @@ impl<'a> LoweringContext<'a> {
15631563
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
15641564
Spanned {
15651565
node: hir::VariantKind {
1566-
name: v.node.ident.name,
1566+
ident: v.node.ident,
15671567
attrs: self.lower_attrs(&v.node.attrs),
15681568
data: self.lower_variant_data(&v.node.data),
15691569
disr_expr: v.node.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
@@ -2738,7 +2738,7 @@ impl<'a> LoweringContext<'a> {
27382738
fn lower_item_kind(
27392739
&mut self,
27402740
id: NodeId,
2741-
name: &mut Name,
2741+
ident: &mut Ident,
27422742
attrs: &hir::HirVec<Attribute>,
27432743
vis: &mut hir::Visibility,
27442744
i: &ItemKind,
@@ -2752,7 +2752,7 @@ impl<'a> LoweringContext<'a> {
27522752
span: use_tree.span,
27532753
};
27542754

2755-
self.lower_use_tree(use_tree, &prefix, id, vis, name, attrs)
2755+
self.lower_use_tree(use_tree, &prefix, id, vis, ident, attrs)
27562756
}
27572757
ItemKind::Static(ref t, m, ref e) => {
27582758
let value = self.lower_body(None, |this| this.lower_expr(e));
@@ -2944,7 +2944,7 @@ impl<'a> LoweringContext<'a> {
29442944
prefix: &Path,
29452945
id: NodeId,
29462946
vis: &mut hir::Visibility,
2947-
name: &mut Name,
2947+
ident: &mut Ident,
29482948
attrs: &hir::HirVec<Attribute>,
29492949
) -> hir::ItemKind {
29502950
debug!("lower_use_tree(tree={:?})", tree);
@@ -2960,28 +2960,28 @@ impl<'a> LoweringContext<'a> {
29602960

29612961
match tree.kind {
29622962
UseTreeKind::Simple(rename, id1, id2) => {
2963-
*name = tree.ident().name;
2963+
*ident = tree.ident();
29642964

2965-
// First apply the prefix to the path
2965+
// First, apply the prefix to the path.
29662966
let mut path = Path {
29672967
segments,
29682968
span: path.span,
29692969
};
29702970

2971-
// Correctly resolve `self` imports
2971+
// Correctly resolve `self` imports.
29722972
if path.segments.len() > 1
29732973
&& path.segments.last().unwrap().ident.name == keywords::SelfLower.name()
29742974
{
29752975
let _ = path.segments.pop();
29762976
if rename.is_none() {
2977-
*name = path.segments.last().unwrap().ident.name;
2977+
*ident = path.segments.last().unwrap().ident;
29782978
}
29792979
}
29802980

29812981
let parent_def_index = self.current_hir_id_owner.last().unwrap().0;
29822982
let mut defs = self.expect_full_def_from_use(id);
2983-
// we want to return *something* from this function, so hang onto the first item
2984-
// for later
2983+
// We want to return *something* from this function, so hold onto the first item
2984+
// for later.
29852985
let ret_def = defs.next().unwrap_or(Def::Err);
29862986

29872987
// Here, we are looping over namespaces, if they exist for the definition
@@ -2991,7 +2991,7 @@ impl<'a> LoweringContext<'a> {
29912991
// two imports.
29922992
for (def, &new_node_id) in defs.zip([id1, id2].iter()) {
29932993
let vis = vis.clone();
2994-
let name = name.clone();
2994+
let ident = ident.clone();
29952995
let mut path = path.clone();
29962996
for seg in &mut path.segments {
29972997
seg.id = self.sess.next_node_id();
@@ -3032,7 +3032,7 @@ impl<'a> LoweringContext<'a> {
30323032
hir::Item {
30333033
id: new_id.node_id,
30343034
hir_id: new_id.hir_id,
3035-
name: name,
3035+
ident,
30363036
attrs: attrs.clone(),
30373037
node: item,
30383038
vis,
@@ -3058,8 +3058,8 @@ impl<'a> LoweringContext<'a> {
30583058
hir::ItemKind::Use(path, hir::UseKind::Glob)
30593059
}
30603060
UseTreeKind::Nested(ref trees) => {
3061-
// Nested imports are desugared into simple
3062-
// imports. So if we start with
3061+
// Nested imports are desugared into simple imports.
3062+
// So, if we start with
30633063
//
30643064
// ```
30653065
// pub(x) use foo::{a, b};
@@ -3080,14 +3080,14 @@ impl<'a> LoweringContext<'a> {
30803080
// `self.items`. However, the structure of this
30813081
// function also requires us to return one item, and
30823082
// for that we return the `{}` import (called the
3083-
// "`ListStem`").
3083+
// `ListStem`).
30843084

30853085
let prefix = Path {
30863086
segments,
30873087
span: prefix.span.to(path.span),
30883088
};
30893089

3090-
// Add all the nested PathListItems to the HIR.
3090+
// Add all the nested `PathListItem`s to the HIR.
30913091
for &(ref use_tree, id) in trees {
30923092
self.allocate_hir_id_counter(id, &use_tree);
30933093

@@ -3097,10 +3097,10 @@ impl<'a> LoweringContext<'a> {
30973097
} = self.lower_node_id(id);
30983098

30993099
let mut vis = vis.clone();
3100-
let mut name = name.clone();
3100+
let mut ident = ident.clone();
31013101
let mut prefix = prefix.clone();
31023102

3103-
// Give the segments new ids since they are being cloned.
3103+
// Give the segments new node-ids since they are being cloned.
31043104
for seg in &mut prefix.segments {
31053105
seg.id = self.sess.next_node_id();
31063106
}
@@ -3115,7 +3115,7 @@ impl<'a> LoweringContext<'a> {
31153115
&prefix,
31163116
new_id,
31173117
&mut vis,
3118-
&mut name,
3118+
&mut ident,
31193119
attrs);
31203120

31213121
let vis_kind = match vis.node {
@@ -3139,7 +3139,7 @@ impl<'a> LoweringContext<'a> {
31393139
hir::Item {
31403140
id: new_id,
31413141
hir_id: new_hir_id,
3142-
name,
3142+
ident,
31433143
attrs: attrs.clone(),
31443144
node: item,
31453145
vis,
@@ -3166,7 +3166,7 @@ impl<'a> LoweringContext<'a> {
31663166
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
31673167
}
31683168
hir::VisibilityKind::Restricted { .. } => {
3169-
// do nothing here, as described in the comment on the match
3169+
// Do nothing here, as described in the comment on the match.
31703170
}
31713171
}
31723172

@@ -3414,15 +3414,15 @@ impl<'a> LoweringContext<'a> {
34143414
}
34153415

34163416
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
3417-
let mut name = i.ident.name;
3417+
let mut ident = i.ident;
34183418
let mut vis = self.lower_visibility(&i.vis, None);
34193419
let attrs = self.lower_attrs(&i.attrs);
34203420
if let ItemKind::MacroDef(ref def) = i.node {
34213421
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
34223422
attr::contains_name(&i.attrs, "rustc_doc_only_macro") {
34233423
let body = self.lower_token_stream(def.stream());
34243424
self.exported_macros.push(hir::MacroDef {
3425-
name,
3425+
name: ident.name,
34263426
vis,
34273427
attrs,
34283428
id: i.id,
@@ -3434,14 +3434,14 @@ impl<'a> LoweringContext<'a> {
34343434
return None;
34353435
}
34363436

3437-
let node = self.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node);
3437+
let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node);
34383438

34393439
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
34403440

34413441
Some(hir::Item {
34423442
id: node_id,
34433443
hir_id,
3444-
name,
3444+
ident,
34453445
attrs,
34463446
node,
34473447
vis,
@@ -3454,7 +3454,7 @@ impl<'a> LoweringContext<'a> {
34543454
let def_id = self.resolver.definitions().local_def_id(node_id);
34553455
hir::ForeignItem {
34563456
id: node_id,
3457-
name: i.ident.name,
3457+
ident: i.ident,
34583458
attrs: self.lower_attrs(&i.attrs),
34593459
node: match i.node {
34603460
ForeignItemKind::Fn(ref fdec, ref generics) => {

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'a> FnLikeNode<'a> {
228228
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
229229
item_fn(ItemFnParts {
230230
id: i.id,
231-
name: i.name,
231+
name: i.ident.name,
232232
decl: &decl,
233233
body: block,
234234
vis: &i.vis,

src/librustc/hir/map/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,11 @@ impl<'hir> Map<'hir> {
813813
/// Returns the name associated with the given NodeId's AST.
814814
pub fn name(&self, id: NodeId) -> Name {
815815
match self.get(id) {
816-
Node::Item(i) => i.name,
817-
Node::ForeignItem(i) => i.name,
816+
Node::Item(i) => i.ident.name,
817+
Node::ForeignItem(fi) => fi.ident.name,
818818
Node::ImplItem(ii) => ii.ident.name,
819819
Node::TraitItem(ti) => ti.ident.name,
820-
Node::Variant(v) => v.node.name,
820+
Node::Variant(v) => v.node.ident.name,
821821
Node::Field(f) => f.ident.name,
822822
Node::Lifetime(lt) => lt.name.ident().name,
823823
Node::GenericParam(param) => param.name.ident().name,
@@ -953,7 +953,7 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> {
953953
loop {
954954
if let Node::Item(item) = map.find(id)? {
955955
if item_is_mod(&item) {
956-
return Some((id, item.name))
956+
return Some((id, item.ident.name))
957957
}
958958
}
959959
let parent = map.get_parent(id);
@@ -1009,9 +1009,9 @@ trait Named {
10091009

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

1012-
impl Named for Item { fn name(&self) -> Name { self.name } }
1013-
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
1014-
impl Named for VariantKind { fn name(&self) -> Name { self.name } }
1012+
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
1013+
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
1014+
impl Named for VariantKind { fn name(&self) -> Name { self.ident.name } }
10151015
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
10161016
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
10171017
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
@@ -1194,7 +1194,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
11941194
}
11951195
Some(Node::Variant(ref variant)) => {
11961196
format!("variant {} in {}{}",
1197-
variant.node.name,
1197+
variant.node.ident,
11981198
path_str(), id_str)
11991199
}
12001200
Some(Node::Field(ref field)) => {

src/librustc/hir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ pub struct EnumDef {
20152015

20162016
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
20172017
pub struct VariantKind {
2018-
pub name: Name,
2018+
pub ident: Ident,
20192019
pub attrs: HirVec<Attribute>,
20202020
pub data: VariantData,
20212021
/// Explicit discriminant, e.g., `Foo = 1`
@@ -2176,7 +2176,7 @@ pub struct ItemId {
21762176
/// The name might be a dummy name in case of anonymous items
21772177
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
21782178
pub struct Item {
2179-
pub name: Name,
2179+
pub ident: Ident,
21802180
pub id: NodeId,
21812181
pub hir_id: HirId,
21822182
pub attrs: HirVec<Attribute>,
@@ -2331,7 +2331,7 @@ pub enum AssociatedItemKind {
23312331

23322332
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
23332333
pub struct ForeignItem {
2334-
pub name: Name,
2334+
pub ident: Ident,
23352335
pub attrs: HirVec<Attribute>,
23362336
pub node: ForeignItemKind,
23372337
pub id: NodeId,

0 commit comments

Comments
 (0)