Skip to content

Commit d440189

Browse files
committed
---
yaml --- r: 178559 b: refs/heads/try c: 9985991 h: refs/heads/master i: 178557: e5b1eaf 178555: 0174582 178551: 5c59882 178543: 2c4bf25 178527: b325358 178495: baa8f55 178431: ffdfc35 v: v3
1 parent c343c4f commit d440189

File tree

12 files changed

+51
-135
lines changed

12 files changed

+51
-135
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 336c8d2e9c6b276b162bdb3edd43706372e6eddd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 474b324eda10440d6568ef872a7307d38e7de95b
5-
refs/heads/try: e8489d3cc7a44dc31030b17ec0faad795d3895df
5+
refs/heads/try: 998599187fa0d1341ffd051e8d54b7ba7fea0be5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/middle/traits/coherence.rs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{Obligation, ObligationCause};
1515
use super::project;
1616
use super::util;
1717

18-
use middle::subst::{Subst, TypeSpace};
18+
use middle::subst::{Subst};
1919
use middle::ty::{self, Ty};
2020
use middle::infer::InferCtxt;
2121
use std::collections::HashSet;
@@ -89,28 +89,16 @@ pub fn orphan_check<'tcx>(tcx: &ty::ctxt<'tcx>,
8989
return Ok(());
9090
}
9191

92-
// First, create an ordered iterator over all the type parameters to the trait, with the self
93-
// type appearing first.
94-
let input_tys = Some(trait_ref.self_ty());
95-
let input_tys = input_tys.iter().chain(trait_ref.substs.types.get_slice(TypeSpace).iter());
96-
let mut input_tys = input_tys;
97-
98-
// Find the first input type that either references a type parameter OR
99-
// some local type.
100-
match input_tys.find(|&&input_ty| references_local_or_type_parameter(tcx, input_ty)) {
101-
Some(&input_ty) => {
102-
// Within this first type, check that all type parameters are covered by a local
103-
// type constructor. Note that if there is no local type constructor, then any
104-
// type parameter at all will be an error.
105-
let covered_params = type_parameters_covered_by_ty(tcx, input_ty);
106-
let all_params = type_parameters_reachable_from_ty(input_ty);
107-
for &param in all_params.difference(&covered_params) {
108-
return Err(OrphanCheckErr::UncoveredTy(param));
109-
}
110-
}
111-
None => {
112-
return Err(OrphanCheckErr::NoLocalInputType);
113-
}
92+
// Otherwise, check that (1) all type parameters are covered.
93+
let covered_params = type_parameters_covered_by_ty(tcx, trait_ref.self_ty());
94+
let all_params = type_parameters_reachable_from_ty(trait_ref.self_ty());
95+
for &param in all_params.difference(&covered_params) {
96+
return Err(OrphanCheckErr::UncoveredTy(param));
97+
}
98+
99+
// And (2) some local type appears.
100+
if !trait_ref.self_ty().walk().any(|t| ty_is_local_constructor(tcx, t)) {
101+
return Err(OrphanCheckErr::NoLocalInputType);
114102
}
115103

116104
return Ok(());
@@ -174,17 +162,13 @@ fn type_parameters_covered_by_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
174162

175163
/// All type parameters reachable from `ty`
176164
fn type_parameters_reachable_from_ty<'tcx>(ty: Ty<'tcx>) -> HashSet<Ty<'tcx>> {
177-
ty.walk().filter(|&t| is_type_parameter(t)).collect()
178-
}
179-
180-
fn references_local_or_type_parameter<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
181-
ty.walk().any(|ty| is_type_parameter(ty) || ty_is_local_constructor(tcx, ty))
182-
}
183-
184-
fn is_type_parameter<'tcx>(ty: Ty<'tcx>) -> bool {
185-
match ty.sty {
186-
// FIXME(#20590) straighten story about projection types
187-
ty::ty_projection(..) | ty::ty_param(..) => true,
188-
_ => false,
189-
}
165+
ty.walk()
166+
.filter(|&t| {
167+
match t.sty {
168+
// FIXME(#20590) straighten story about projection types
169+
ty::ty_projection(..) | ty::ty_param(..) => true,
170+
_ => false,
171+
}
172+
})
173+
.collect()
190174
}

