Skip to content

Commit f0622df

Browse files
committed
Use Idents for associated item definitions in HIR
Remove emulation of hygiene with gensyms
1 parent c6ca1e4 commit f0622df

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
@@ -57,7 +57,7 @@ pub enum FnKind<'a> {
5757
ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
5858

5959
/// fn foo(&self)
60-
Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
60+
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
6161

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

825825
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) {
826-
visitor.visit_name(trait_item.span, trait_item.name);
826+
visitor.visit_ident(trait_item.ident);
827827
walk_list!(visitor, visit_attribute, &trait_item.attrs);
828828
visitor.visit_generics(&trait_item.generics);
829829
match trait_item.node {
@@ -840,7 +840,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
840840
}
841841
}
842842
TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => {
843-
visitor.visit_fn(FnKind::Method(trait_item.name,
843+
visitor.visit_fn(FnKind::Method(trait_item.ident,
844844
sig,
845845
None,
846846
&trait_item.attrs),
@@ -859,9 +859,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
859859

860860
pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) {
861861
// NB: Deliberately force a compilation error if/when new fields are added.
862-
let TraitItemRef { id, name, ref kind, span, ref defaultness } = *trait_item_ref;
862+
let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref;
863863
visitor.visit_nested_trait_item(id);
864-
visitor.visit_name(span, name);
864+
visitor.visit_ident(ident);
865865
visitor.visit_associated_item_kind(kind);
866866
visitor.visit_defaultness(defaultness);
867867
}
@@ -871,16 +871,16 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
871871
let ImplItem {
872872
id: _,
873873
hir_id: _,
874-
name,
874+
ident,
875875
ref vis,
876876
ref defaultness,
877877
ref attrs,
878878
ref generics,
879879
ref node,
880-
span
880+
span: _,
881881
} = *impl_item;
882882

883-
visitor.visit_name(span, name);
883+
visitor.visit_ident(ident);
884884
visitor.visit_vis(vis);
885885
visitor.visit_defaultness(defaultness);
886886
walk_list!(visitor, visit_attribute, attrs);
@@ -892,7 +892,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
892892
visitor.visit_nested_body(body);
893893
}
894894
ImplItemKind::Method(ref sig, body_id) => {
895-
visitor.visit_fn(FnKind::Method(impl_item.name,
895+
visitor.visit_fn(FnKind::Method(impl_item.ident,
896896
sig,
897897
Some(&impl_item.vis),
898898
&impl_item.attrs),
@@ -910,9 +910,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
910910

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

src/librustc/hir/lowering.rs

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

5757
use std::collections::{BTreeMap, HashSet};
5858
use std::fmt::Debug;
@@ -85,7 +85,6 @@ pub struct LoweringContext<'a> {
8585
cstore: &'a CrateStore,
8686

8787
resolver: &'a mut Resolver,
88-
name_map: FxHashMap<Ident, Name>,
8988

9089
/// The items being lowered are collected here.
9190
items: BTreeMap<NodeId, hir::Item>,
@@ -210,7 +209,6 @@ pub fn lower_crate(
210209
sess,
211210
cstore,
212211
resolver,
213-
name_map: FxHashMap(),
214212
items: BTreeMap::new(),
215213
trait_items: BTreeMap::new(),
216214
impl_items: BTreeMap::new(),
@@ -957,16 +955,6 @@ impl<'a> LoweringContext<'a> {
957955
}
958956
}
959957

960-
fn lower_ident(&mut self, ident: Ident) -> Name {
961-
let ident = ident.modern();
962-
if ident.span.ctxt() == SyntaxContext::empty() {
963-
return ident.name;
964-
}
965-
*self.name_map
966-
.entry(ident)
967-
.or_insert_with(|| Symbol::from_ident(ident))
968-
}
969-
970958
fn lower_label(&mut self, label: Option<Label>) -> Option<hir::Label> {
971959
label.map(|label| hir::Label {
972960
ident: label.ident,
@@ -2962,7 +2950,7 @@ impl<'a> LoweringContext<'a> {
29622950
hir::TraitItem {
29632951
id: node_id,
29642952
hir_id,
2965-
name: self.lower_ident(i.ident),
2953+
ident: i.ident,
29662954
attrs: self.lower_attrs(&i.attrs),
29672955
generics,
29682956
node,
@@ -2988,7 +2976,7 @@ impl<'a> LoweringContext<'a> {
29882976
};
29892977
hir::TraitItemRef {
29902978
id: hir::TraitItemId { node_id: i.id },
2991-
name: self.lower_ident(i.ident),
2979+
ident: i.ident,
29922980
span: i.span,
29932981
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
29942982
kind,
@@ -3054,7 +3042,7 @@ impl<'a> LoweringContext<'a> {
30543042
hir::ImplItem {
30553043
id: node_id,
30563044
hir_id,
3057-
name: self.lower_ident(i.ident),
3045+
ident: i.ident,
30583046
attrs: self.lower_attrs(&i.attrs),
30593047
generics,
30603048
vis: self.lower_visibility(&i.vis, None),
@@ -3069,7 +3057,7 @@ impl<'a> LoweringContext<'a> {
30693057
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
30703058
hir::ImplItemRef {
30713059
id: hir::ImplItemId { node_id: i.id },
3072-
name: self.lower_ident(i.ident),
3060+
ident: i.ident,
30733061
span: i.span,
30743062
vis: self.lower_visibility(&i.vis, Some(i.id)),
30753063
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),

src/librustc/hir/map/blocks.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hir as ast;
2525
use hir::map::{self, Node};
2626
use hir::{Expr, FnDecl};
2727
use hir::intravisit::FnKind;
28-
use syntax::ast::{Attribute, Name, NodeId};
28+
use syntax::ast::{Attribute, Ident, Name, NodeId};
2929
use syntax_pos::Span;
3030

3131
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
@@ -209,16 +209,16 @@ impl<'a> FnLikeNode<'a> {
209209
let closure = |c: ClosureParts<'a>| {
210210
FnKind::Closure(c.attrs)
211211
};
212-
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _, attrs| {
213-
FnKind::Method(name, sig, vis, attrs)
212+
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
213+
FnKind::Method(ident, sig, vis, attrs)
214214
};
215215
self.handle(item, method, closure)
216216
}
217217

218218
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
219219
I: FnOnce(ItemFnParts<'a>) -> A,
220220
M: FnOnce(NodeId,
221-
Name,
221+
Ident,
222222
&'a ast::MethodSig,
223223
Option<&'a ast::Visibility>,
224224
ast::BodyId,
@@ -245,14 +245,14 @@ impl<'a> FnLikeNode<'a> {
245245
},
246246
map::NodeTraitItem(ti) => match ti.node {
247247
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
248-
method(ti.id, ti.name, sig, None, body, ti.span, &ti.attrs)
248+
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
249249
}
250250
_ => bug!("trait method FnLikeNode that is not fn-like"),
251251
},
252252
map::NodeImplItem(ii) => {
253253
match ii.node {
254254
ast::ImplItemKind::Method(ref sig, body) => {
255-
method(ii.id, ii.name, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
255+
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
256256
}
257257
_ => {
258258
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
@@ -495,7 +495,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
495495
// map the actual nodes, not the duplicate ones in the *Ref.
496496
let TraitItemRef {
497497
id,
498-
name: _,
498+
ident: _,
499499
kind: _,
500500
span: _,
501501
defaultness: _,
@@ -509,7 +509,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
509509
// map the actual nodes, not the duplicate ones in the *Ref.
510510
let ImplItemRef {
511511
id,
512-
name: _,
512+
ident: _,
513513
kind: _,
514514
span: _,
515515
vis: _,

src/librustc/hir/map/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ impl<'hir> Map<'hir> {
949949
match self.get(id) {
950950
NodeItem(i) => i.name,
951951
NodeForeignItem(i) => i.name,
952-
NodeImplItem(ii) => ii.name,
953-
NodeTraitItem(ti) => ti.name,
952+
NodeImplItem(ii) => ii.ident.name,
953+
NodeTraitItem(ti) => ti.ident.name,
954954
NodeVariant(v) => v.node.name,
955955
NodeField(f) => f.ident.name,
956956
NodeLifetime(lt) => lt.name.ident().name,
@@ -1149,8 +1149,8 @@ impl Named for Item { fn name(&self) -> Name { self.name } }
11491149
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
11501150
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
11511151
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
1152-
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
1153-
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
1152+
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
1153+
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
11541154

11551155

11561156
pub fn map_crate<'hir>(sess: &::session::Session,
@@ -1309,13 +1309,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
13091309
Some(NodeImplItem(ii)) => {
13101310
match ii.node {
13111311
ImplItemKind::Const(..) => {
1312-
format!("assoc const {} in {}{}", ii.name, path_str(), id_str)
1312+
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
13131313
}
13141314
ImplItemKind::Method(..) => {
1315-
format!("method {} in {}{}", ii.name, path_str(), id_str)
1315+
format!("method {} in {}{}", ii.ident, path_str(), id_str)
13161316
}
13171317
ImplItemKind::Type(_) => {
1318-
format!("assoc type {} in {}{}", ii.name, path_str(), id_str)
1318+
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
13191319
}
13201320
}
13211321
}
@@ -1326,7 +1326,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
13261326
TraitItemKind::Type(..) => "assoc type",
13271327
};
13281328

1329-
format!("{} {} in {}{}", kind, ti.name, path_str(), id_str)
1329+
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str)
13301330
}
13311331
Some(NodeVariant(ref variant)) => {
13321332
format!("variant {} in {}{}",

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ pub struct TraitItemId {
15361536
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
15371537
pub struct TraitItem {
15381538
pub id: NodeId,
1539-
pub name: Name,
1539+
pub ident: Ident,
15401540
pub hir_id: HirId,
15411541
pub attrs: HirVec<Attribute>,
15421542
pub generics: Generics,
@@ -1579,7 +1579,7 @@ pub struct ImplItemId {
15791579
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
15801580
pub struct ImplItem {
15811581
pub id: NodeId,
1582-
pub name: Name,
1582+
pub ident: Ident,
15831583
pub hir_id: HirId,
15841584
pub vis: Visibility,
15851585
pub defaultness: Defaultness,
@@ -2140,7 +2140,7 @@ impl Item_ {
21402140
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
21412141
pub struct TraitItemRef {
21422142
pub id: TraitItemId,
2143-
pub name: Name,
2143+
pub ident: Ident,
21442144
pub kind: AssociatedItemKind,
21452145
pub span: Span,
21462146
pub defaultness: Defaultness,
@@ -2155,7 +2155,7 @@ pub struct TraitItemRef {
21552155
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
21562156
pub struct ImplItemRef {
21572157
pub id: ImplItemId,
2158-
pub name: Name,
2158+
pub ident: Ident,
21592159
pub kind: AssociatedItemKind,
21602160
pub span: Span,
21612161
pub vis: Visibility,

0 commit comments

Comments
 (0)