Skip to content

Commit 98979b2

Browse files
committed
---
yaml --- r: 30234 b: refs/heads/incoming c: 5b4d5ce h: refs/heads/master v: v3
1 parent 40b9ca5 commit 98979b2

File tree

3 files changed

+10
-56
lines changed

3 files changed

+10
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 3b554c1e0c46efcf0e55994fcd8fbc0c17b9c119
9+
refs/heads/incoming: 5b4d5cee03bdc297361f52b34e6e09b7b64161ea
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/rustc/middle/typeck/coherence.rs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,12 @@ struct CoherenceChecker {
147147

148148
let privileged_implementations: hashmap<node_id,()>;
149149

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-
155150
new(crate_context: @crate_ctxt) {
156151
self.crate_context = crate_context;
157152
self.inference_context = new_infer_ctxt(crate_context.tcx);
158153

159154
self.base_type_def_ids = new_def_hash();
160155
self.privileged_implementations = int_hash();
161-
self.privileged_types = new_def_hash();
162156
}
163157

164158
// Create a mapping containing a MethodInfo for every provided
@@ -427,36 +421,12 @@ struct CoherenceChecker {
427421

428422
// Privileged scope checking
429423
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-
437424
visit_crate(*crate, (), mk_vt(@{
438425
visit_item: |item, _context, visitor| {
439426
match item.node {
440427
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-
453428
// Then visit the module items.
454429
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-
}
460430
}
461431
item_impl(_, associated_traits, _, _) => {
462432
match self.base_type_def_ids.find(
@@ -467,12 +437,9 @@ struct CoherenceChecker {
467437
}
468438
Some(base_type_def_id) => {
469439
// 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.
475441

442+
if base_type_def_id.crate == local_crate {
476443
// Record that this implementation is OK.
477444
self.privileged_implementations.insert
478445
(item.id, ());
@@ -492,7 +459,7 @@ struct CoherenceChecker {
492459
~"cannot implement \
493460
inherent methods \
494461
for a type outside \
495-
the scope the type \
462+
the crate the type \
496463
was defined in; \
497464
define and \
498465
implement a trait \
@@ -546,25 +513,6 @@ struct CoherenceChecker {
546513
return trait_id;
547514
}
548515
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-
568516
// Converts an implementation in the AST to an Impl structure.
569517
fn create_impl_from_item(item: @item) -> @Impl {
570518
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
enum x { foo }
3+
impl x : core::cmp::Eq {
4+
pure fn eq(&&other: x) -> bool { self as int == other as int }
5+
}
6+
}

0 commit comments

Comments
 (0)