@@ -108,7 +108,7 @@ pub type ExportMap2 = NodeMap<Vec<Export2>>;
108
108
109
109
pub struct Export2 {
110
110
pub name : String , // The name of the target.
111
- pub def_id : DefId , // The definition of the target.
111
+ pub def_id : DefId , // The definition of the target.
112
112
}
113
113
114
114
// This set contains all exported definitions from external crates. The set does
@@ -314,7 +314,7 @@ impl<'a> Copy for TypeParameters<'a> {}
314
314
315
315
// The rib kind controls the translation of local
316
316
// definitions (`DefLocal`) to upvars (`DefUpvar`).
317
-
317
+ # [ deriving ( Show ) ]
318
318
enum RibKind {
319
319
// No translation needs to be applied.
320
320
NormalRibKind ,
@@ -340,6 +340,7 @@ enum RibKind {
340
340
impl Copy for RibKind { }
341
341
342
342
// Methods can be required or provided. RequiredMethod methods only occur in traits.
343
+ #[ deriving( Show ) ]
343
344
enum MethodSort {
344
345
RequiredMethod ,
345
346
ProvidedMethod ( NodeId )
@@ -414,6 +415,7 @@ enum DuplicateCheckingMode {
414
415
impl Copy for DuplicateCheckingMode { }
415
416
416
417
/// One local scope.
418
+ #[ deriving( Show ) ]
417
419
struct Rib {
418
420
bindings : HashMap < Name , DefLike > ,
419
421
kind : RibKind ,
@@ -728,8 +730,11 @@ impl NameBindings {
728
730
let type_def = self . type_def . borrow ( ) . clone ( ) ;
729
731
match type_def {
730
732
None => {
731
- let module = Module :: new ( parent_link, def_id, kind,
732
- external, is_public) ;
733
+ let module = Module :: new ( parent_link,
734
+ def_id,
735
+ kind,
736
+ external,
737
+ is_public) ;
733
738
* self . type_def . borrow_mut ( ) = Some ( TypeNsDef {
734
739
modifiers : modifiers,
735
740
module_def : Some ( Rc :: new ( module) ) ,
@@ -774,9 +779,9 @@ impl NameBindings {
774
779
}
775
780
Some ( type_def) => {
776
781
* self . type_def . borrow_mut ( ) = Some ( TypeNsDef {
782
+ module_def : type_def. module_def ,
777
783
type_def : Some ( def) ,
778
784
type_span : Some ( sp) ,
779
- module_def : type_def. module_def ,
780
785
modifiers : modifiers,
781
786
} ) ;
782
787
}
@@ -1286,7 +1291,7 @@ impl<'a> Resolver<'a> {
1286
1291
}
1287
1292
1288
1293
fn get_parent_link ( & mut self , parent : ReducedGraphParent , name : Name )
1289
- -> ParentLink {
1294
+ -> ParentLink {
1290
1295
match parent {
1291
1296
ModuleReducedGraphParent ( module_) => {
1292
1297
return ModuleParentLink ( module_. downgrade ( ) , name) ;
@@ -1578,14 +1583,14 @@ impl<'a> Resolver<'a> {
1578
1583
1579
1584
ItemImpl ( _, Some ( _) , _, _) => parent,
1580
1585
1581
- ItemTrait ( _, _, _, ref methods ) => {
1586
+ ItemTrait ( _, _, _, ref items ) => {
1582
1587
let name_bindings =
1583
1588
self . add_child ( name,
1584
1589
parent. clone ( ) ,
1585
1590
ForbidDuplicateTypesAndModules ,
1586
1591
sp) ;
1587
1592
1588
- // Add all the methods within to a new module.
1593
+ // Add all the items within to a new module.
1589
1594
let parent_link = self . get_parent_link ( parent. clone ( ) , name) ;
1590
1595
name_bindings. define_module ( parent_link,
1591
1596
Some ( local_def ( item. id ) ) ,
@@ -1598,13 +1603,12 @@ impl<'a> Resolver<'a> {
1598
1603
1599
1604
let def_id = local_def ( item. id ) ;
1600
1605
1601
- // Add the names of all the methods to the trait info.
1602
- for method in methods . iter ( ) {
1603
- let ( name, kind) = match * method {
1606
+ // Add the names of all the items to the trait info.
1607
+ for trait_item in items . iter ( ) {
1608
+ let ( name, kind) = match * trait_item {
1604
1609
ast:: RequiredMethod ( _) |
1605
1610
ast:: ProvidedMethod ( _) => {
1606
- let ty_m =
1607
- ast_util:: trait_item_to_ty_method ( method) ;
1611
+ let ty_m = ast_util:: trait_item_to_ty_method ( trait_item) ;
1608
1612
1609
1613
let name = ty_m. ident . name ;
1610
1614
@@ -3353,7 +3357,7 @@ impl<'a> Resolver<'a> {
3353
3357
use_lexical_scope : UseLexicalScopeFlag ,
3354
3358
span : Span ,
3355
3359
name_search_type : NameSearchType )
3356
- -> ResolveResult < ( Rc < Module > , LastPrivate ) > {
3360
+ -> ResolveResult < ( Rc < Module > , LastPrivate ) > {
3357
3361
let module_path_len = module_path. len ( ) ;
3358
3362
assert ! ( module_path_len > 0 ) ;
3359
3363
@@ -3382,7 +3386,9 @@ impl<'a> Resolver<'a> {
3382
3386
mpath. slice_to( idx - 1 ) ) ;
3383
3387
return Failed ( Some ( ( span, msg) ) ) ;
3384
3388
} ,
3385
- None => return Failed ( None ) ,
3389
+ None => {
3390
+ return Failed ( None )
3391
+ }
3386
3392
}
3387
3393
}
3388
3394
Failed ( err) => return Failed ( err) ,
@@ -3407,9 +3413,8 @@ impl<'a> Resolver<'a> {
3407
3413
// This is not a crate-relative path. We resolve the
3408
3414
// first component of the path in the current lexical
3409
3415
// scope and then proceed to resolve below that.
3410
- match self . resolve_module_in_lexical_scope (
3411
- module_,
3412
- module_path[ 0 ] ) {
3416
+ match self . resolve_module_in_lexical_scope ( module_,
3417
+ module_path[ 0 ] ) {
3413
3418
Failed ( err) => return Failed ( err) ,
3414
3419
Indeterminate => {
3415
3420
debug ! ( "(resolving module path for import) \
@@ -3576,8 +3581,7 @@ impl<'a> Resolver<'a> {
3576
3581
-> ResolveResult < Rc < Module > > {
3577
3582
// If this module is an anonymous module, resolve the item in the
3578
3583
// lexical scope. Otherwise, resolve the item from the crate root.
3579
- let resolve_result = self . resolve_item_in_lexical_scope (
3580
- module_, name, TypeNS ) ;
3584
+ let resolve_result = self . resolve_item_in_lexical_scope ( module_, name, TypeNS ) ;
3581
3585
match resolve_result {
3582
3586
Success ( ( target, _) ) => {
3583
3587
let bindings = & * target. bindings ;
@@ -4590,25 +4594,42 @@ impl<'a> Resolver<'a> {
4590
4594
4591
4595
fn resolve_where_clause ( & mut self , where_clause : & ast:: WhereClause ) {
4592
4596
for predicate in where_clause. predicates . iter ( ) {
4593
- match self . resolve_identifier ( predicate. ident ,
4594
- TypeNS ,
4595
- true ,
4596
- predicate. span ) {
4597
- Some ( ( def @ DefTyParam ( _, _, _) , last_private) ) => {
4598
- self . record_def ( predicate. id , ( def, last_private) ) ;
4599
- }
4600
- _ => {
4601
- self . resolve_error (
4602
- predicate. span ,
4603
- format ! ( "undeclared type parameter `{}`" ,
4604
- token:: get_ident(
4605
- predicate. ident) ) . as_slice ( ) ) ;
4597
+ match predicate {
4598
+ & ast:: WherePredicate :: BoundPredicate ( ref bound_pred) => {
4599
+ match self . resolve_identifier ( bound_pred. ident ,
4600
+ TypeNS ,
4601
+ true ,
4602
+ bound_pred. span ) {
4603
+ Some ( ( def @ DefTyParam ( ..) , last_private) ) => {
4604
+ self . record_def ( bound_pred. id , ( def, last_private) ) ;
4605
+ }
4606
+ _ => {
4607
+ self . resolve_error (
4608
+ bound_pred. span ,
4609
+ format ! ( "undeclared type parameter `{}`" ,
4610
+ token:: get_ident(
4611
+ bound_pred. ident) ) . as_slice ( ) ) ;
4612
+ }
4613
+ }
4614
+
4615
+ for bound in bound_pred. bounds . iter ( ) {
4616
+ self . resolve_type_parameter_bound ( bound_pred. id , bound,
4617
+ TraitBoundingTypeParameter ) ;
4618
+ }
4606
4619
}
4607
- }
4620
+ & ast:: WherePredicate :: EqPredicate ( ref eq_pred) => {
4621
+ match self . resolve_path ( eq_pred. id , & eq_pred. path , TypeNS , true ) {
4622
+ Some ( ( def @ DefTyParam ( ..) , last_private) ) => {
4623
+ self . record_def ( eq_pred. id , ( def, last_private) ) ;
4624
+ }
4625
+ _ => {
4626
+ self . resolve_error ( eq_pred. path . span ,
4627
+ "undeclared associated type" ) ;
4628
+ }
4629
+ }
4608
4630
4609
- for bound in predicate. bounds . iter ( ) {
4610
- self . resolve_type_parameter_bound ( predicate. id , bound,
4611
- TraitBoundingTypeParameter ) ;
4631
+ self . resolve_type ( & * eq_pred. ty ) ;
4632
+ }
4612
4633
}
4613
4634
}
4614
4635
}
@@ -5269,15 +5290,19 @@ impl<'a> Resolver<'a> {
5269
5290
path : & Path ,
5270
5291
namespace : Namespace ,
5271
5292
check_ribs : bool ) -> Option < ( Def , LastPrivate ) > {
5272
- // First, resolve the types.
5293
+ // First, resolve the types and associated type bindings .
5273
5294
for ty in path. segments . iter ( ) . flat_map ( |s| s. parameters . types ( ) . into_iter ( ) ) {
5274
5295
self . resolve_type ( & * * ty) ;
5275
5296
}
5297
+ for binding in path. segments . iter ( ) . flat_map ( |s| s. parameters . bindings ( ) . into_iter ( ) ) {
5298
+ self . resolve_type ( & * binding. ty ) ;
5299
+ }
5276
5300
5277
5301
if path. global {
5278
5302
return self . resolve_crate_relative_path ( path, namespace) ;
5279
5303
}
5280
5304
5305
+ // Try to find a path to an item in a module.
5281
5306
let unqualified_def =
5282
5307
self . resolve_identifier ( path. segments
5283
5308
. last ( ) . unwrap ( )
@@ -5307,15 +5332,15 @@ impl<'a> Resolver<'a> {
5307
5332
5308
5333
// resolve a single identifier (used as a varref)
5309
5334
fn resolve_identifier ( & mut self ,
5310
- identifier : Ident ,
5311
- namespace : Namespace ,
5312
- check_ribs : bool ,
5313
- span : Span )
5314
- -> Option < ( Def , LastPrivate ) > {
5335
+ identifier : Ident ,
5336
+ namespace : Namespace ,
5337
+ check_ribs : bool ,
5338
+ span : Span )
5339
+ -> Option < ( Def , LastPrivate ) > {
5315
5340
if check_ribs {
5316
5341
match self . resolve_identifier_in_local_ribs ( identifier,
5317
- namespace,
5318
- span) {
5342
+ namespace,
5343
+ span) {
5319
5344
Some ( def) => {
5320
5345
return Some ( ( def, LastMod ( AllPublic ) ) ) ;
5321
5346
}
@@ -5333,7 +5358,7 @@ impl<'a> Resolver<'a> {
5333
5358
containing_module : Rc < Module > ,
5334
5359
name : Name ,
5335
5360
namespace : Namespace )
5336
- -> NameDefinition {
5361
+ -> NameDefinition {
5337
5362
// First, search children.
5338
5363
self . populate_module_if_necessary ( & containing_module) ;
5339
5364
@@ -5403,9 +5428,9 @@ impl<'a> Resolver<'a> {
5403
5428
5404
5429
// resolve a "module-relative" path, e.g. a::b::c
5405
5430
fn resolve_module_relative_path ( & mut self ,
5406
- path : & Path ,
5407
- namespace : Namespace )
5408
- -> Option < ( Def , LastPrivate ) > {
5431
+ path : & Path ,
5432
+ namespace : Namespace )
5433
+ -> Option < ( Def , LastPrivate ) > {
5409
5434
let module_path = path. segments . init ( ) . iter ( )
5410
5435
. map ( |ps| ps. identifier . name )
5411
5436
. collect :: < Vec < _ > > ( ) ;
@@ -5422,9 +5447,8 @@ impl<'a> Resolver<'a> {
5422
5447
let ( span, msg) = match err {
5423
5448
Some ( ( span, msg) ) => ( span, msg) ,
5424
5449
None => {
5425
- let msg = format ! ( "Use of undeclared module `{}`" ,
5426
- self . names_to_string(
5427
- module_path. as_slice( ) ) ) ;
5450
+ let msg = format ! ( "Use of undeclared type or module `{}`" ,
5451
+ self . names_to_string( module_path. as_slice( ) ) ) ;
5428
5452
( path. span , msg)
5429
5453
}
5430
5454
} ;
@@ -5518,10 +5542,10 @@ impl<'a> Resolver<'a> {
5518
5542
}
5519
5543
5520
5544
fn resolve_identifier_in_local_ribs ( & mut self ,
5521
- ident : Ident ,
5522
- namespace : Namespace ,
5523
- span : Span )
5524
- -> Option < Def > {
5545
+ ident : Ident ,
5546
+ namespace : Namespace ,
5547
+ span : Span )
5548
+ -> Option < Def > {
5525
5549
// Check the local set of ribs.
5526
5550
let search_result = match namespace {
5527
5551
ValueNS => {
0 commit comments