Skip to content

Commit 1fe9b4d

Browse files
committed
Use Idents for associated type bindings in HIR
1 parent c5454c0 commit 1fe9b4d

File tree

15 files changed

+38
-36
lines changed

15 files changed

+38
-36
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
660660
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
661661
type_binding: &'v TypeBinding) {
662662
visitor.visit_id(type_binding.id);
663-
visitor.visit_name(type_binding.span, type_binding.name);
663+
visitor.visit_ident(type_binding.ident);
664664
visitor.visit_ty(&type_binding.ty);
665665
}
666666

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ impl<'a> LoweringContext<'a> {
10641064
fn lower_ty_binding(&mut self, b: &TypeBinding, itctx: ImplTraitContext) -> hir::TypeBinding {
10651065
hir::TypeBinding {
10661066
id: self.lower_node_id(b.id).node_id,
1067-
name: self.lower_ident(b.ident),
1067+
ident: b.ident,
10681068
ty: self.lower_ty(&b.ty, itctx),
10691069
span: b.span,
10701070
}
@@ -1820,7 +1820,7 @@ impl<'a> LoweringContext<'a> {
18201820
bindings: hir_vec![
18211821
hir::TypeBinding {
18221822
id: this.next_id().node_id,
1823-
name: Symbol::intern(FN_OUTPUT_NAME),
1823+
ident: Ident::from_str(FN_OUTPUT_NAME),
18241824
ty: output
18251825
.as_ref()
18261826
.map(|ty| this.lower_ty(&ty, DISALLOWED))

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ pub enum ImplItemKind {
16071607
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
16081608
pub struct TypeBinding {
16091609
pub id: NodeId,
1610-
pub name: Name,
1610+
pub ident: Ident,
16111611
pub ty: P<Ty>,
16121612
pub span: Span,
16131613
}

src/librustc/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ impl<'a> State<'a> {
17621762

17631763
for binding in generic_args.bindings.iter() {
17641764
start_or_comma(self)?;
1765-
self.print_name(binding.name)?;
1765+
self.print_ident(binding.ident)?;
17661766
self.s.space()?;
17671767
self.word_space("=")?;
17681768
self.print_type(&binding.ty)?;

src/librustc/ich/impls_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl_stable_hash_for!(struct hir::MethodSig {
278278

279279
impl_stable_hash_for!(struct hir::TypeBinding {
280280
id,
281-
name,
281+
ident,
282282
ty,
283283
span
284284
});

src/librustc/traits/project.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use infer::type_variable::TypeVariableOrigin;
3131
use middle::const_val::ConstVal;
3232
use mir::interpret::{GlobalId};
3333
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
34+
use syntax::ast::Ident;
3435
use syntax::symbol::Symbol;
3536
use ty::subst::{Subst, Substs};
3637
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
@@ -1452,7 +1453,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
14521453
projection_ty: ty::ProjectionTy::from_ref_and_name(
14531454
tcx,
14541455
trait_ref,
1455-
Symbol::intern(FN_OUTPUT_NAME),
1456+
Ident::from_str(FN_OUTPUT_NAME),
14561457
),
14571458
ty: ret_type
14581459
}
@@ -1546,7 +1547,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
15461547
let impl_node = specialization_graph::Node::Impl(impl_def_id);
15471548
for item in impl_node.items(tcx) {
15481549
if item.kind == ty::AssociatedKind::Type &&
1549-
tcx.hygienic_eq(item.name, assoc_ty_name, trait_def_id) {
1550+
tcx.hygienic_eq(item.name.to_ident(), assoc_ty_name.to_ident(), trait_def_id) {
15501551
return specialization_graph::NodeItem {
15511552
node: specialization_graph::Node::Impl(impl_def_id),
15521553
item,

src/librustc/traits/specialize/specialization_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'a, 'gcx, 'tcx> Ancestors {
379379
self.flat_map(move |node| {
380380
node.items(tcx).filter(move |impl_item| {
381381
impl_item.kind == trait_item_kind &&
382-
tcx.hygienic_eq(impl_item.name, trait_item_name, trait_def_id)
382+
tcx.hygienic_eq(impl_item.name.to_ident(), trait_item_name.to_ident(), trait_def_id)
383383
}).map(move |item| NodeItem { node: node, item: item })
384384
})
385385
}

src/librustc/ty/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,9 +2717,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27172717
// Hygienically compare a use-site name (`use_name`) for a field or an associated item with its
27182718
// supposed definition name (`def_name`). The method also needs `DefId` of the supposed
27192719
// definition's parent/scope to perform comparison.
2720-
pub fn hygienic_eq(self, use_name: Name, def_name: Name, def_parent_def_id: DefId) -> bool {
2721-
let (use_ident, def_ident) = (use_name.to_ident(), def_name.to_ident());
2722-
self.adjust_ident(use_ident, def_parent_def_id, DUMMY_NODE_ID).0 == def_ident
2720+
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
2721+
self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern()
27232722
}
27242723

27252724
pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) {

src/librustc/ty/sty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use mir::interpret::{Scalar, Pointer, Value, ConstValue};
2525
use std::iter;
2626
use std::cmp::Ordering;
2727
use rustc_target::spec::abi;
28-
use syntax::ast::{self, Name};
28+
use syntax::ast::{self, Ident};
2929
use syntax::symbol::{keywords, InternedString};
3030

3131
use serialize;
@@ -853,11 +853,11 @@ impl<'a, 'tcx> ProjectionTy<'tcx> {
853853
/// Construct a ProjectionTy by searching the trait from trait_ref for the
854854
/// associated item named item_name.
855855
pub fn from_ref_and_name(
856-
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Name
856+
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Ident
857857
) -> ProjectionTy<'tcx> {
858858
let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| {
859859
item.kind == ty::AssociatedKind::Type &&
860-
tcx.hygienic_eq(item_name, item.name, trait_ref.def_id)
860+
tcx.hygienic_eq(item_name, item.name.to_ident(), trait_ref.def_id)
861861
}).unwrap().def_id;
862862

863863
ProjectionTy {

src/librustc_traits/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
417417
let hypotheses = vec![trait_implemented];
418418

419419
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
420-
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
420+
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name.to_ident());
421421

422422
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
423423
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });

src/librustc_typeck/astconv.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub trait AstConv<'gcx, 'tcx> {
8383
}
8484

8585
struct ConvertedBinding<'tcx> {
86-
item_name: ast::Name,
86+
item_name: ast::Ident,
8787
ty: Ty<'tcx>,
8888
span: Span,
8989
}
@@ -342,7 +342,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
342342

343343
let assoc_bindings = generic_args.bindings.iter().map(|binding| {
344344
ConvertedBinding {
345-
item_name: binding.name,
345+
item_name: binding.ident,
346346
ty: self.ast_ty_to_ty(&binding.ty),
347347
span: binding.span,
348348
}
@@ -485,12 +485,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
485485

486486
fn trait_defines_associated_type_named(&self,
487487
trait_def_id: DefId,
488-
assoc_name: ast::Name)
488+
assoc_name: ast::Ident)
489489
-> bool
490490
{
491491
self.tcx().associated_items(trait_def_id).any(|item| {
492492
item.kind == ty::AssociatedKind::Type &&
493-
self.tcx().hygienic_eq(assoc_name, item.name, trait_def_id)
493+
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), trait_def_id)
494494
})
495495
}
496496

@@ -569,7 +569,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
569569
}?;
570570

571571
let (assoc_ident, def_scope) =
572-
tcx.adjust_ident(binding.item_name.to_ident(), candidate.def_id(), ref_id);
572+
tcx.adjust_ident(binding.item_name, candidate.def_id(), ref_id);
573573
let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| {
574574
i.kind == ty::AssociatedKind::Type && i.name.to_ident() == assoc_ident
575575
}).expect("missing associated type");
@@ -778,7 +778,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
778778
// any ambiguity.
779779
fn find_bound_for_assoc_item(&self,
780780
ty_param_def_id: DefId,
781-
assoc_name: ast::Name,
781+
assoc_name: ast::Ident,
782782
span: Span)
783783
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
784784
{
@@ -807,7 +807,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
807807
fn one_bound_for_assoc_type<I>(&self,
808808
mut bounds: I,
809809
ty_param_name: &str,
810-
assoc_name: ast::Name,
810+
assoc_name: ast::Ident,
811811
span: Span)
812812
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
813813
where I: Iterator<Item=ty::PolyTraitRef<'tcx>>
@@ -837,7 +837,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
837837
for bound in bounds {
838838
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
839839
item.kind == ty::AssociatedKind::Type &&
840-
self.tcx().hygienic_eq(assoc_name, item.name, bound.def_id())
840+
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), bound.def_id())
841841
})
842842
.and_then(|item| self.tcx().hir.span_if_local(item.def_id));
843843

@@ -873,7 +873,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
873873
-> (Ty<'tcx>, Def)
874874
{
875875
let tcx = self.tcx();
876-
let assoc_name = item_segment.name;
876+
let assoc_name = item_segment.name.to_ident();
877877

878878
debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name);
879879

@@ -895,8 +895,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
895895

896896
let candidates =
897897
traits::supertraits(tcx, ty::Binder::bind(trait_ref))
898-
.filter(|r| self.trait_defines_associated_type_named(r.def_id(),
899-
assoc_name));
898+
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), assoc_name));
900899

901900
match self.one_bound_for_assoc_type(candidates, "Self", assoc_name, span) {
902901
Ok(bound) => bound,
@@ -923,7 +922,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
923922
};
924923

925924
let trait_did = bound.def_id();
926-
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name.to_ident(), trait_did, ref_id);
925+
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name, trait_did, ref_id);
927926
let item = tcx.associated_items(trait_did).find(|i| {
928927
Namespace::from(i.kind) == Namespace::Type &&
929928
i.name.to_ident() == assoc_ident

src/librustc_typeck/check/autoderef.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc::ty::{ToPredicate, TypeFoldable};
2121
use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
2222

2323
use syntax_pos::Span;
24-
use syntax::symbol::Symbol;
24+
use syntax::ast::Ident;
2525

2626
use std::iter;
2727

@@ -134,7 +134,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
134134
ty::ProjectionTy::from_ref_and_name(
135135
tcx,
136136
trait_ref,
137-
Symbol::intern("Target"),
137+
Ident::from_str("Target"),
138138
),
139139
cause,
140140
0,

src/librustc_typeck/check/method/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
387387
/// and return it, or `None`, if no such item was defined there.
388388
pub fn associated_item(&self, def_id: DefId, item_name: ast::Name, ns: Namespace)
389389
-> Option<ty::AssociatedItem> {
390-
self.tcx.associated_items(def_id)
391-
.find(|item| Namespace::from(item.kind) == ns &&
392-
self.tcx.hygienic_eq(item_name, item.name, def_id))
390+
self.tcx.associated_items(def_id).find(|item| {
391+
Namespace::from(item.kind) == ns &&
392+
self.tcx.hygienic_eq(item_name.to_ident(), item.name.to_ident(), def_id)
393+
})
393394
}
394395
}

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,13 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14001400
let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id));
14011401
let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id)
14021402
.find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) &&
1403-
tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
1403+
tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(),
1404+
impl_trait_ref.def_id))
14041405
.or_else(|| {
14051406
// Not compatible, but needed for the error message
14061407
tcx.associated_items(impl_trait_ref.def_id)
1407-
.find(|ac| tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
1408+
.find(|ac| tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(),
1409+
impl_trait_ref.def_id))
14081410
});
14091411

14101412
// Check that impl definition matches trait definition

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4293,7 +4293,7 @@ pub struct TypeBinding {
42934293
impl Clean<TypeBinding> for hir::TypeBinding {
42944294
fn clean(&self, cx: &DocContext) -> TypeBinding {
42954295
TypeBinding {
4296-
name: self.name.clean(cx),
4296+
name: self.ident.name.clean(cx),
42974297
ty: self.ty.clean(cx)
42984298
}
42994299
}

0 commit comments

Comments
 (0)