@@ -147,18 +147,12 @@ struct CoherenceChecker {
147
147
148
148
let privileged_implementations: hashmap < node_id , ( ) > ;
149
149
150
- // The set of types that we are currently in the privileged scope of. This
151
- // is used while we traverse the AST while checking privileged scopes.
152
-
153
- let privileged_types: hashmap < def_id , ( ) > ;
154
-
155
150
new ( crate_context: @crate_ctxt) {
156
151
self . crate_context = crate_context;
157
152
self . inference_context = new_infer_ctxt ( crate_context. tcx ) ;
158
153
159
154
self . base_type_def_ids = new_def_hash ( ) ;
160
155
self . privileged_implementations = int_hash ( ) ;
161
- self . privileged_types = new_def_hash ( ) ;
162
156
}
163
157
164
158
// Create a mapping containing a MethodInfo for every provided
@@ -427,36 +421,12 @@ struct CoherenceChecker {
427
421
428
422
// Privileged scope checking
429
423
fn check_privileged_scopes( crate : @crate ) {
430
- // Gather up all privileged types.
431
- let privileged_types =
432
- self . gather_privileged_types ( crate . node. module . items ) ;
433
- for privileged_types. each |privileged_type| {
434
- self . privileged_types . insert ( privileged_type, ( ) ) ;
435
- }
436
-
437
424
visit_crate( * crate , ( ) , mk_vt( @{
438
425
visit_item: |item, _context, visitor| {
439
426
match item. node {
440
427
item_mod( module_) => {
441
- // First, gather up all privileged types.
442
- let privileged_types =
443
- self . gather_privileged_types ( module_. items ) ;
444
- for privileged_types. each |privileged_type| {
445
- debug ! ( "(checking privileged scopes) entering \
446
- privileged scope of %d:%d",
447
- privileged_type. crate ,
448
- privileged_type. node) ;
449
-
450
- self . privileged_types . insert ( privileged_type, ( ) ) ;
451
- }
452
-
453
428
// Then visit the module items.
454
429
visit_mod ( module_, item. span , item. id , ( ) , visitor) ;
455
-
456
- // Finally, remove privileged types from the map.
457
- for privileged_types. each |privileged_type| {
458
- self . privileged_types. remove( privileged_type) ;
459
- }
460
430
}
461
431
item_impl( _, associated_traits, _, _) => {
462
432
match self . base_type_def_ids . find (
@@ -467,12 +437,9 @@ struct CoherenceChecker {
467
437
}
468
438
Some ( base_type_def_id) => {
469
439
// Check to see whether the implementation is
470
- // in the scope of its base type.
471
-
472
- let privileged_types = & self . privileged_types ;
473
- if privileged_types.
474
- contains_key ( base_type_def_id) {
440
+ // in the same crate as its base type.
475
441
442
+ if base_type_def_id. crate == local_crate {
476
443
// Record that this implementation is OK.
477
444
self . privileged_implementations . insert
478
445
( item. id , ( ) ) ;
@@ -492,7 +459,7 @@ struct CoherenceChecker {
492
459
~"cannot implement \
493
460
inherent methods \
494
461
for a type outside \
495
- the scope the type \
462
+ the crate the type \
496
463
was defined in ; \
497
464
define and \
498
465
implement a trait \
@@ -546,25 +513,6 @@ struct CoherenceChecker {
546
513
return trait_id;
547
514
}
548
515
549
- fn gather_privileged_types(items: ~[@item]) -> @DVec<def_id> {
550
- let results = @DVec();
551
- for items.each |item| {
552
- match item.node {
553
- item_class(*) | item_enum(*) | item_trait(*) => {
554
- results.push(local_def(item.id));
555
- }
556
-
557
- item_const(*) | item_fn(*) | item_mod(*) |
558
- item_foreign_mod(*) | item_ty(*) | item_impl(*) |
559
- item_mac(*) => {
560
- // Nothing to do.
561
- }
562
- }
563
- }
564
-
565
- return results;
566
- }
567
-
568
516
// Converts an implementation in the AST to an Impl structure.
569
517
fn create_impl_from_item(item: @item) -> @Impl {
570
518
0 commit comments