branches/try/src/librustc_typeck/coherence/orphan.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
7777
Ok(()) => { }
7878
Err(traits::OrphanCheckErr::NoLocalInputType) => {
7979
if !ty::has_attr(self.tcx, trait_def_id, "old_orphan_check") {
80+
let self_ty = ty::lookup_item_type(self.tcx, def_id).ty;
8081
span_err!(
8182
self.tcx.sess, item.span, E0117,
82-
"the impl does not reference any \
83+
"the type `{}` does not reference any \
8384
types defined in this crate; \
8485
only traits defined in the current crate can be \
85-
implemented for arbitrary types");
86+
implemented for arbitrary types",
87+
self_ty.user_string(self.tcx));
8688
}
8789
}
8890
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {

branches/try/src/libstd/collections/hash/table.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ use clone::Clone;
1616
use cmp;
1717
use hash::{Hash, Hasher};
1818
use iter::{Iterator, IteratorExt, ExactSizeIterator, count};
19-
use marker::{Copy, Sized, self};
19+
use marker::{Copy, Send, Sync, Sized, self};
2020
use mem::{min_align_of, size_of};
2121
use mem;
2222
use num::{Int, UnsignedInt};
2323
use ops::{Deref, DerefMut, Drop};
2424
use option::Option;
2525
use option::Option::{Some, None};
26-
use ptr::{Unique, PtrExt, copy_nonoverlapping_memory, zero_memory};
27-
use ptr;
26+
use ptr::{self, PtrExt, copy_nonoverlapping_memory, zero_memory};
2827
use rt::heap::{allocate, deallocate};
2928
use collections::hash_state::HashState;
3029

@@ -70,12 +69,15 @@ const EMPTY_BUCKET: u64 = 0u64;
7069
pub struct RawTable<K, V> {
7170
capacity: uint,
7271
size: uint,
73-
hashes: Unique<u64>,
72+
hashes: *mut u64,
7473
// Because K/V do not appear directly in any of the types in the struct,
7574
// inform rustc that in fact instances of K and V are reachable from here.
7675
marker: marker::CovariantType<(K,V)>,
7776
}
7877

78+
unsafe impl<K: Send, V: Send> Send for RawTable<K, V> {}
79+
unsafe impl<K: Sync, V: Sync> Sync for RawTable<K, V> {}
80+
7981
struct RawBucket<K, V> {
8082
hash: *mut u64,
8183
key: *mut K,
@@ -565,7 +567,7 @@ impl<K, V> RawTable<K, V> {
565567
return RawTable {
566568
size: 0,
567569
capacity: 0,
568-
hashes: Unique::null(),
570+
hashes: ptr::null_mut(),
569571
marker: marker::CovariantType,
570572
};
571573
}
@@ -604,7 +606,7 @@ impl<K, V> RawTable<K, V> {
604606
RawTable {
605607
capacity: capacity,
606608
size: 0,
607-
hashes: Unique(hashes),
609+
hashes: hashes,
608610
marker: marker::CovariantType,
609611
}
610612
}
@@ -613,14 +615,14 @@ impl<K, V> RawTable<K, V> {
613615
let hashes_size = self.capacity * size_of::<u64>();
614616
let keys_size = self.capacity * size_of::<K>();
615617

616-
let buffer = self.hashes.0 as *mut u8;
618+
let buffer = self.hashes as *mut u8;
617619
let (keys_offset, vals_offset) = calculate_offsets(hashes_size,
618620
keys_size, min_align_of::<K>(),
619621
min_align_of::<V>());
620622

621623
unsafe {
622624
RawBucket {
623-
hash: self.hashes.0,
625+
hash: self.hashes,
624626
key: buffer.offset(keys_offset as int) as *mut K,
625627
val: buffer.offset(vals_offset as int) as *mut V
626628
}
@@ -632,7 +634,7 @@ impl<K, V> RawTable<K, V> {
632634
pub fn new(capacity: uint) -> RawTable<K, V> {
633635
unsafe {
634636
let ret = RawTable::new_uninitialized(capacity);
635-
zero_memory(ret.hashes.0, capacity);
637+
zero_memory(ret.hashes, capacity);
636638
ret
637639
}
638640
}
@@ -652,7 +654,7 @@ impl<K, V> RawTable<K, V> {
652654
RawBuckets {
653655
raw: self.first_bucket_raw(),
654656
hashes_end: unsafe {
655-
self.hashes.0.offset(self.capacity as int)
657+
self.hashes.offset(self.capacity as int)
656658
},
657659
marker: marker::ContravariantLifetime,
658660
}
@@ -964,7 +966,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
964966
#[unsafe_destructor]
965967
impl<K, V> Drop for RawTable<K, V> {
966968
fn drop(&mut self) {
967-
if self.hashes.0.is_null() {
969+
if self.hashes.is_null() {
968970
return;
969971
}
970972
// This is done in reverse because we've likely partially taken
@@ -984,7 +986,7 @@ impl<K, V> Drop for RawTable<K, V> {
984986
vals_size, min_align_of::<V>());
985987

986988
unsafe {
987-
deallocate(self.hashes.0 as *mut u8, size, align);
989+
deallocate(self.hashes as *mut u8, size, align);
988990
// Remember how everything was allocated out of one buffer
989991
// during initialization? We only need one call to free here.
990992
}

branches/try/src/test/compile-fail/coherence-all-remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ extern crate "coherence-lib" as lib;
1414
use lib::Remote1;
1515

1616
impl<T> Remote1<T> for isize { }
17-
//~^ ERROR E0210
17+
//~^ ERROR E0117
1818

1919
fn main() { }

branches/try/src/test/run-pass/coherence-bigint-int.rs renamed to branches/try/src/test/compile-fail/coherence-bigint-int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ use lib::Remote1;
1515

1616
pub struct BigInt;
1717

18-
impl Remote1<BigInt> for isize { }
18+
impl Remote1<BigInt> for isize { } //~ ERROR E0117
1919

2020
fn main() { }

branches/try/src/test/run-pass/coherence-bigint-vecint.rs renamed to branches/try/src/test/compile-fail/coherence-bigint-vecint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ use lib::Remote1;
1515

1616
pub struct BigInt;
1717

18-
impl Remote1<BigInt> for Vec<isize> { }
18+
impl Remote1<BigInt> for Vec<isize> { } //~ ERROR E0117
1919

2020
fn main() { }

branches/try/src/test/compile-fail/coherence-orphan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct TheType;
2121

2222
impl TheTrait<usize> for isize { } //~ ERROR E0117
2323

24-
impl TheTrait<TheType> for isize { }
24+
impl TheTrait<TheType> for isize { } //~ ERROR E0117
2525

2626
impl TheTrait<isize> for TheType { }
2727

branches/try/src/test/compile-fail/coherence-pair-covered-uncovered-1.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

branches/try/src/test/compile-fail/coherence-cow-no-cover.rs renamed to branches/try/src/test/compile-fail/issue-21763.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// aux-build:coherence-lib.rs
11+
// Regression test for HashMap only impl'ing Send/Sync if its contents do
1212

13-
// Test that it's not ok for U to appear uncovered
13+
use std::collections::HashMap;
14+
use std::rc::Rc;
1415

15-
extern crate "coherence-lib" as lib;
16-
use lib::{Remote,Pair};
16+
fn foo<T: Send>() {}
1717

18-
pub struct Cover<T>(T);
19-
20-
impl<T,U> Remote for Pair<Cover<T>,U> { }
21-
//~^ ERROR type parameter `U` is not constrained by any local type
22-
23-
fn main() { }
18+
fn main() {
19+
foo::<HashMap<Rc<()>, Rc<()>>>();
20+
//~^ ERROR: the trait `core::marker::Send` is not implemented for the type `alloc::rc::Rc<()>`
21+
}

branches/try/src/test/run-pass/coherence-cow-1.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

branches/try/src/test/run-pass/coherence-cow-2.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)