Skip to content

Commit 856e84f

Browse files
author
Alexander Regueiro
committed
Resolve Self within type definitions.
Currently type definitions include `struct`, `enum`, `union`, `existential type`.
1 parent 5db71db commit 856e84f

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/librustc_resolve/lib.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,14 +2192,22 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
21922192
self.check_proc_macro_attrs(&item.attrs);
21932193

21942194
match item.node {
2195-
ItemKind::Enum(_, ref generics) |
21962195
ItemKind::Ty(_, ref generics) |
2197-
ItemKind::Existential(_, ref generics) |
2198-
ItemKind::Struct(_, ref generics) |
2199-
ItemKind::Union(_, ref generics) |
2200-
ItemKind::Fn(_, _, ref generics, _) => {
2196+
ItemKind::Fn(_, _, ref generics, _) |
2197+
ItemKind::Existential(_, ref generics) => {
22012198
self.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind),
2202-
|this| visit::walk_item(this, item));
2199+
|this| visit::walk_item(this, item));
2200+
}
2201+
2202+
ItemKind::Enum(_, ref generics) |
2203+
ItemKind::Struct(_, ref generics) |
2204+
ItemKind::Union(_, ref generics) => {
2205+
self.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind), |this| {
2206+
let item_def_id = this.definitions.local_def_id(item.id);
2207+
this.with_self_rib(Def::SelfTy(None, Some(item_def_id)), |this| {
2208+
visit::walk_item(this, item);
2209+
});
2210+
});
22032211
}
22042212

22052213
ItemKind::Impl(.., ref generics, ref opt_trait_ref, ref self_type, ref impl_items) =>
@@ -2489,13 +2497,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
24892497
let item_def_id = this.definitions.local_def_id(item_id);
24902498
this.with_self_rib(Def::SelfTy(trait_id, Some(item_def_id)), |this| {
24912499
if let Some(trait_ref) = opt_trait_reference.as_ref() {
2492-
// Resolve type arguments in trait path
2500+
// Resolve type arguments in the trait path.
24932501
visit::walk_trait_ref(this, trait_ref);
24942502
}
24952503
// Resolve the self type.
24962504
this.visit_ty(self_type);
24972505
// Resolve the type parameters.
24982506
this.visit_generics(generics);
2507+
// Resolve the items within the impl.
24992508
this.with_current_self_type(self_type, |this| {
25002509
for impl_item in impl_items {
25012510
this.check_proc_macro_attrs(&impl_item.attrs);
@@ -2511,8 +2520,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
25112520
// If this is a trait impl, ensure the const
25122521
// exists in trait
25132522
this.check_trait_item(impl_item.ident,
2514-
ValueNS,
2515-
impl_item.span,
2523+
ValueNS,
2524+
impl_item.span,
25162525
|n, s| ConstNotMemberOfTrait(n, s));
25172526
this.with_constant_rib(|this|
25182527
visit::walk_impl_item(this, impl_item)
@@ -2522,8 +2531,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
25222531
// If this is a trait impl, ensure the method
25232532
// exists in trait
25242533
this.check_trait_item(impl_item.ident,
2525-
ValueNS,
2526-
impl_item.span,
2534+
ValueNS,
2535+
impl_item.span,
25272536
|n, s| MethodNotMemberOfTrait(n, s));
25282537

25292538
visit::walk_impl_item(this, impl_item);
@@ -2532,8 +2541,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
25322541
// If this is a trait impl, ensure the type
25332542
// exists in trait
25342543
this.check_trait_item(impl_item.ident,
2535-
TypeNS,
2536-
impl_item.span,
2544+
TypeNS,
2545+
impl_item.span,
25372546
|n, s| TypeNotMemberOfTrait(n, s));
25382547

25392548
this.visit_ty(ty);
@@ -2542,8 +2551,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
25422551
// If this is a trait impl, ensure the type
25432552
// exists in trait
25442553
this.check_trait_item(impl_item.ident,
2545-
TypeNS,
2546-
impl_item.span,
2554+
TypeNS,
2555+
impl_item.span,
25472556
|n, s| TypeNotMemberOfTrait(n, s));
25482557

25492558
for bound in bounds {

0 commit comments

Comments
 (0)