Skip to content

Commit ade1d28

Browse files
committed
Use Idents for associated type bindings in HIR
1 parent 897f6a5 commit ade1d28

File tree

15 files changed

+38
-36
lines changed

15 files changed

+38
-36
lines changed

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V,
651651
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
652652
type_binding: &'v TypeBinding) {
653653
visitor.visit_id(type_binding.id);
654-
visitor.visit_name(type_binding.span, type_binding.name);
654+
visitor.visit_ident(type_binding.ident);
655655
visitor.visit_ty(&type_binding.ty);
656656
}
657657

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ impl<'a> LoweringContext<'a> {
10081008
fn lower_ty_binding(&mut self, b: &TypeBinding, itctx: ImplTraitContext) -> hir::TypeBinding {
10091009
hir::TypeBinding {
10101010
id: self.lower_node_id(b.id).node_id,
1011-
name: self.lower_ident(b.ident),
1011+
ident: b.ident,
10121012
ty: self.lower_ty(&b.ty, itctx),
10131013
span: b.span,
10141014
}
@@ -1676,7 +1676,7 @@ impl<'a> LoweringContext<'a> {
16761676
bindings: hir_vec![
16771677
hir::TypeBinding {
16781678
id: this.next_id().node_id,
1679-
name: Symbol::intern(FN_OUTPUT_NAME),
1679+
ident: Ident::from_str(FN_OUTPUT_NAME),
16801680
ty: output
16811681
.as_ref()
16821682
.map(|ty| this.lower_ty(&ty, DISALLOWED))

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ pub enum ImplItemKind {
16601660
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
16611661
pub struct TypeBinding {
16621662
pub id: NodeId,
1663-
pub name: Name,
1663+
pub ident: Ident,
16641664
pub ty: P<Ty>,
16651665
pub span: Span,
16661666
}

src/librustc/hir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ impl<'a> State<'a> {
17151715

17161716
for binding in parameters.bindings.iter() {
17171717
start_or_comma(self)?;
1718-
self.print_name(binding.name)?;
1718+
self.print_ident(binding.ident)?;
17191719
self.s.space()?;
17201720
self.word_space("=")?;
17211721
self.print_type(&binding.ty)?;

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl_stable_hash_for!(struct hir::MethodSig {
268268

269269
impl_stable_hash_for!(struct hir::TypeBinding {
270270
id,
271-
name,
271+
ident,
272272
ty,
273273
span
274274
});

src/librustc/traits/project.rs

+3-2
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

+1-1
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

+2-3
Original file line numberDiff line numberDiff line change
@@ -2720,9 +2720,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27202720
// Hygienically compare a use-site name (`use_name`) for a field or an associated item with its
27212721
// supposed definition name (`def_name`). The method also needs `DefId` of the supposed
27222722
// definition's parent/scope to perform comparison.
2723-
pub fn hygienic_eq(self, use_name: Name, def_name: Name, def_parent_def_id: DefId) -> bool {
2724-
let (use_ident, def_ident) = (use_name.to_ident(), def_name.to_ident());
2725-
self.adjust_ident(use_ident, def_parent_def_id, DUMMY_NODE_ID).0 == def_ident
2723+
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
2724+
self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern()
27262725
}
27272726

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

src/librustc/ty/sty.rs

+3-3
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;
@@ -851,11 +851,11 @@ impl<'a, 'tcx> ProjectionTy<'tcx> {
851851
/// Construct a ProjectionTy by searching the trait from trait_ref for the
852852
/// associated item named item_name.
853853
pub fn from_ref_and_name(
854-
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Name
854+
tcx: TyCtxt, trait_ref: ty::TraitRef<'tcx>, item_name: Ident
855855
) -> ProjectionTy<'tcx> {
856856
let item_def_id = tcx.associated_items(trait_ref.def_id).find(|item| {
857857
item.kind == ty::AssociatedKind::Type &&
858-
tcx.hygienic_eq(item_name, item.name, trait_ref.def_id)
858+
tcx.hygienic_eq(item_name, item.name.to_ident(), trait_ref.def_id)
859859
}).unwrap().def_id;
860860

861861
ProjectionTy {

src/librustc_traits/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
332332
let mut where_clauses = vec![trait_implemented];
333333
where_clauses.extend(item_where_clauses);
334334
// `<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm>`
335-
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name);
335+
let projection_ty = ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, item.name.to_ident());
336336
// `Normalize(<A0 as Trait<A1..An>>::AssocType<Pn+1..Pm> -> T)`
337337
let normalize_goal = DomainGoal::Normalize(ty::ProjectionPredicate { projection_ty, ty });
338338
// `Normalize(... -> T) :- ...`

src/librustc_typeck/astconv.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub trait AstConv<'gcx, 'tcx> {
8484
}
8585

8686
struct ConvertedBinding<'tcx> {
87-
item_name: ast::Name,
87+
item_name: ast::Ident,
8888
ty: Ty<'tcx>,
8989
span: Span,
9090
}
@@ -333,7 +333,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
333333

334334
let assoc_bindings = parameters.bindings.iter().map(|binding| {
335335
ConvertedBinding {
336-
item_name: binding.name,
336+
item_name: binding.ident,
337337
ty: self.ast_ty_to_ty(&binding.ty),
338338
span: binding.span,
339339
}
@@ -475,12 +475,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
475475

476476
fn trait_defines_associated_type_named(&self,
477477
trait_def_id: DefId,
478-
assoc_name: ast::Name)
478+
assoc_name: ast::Ident)
479479
-> bool
480480
{
481481
self.tcx().associated_items(trait_def_id).any(|item| {
482482
item.kind == ty::AssociatedKind::Type &&
483-
self.tcx().hygienic_eq(assoc_name, item.name, trait_def_id)
483+
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), trait_def_id)
484484
})
485485
}
486486

@@ -559,7 +559,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
559559
}?;
560560

561561
let (assoc_ident, def_scope) =
562-
tcx.adjust_ident(binding.item_name.to_ident(), candidate.def_id(), ref_id);
562+
tcx.adjust_ident(binding.item_name, candidate.def_id(), ref_id);
563563
let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| {
564564
i.kind == ty::AssociatedKind::Type && i.name.to_ident() == assoc_ident
565565
}).expect("missing associated type");
@@ -768,7 +768,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
768768
// any ambiguity.
769769
fn find_bound_for_assoc_item(&self,
770770
ty_param_def_id: DefId,
771-
assoc_name: ast::Name,
771+
assoc_name: ast::Ident,
772772
span: Span)
773773
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
774774
{
@@ -797,7 +797,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
797797
fn one_bound_for_assoc_type<I>(&self,
798798
mut bounds: I,
799799
ty_param_name: &str,
800-
assoc_name: ast::Name,
800+
assoc_name: ast::Ident,
801801
span: Span)
802802
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
803803
where I: Iterator<Item=ty::PolyTraitRef<'tcx>>
@@ -827,7 +827,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
827827
for bound in bounds {
828828
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
829829
item.kind == ty::AssociatedKind::Type &&
830-
self.tcx().hygienic_eq(assoc_name, item.name, bound.def_id())
830+
self.tcx().hygienic_eq(assoc_name, item.name.to_ident(), bound.def_id())
831831
})
832832
.and_then(|item| self.tcx().hir.span_if_local(item.def_id));
833833

@@ -863,7 +863,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
863863
-> (Ty<'tcx>, Def)
864864
{
865865
let tcx = self.tcx();
866-
let assoc_name = item_segment.name;
866+
let assoc_name = item_segment.name.to_ident();
867867

868868
debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name);
869869

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

886886
let candidates =
887887
traits::supertraits(tcx, ty::Binder::bind(trait_ref))
888-
.filter(|r| self.trait_defines_associated_type_named(r.def_id(),
889-
assoc_name));
888+
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), assoc_name));
890889

891890
match self.one_bound_for_assoc_type(candidates, "Self", assoc_name, span) {
892891
Ok(bound) => bound,
@@ -913,7 +912,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
913912
};
914913

915914
let trait_did = bound.def_id();
916-
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name.to_ident(), trait_did, ref_id);
915+
let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_name, trait_did, ref_id);
917916
let item = tcx.associated_items(trait_did).find(|i| {
918917
Namespace::from(i.kind) == Namespace::Type &&
919918
i.name.to_ident() == assoc_ident

src/librustc_typeck/check/autoderef.rs

+2-2
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

+4-3
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1398,11 +1398,13 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13981398
let ty_impl_item = tcx.associated_item(tcx.hir.local_def_id(impl_item.id));
13991399
let ty_trait_item = tcx.associated_items(impl_trait_ref.def_id)
14001400
.find(|ac| Namespace::from(&impl_item.node) == Namespace::from(ac.kind) &&
1401-
tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
1401+
tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(),
1402+
impl_trait_ref.def_id))
14021403
.or_else(|| {
14031404
// Not compatible, but needed for the error message
14041405
tcx.associated_items(impl_trait_ref.def_id)
1405-
.find(|ac| tcx.hygienic_eq(ty_impl_item.name, ac.name, impl_trait_ref.def_id))
1406+
.find(|ac| tcx.hygienic_eq(ty_impl_item.name.to_ident(), ac.name.to_ident(),
1407+
impl_trait_ref.def_id))
14061408
});
14071409

14081410
// Check that impl definition matches trait definition

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,7 @@ pub struct TypeBinding {
42024202
impl Clean<TypeBinding> for hir::TypeBinding {
42034203
fn clean(&self, cx: &DocContext) -> TypeBinding {
42044204
TypeBinding {
4205-
name: self.name.clean(cx),
4205+
name: self.ident.name.clean(cx),
42064206
ty: self.ty.clean(cx)
42074207
}
42084208
}

0 commit comments

Comments
 (0)