Skip to content

Commit 0dcd858

Browse files
committed
Use Idents for associated item definitions in HIR
Remove emulation of hygiene with gensyms
1 parent 9cf1847 commit 0dcd858

File tree

45 files changed

+176
-207
lines changed

Some content is hidden

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

45 files changed

+176
-207
lines changed

src/librustc/hir/intravisit.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum FnKind<'a> {
5858
ItemFn(Name, &'a Generics, Unsafety, Constness, Abi, &'a Visibility, &'a [Attribute]),
5959

6060
/// fn foo(&self)
61-
Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
61+
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
6262

6363
/// |x, y| {}
6464
Closure(&'a [Attribute]),
@@ -827,7 +827,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
827827
}
828828

829829
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) {
830-
visitor.visit_name(trait_item.span, trait_item.name);
830+
visitor.visit_ident(trait_item.ident);
831831
walk_list!(visitor, visit_attribute, &trait_item.attrs);
832832
visitor.visit_generics(&trait_item.generics);
833833
match trait_item.node {
@@ -844,7 +844,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
844844
}
845845
}
846846
TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => {
847-
visitor.visit_fn(FnKind::Method(trait_item.name,
847+
visitor.visit_fn(FnKind::Method(trait_item.ident,
848848
sig,
849849
None,
850850
&trait_item.attrs),
@@ -863,9 +863,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
863863

864864
pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
865865
// NB: Deliberately force a compilation error if/when new fields are added.
866-
let TraitItemRef { id, name, ref kind, span, ref defaultness } = *trait_item_ref;
866+
let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
867867
visitor.visit_nested_trait_item(id);
868-
visitor.visit_name(span, name);
868+
visitor.visit_ident(ident);
869869
visitor.visit_associated_item_kind(kind);
870870
visitor.visit_defaultness(defaultness);
871871
}
@@ -875,16 +875,16 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
875875
let ImplItem {
876876
id: _,
877877
hir_id: _,
878-
name,
878+
ident,
879879
ref vis,
880880
ref defaultness,
881881
ref attrs,
882882
ref generics,
883883
ref node,
884-
span
884+
span: _,
885885
} = *impl_item;
886886

887-
visitor.visit_name(span, name);
887+
visitor.visit_ident(ident);
888888
visitor.visit_vis(vis);
889889
visitor.visit_defaultness(defaultness);
890890
walk_list!(visitor, visit_attribute, attrs);
@@ -896,7 +896,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
896896
visitor.visit_nested_body(body);
897897
}
898898
ImplItemKind::Method(ref sig, body_id) => {
899-
visitor.visit_fn(FnKind::Method(impl_item.name,
899+
visitor.visit_fn(FnKind::Method(impl_item.ident,
900900
sig,
901901
Some(&impl_item.vis),
902902
&impl_item.attrs),
@@ -914,9 +914,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
914914

915915
pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) {
916916
// NB: Deliberately force a compilation error if/when new fields are added.
917-
let ImplItemRef { id, name, ref kind, span, ref vis, ref defaultness } = *impl_item_ref;
917+
let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref;
918918
visitor.visit_nested_impl_item(id);
919-
visitor.visit_name(span, name);
919+
visitor.visit_ident(ident);
920920
visitor.visit_associated_item_kind(kind);
921921
visitor.visit_vis(vis);
922922
visitor.visit_defaultness(defaultness);

src/librustc/hir/lowering.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use middle::cstore::CrateStore;
5151
use rustc_data_structures::indexed_vec::IndexVec;
5252
use session::Session;
5353
use util::common::FN_OUTPUT_NAME;
54-
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
54+
use util::nodemap::{DefIdMap, NodeMap};
5555

5656
use std::collections::{BTreeMap, HashSet};
5757
use std::fmt::Debug;
@@ -83,7 +83,6 @@ pub struct LoweringContext<'a> {
8383
cstore: &'a CrateStore,
8484

8585
resolver: &'a mut Resolver,
86-
name_map: FxHashMap<Ident, Name>,
8786

8887
/// The items being lowered are collected here.
8988
items: BTreeMap<NodeId, hir::Item>,
@@ -202,7 +201,6 @@ pub fn lower_crate(
202201
sess,
203202
cstore,
204203
resolver,
205-
name_map: FxHashMap(),
206204
items: BTreeMap::new(),
207205
trait_items: BTreeMap::new(),
208206
impl_items: BTreeMap::new(),
@@ -901,16 +899,6 @@ impl<'a> LoweringContext<'a> {
901899
}
902900
}
903901

904-
fn lower_ident(&mut self, ident: Ident) -> Name {
905-
let ident = ident.modern();
906-
if ident.span.ctxt() == SyntaxContext::empty() {
907-
return ident.name;
908-
}
909-
*self.name_map
910-
.entry(ident)
911-
.or_insert_with(|| Symbol::from_ident(ident))
912-
}
913-
914902
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
915903
label.map(|label| hir::Label {
916904
ident: label.ident,
@@ -2530,7 +2518,7 @@ impl<'a> LoweringContext<'a> {
25302518
hir::TraitItem {
25312519
id: node_id,
25322520
hir_id,
2533-
name: self.lower_ident(i.ident),
2521+
ident: i.ident,
25342522
attrs: self.lower_attrs(&i.attrs),
25352523
generics,
25362524
node,
@@ -2556,7 +2544,7 @@ impl<'a> LoweringContext<'a> {
25562544
};
25572545
hir::TraitItemRef {
25582546
id: hir::TraitItemId { node_id: i.id },
2559-
name: self.lower_ident(i.ident),
2547+
ident: i.ident,
25602548
span: i.span,
25612549
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
25622550
kind,
@@ -2611,7 +2599,7 @@ impl<'a> LoweringContext<'a> {
26112599
hir::ImplItem {
26122600
id: node_id,
26132601
hir_id,
2614-
name: self.lower_ident(i.ident),
2602+
ident: i.ident,
26152603
attrs: self.lower_attrs(&i.attrs),
26162604
generics,
26172605
vis: self.lower_visibility(&i.vis, None),
@@ -2626,7 +2614,7 @@ impl<'a> LoweringContext<'a> {
26262614
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
26272615
hir::ImplItemRef {
26282616
id: hir::ImplItemId { node_id: i.id },
2629-
name: self.lower_ident(i.ident),
2617+
ident: i.ident,
26302618
span: i.span,
26312619
vis: self.lower_visibility(&i.vis, Some(i.id)),
26322620
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),

src/librustc/hir/map/blocks.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use hir::map::{self, Node};
2626
use hir::{Expr, FnDecl};
2727
use hir::intravisit::FnKind;
2828
use rustc_target::spec::abi;
29-
use syntax::ast::{Attribute, Name, NodeId};
29+
use syntax::ast::{Attribute, Ident, Name, NodeId};
3030
use syntax_pos::Span;
3131

3232
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
@@ -212,16 +212,16 @@ impl<'a> FnLikeNode<'a> {
212212
let closure = |c: ClosureParts<'a>| {
213213
FnKind::Closure(c.attrs)
214214
};
215-
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _, attrs| {
216-
FnKind::Method(name, sig, vis, attrs)
215+
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
216+
FnKind::Method(ident, sig, vis, attrs)
217217
};
218218
self.handle(item, method, closure)
219219
}
220220

221221
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
222222
I: FnOnce(ItemFnParts<'a>) -> A,
223223
M: FnOnce(NodeId,
224-
Name,
224+
Ident,
225225
&'a ast::MethodSig,
226226
Option<&'a ast::Visibility>,
227227
ast::BodyId,
@@ -250,14 +250,14 @@ impl<'a> FnLikeNode<'a> {
250250
},
251251
map::NodeTraitItem(ti) => match ti.node {
252252
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
253-
method(ti.id, ti.name, sig, None, body, ti.span, &ti.attrs)
253+
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
254254
}
255255
_ => bug!("trait method FnLikeNode that is not fn-like"),
256256
},
257257
map::NodeImplItem(ii) => {
258258
match ii.node {
259259
ast::ImplItemKind::Method(ref sig, body) => {
260-
method(ii.id, ii.name, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
260+
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
261261
}
262262
_ => {
263263
bug!("impl method FnLikeNode that is not fn-like")

src/librustc/hir/map/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
502502
// map the actual nodes, not the duplicate ones in the *Ref.
503503
let TraitItemRef {
504504
id,
505-
name: _,
505+
ident: _,
506506
kind: _,
507507
span: _,
508508
defaultness: _,
@@ -516,7 +516,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
516516
// map the actual nodes, not the duplicate ones in the *Ref.
517517
let ImplItemRef {
518518
id,
519-
name: _,
519+
ident: _,
520520
kind: _,
521521
span: _,
522522
vis: _,

src/librustc/hir/map/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ impl<'hir> Map<'hir> {
906906
match self.get(id) {
907907
NodeItem(i) => i.name,
908908
NodeForeignItem(i) => i.name,
909-
NodeImplItem(ii) => ii.name,
910-
NodeTraitItem(ti) => ti.name,
909+
NodeImplItem(ii) => ii.ident.name,
910+
NodeTraitItem(ti) => ti.ident.name,
911911
NodeVariant(v) => v.node.name,
912912
NodeField(f) => f.ident.name,
913913
NodeLifetime(lt) => lt.name.ident().name,
@@ -1106,8 +1106,8 @@ impl Named for Item { fn name(&self) -> Name { self.name } }
11061106
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
11071107
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
11081108
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
1109-
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
1110-
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
1109+
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
1110+
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
11111111

11121112

11131113
pub fn map_crate<'hir>(sess: &::session::Session,
@@ -1265,13 +1265,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
12651265
Some(NodeImplItem(ii)) => {
12661266
match ii.node {
12671267
ImplItemKind::Const(..) => {
1268-
format!("assoc const {} in {}{}", ii.name, path_str(), id_str)
1268+
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
12691269
}
12701270
ImplItemKind::Method(..) => {
1271-
format!("method {} in {}{}", ii.name, path_str(), id_str)
1271+
format!("method {} in {}{}", ii.ident, path_str(), id_str)
12721272
}
12731273
ImplItemKind::Type(_) => {
1274-
format!("assoc type {} in {}{}", ii.name, path_str(), id_str)
1274+
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
12751275
}
12761276
}
12771277
}
@@ -1282,7 +1282,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
12821282
TraitItemKind::Type(..) => "assoc type",
12831283
};
12841284

1285-
format!("{} {} in {}{}", kind, ti.name, path_str(), id_str)
1285+
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
12861286
}
12871287
Some(NodeVariant(ref variant)) => {
12881288
format!("variant {} in {}{}",

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ pub struct TraitItemId {
15891589
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
15901590
pub struct TraitItem {
15911591
pub id: NodeId,
1592-
pub name: Name,
1592+
pub ident: Ident,
15931593
pub hir_id: HirId,
15941594
pub attrs: HirVec<Attribute>,
15951595
pub generics: Generics,
@@ -1632,7 +1632,7 @@ pub struct ImplItemId {
16321632
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
16331633
pub struct ImplItem {
16341634
pub id: NodeId,
1635-
pub name: Name,
1635+
pub ident: Ident,
16361636
pub hir_id: HirId,
16371637
pub vis: Visibility,
16381638
pub defaultness: Defaultness,
@@ -2175,7 +2175,7 @@ impl Item_ {
21752175
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
21762176
pub struct TraitItemRef {
21772177
pub id: TraitItemId,
2178-
pub name: Name,
2178+
pub ident: Ident,
21792179
pub kind: AssociatedItemKind,
21802180
pub span: Span,
21812181
pub defaultness: Defaultness,
@@ -2190,7 +2190,7 @@ pub struct TraitItemRef {
21902190
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
21912191
pub struct ImplItemRef {
21922192
pub id: ImplItemId,
2193-
pub name: Name,
2193+
pub ident: Ident,
21942194
pub kind: AssociatedItemKind,
21952195
pub span: Span,
21962196
pub vis: Visibility,

0 commit comments

Comments
 (0)