Skip to content

Commit 9ed4280

Browse files
nikomatsakisflaper87
authored andcommitted
---
yaml --- r: 187640 b: refs/heads/tmp c: 40fffc9 h: refs/heads/master v: v3
1 parent 6e4b6b8 commit 9ed4280

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: d215411911c2f6e5a68a12686c930352f68d2031
37+
refs/heads/tmp: 40fffc9e3fe1664240683a2e86f2d14827417ef5
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/librustc/middle/traits/select.rs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ enum SelectionCandidate<'tcx> {
152152

153153
ObjectCandidate,
154154

155+
BuiltinObjectCandidate,
156+
155157
ErrorCandidate,
156158
}
157159

@@ -818,21 +820,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
818820
debug!("obligation self ty is {}",
819821
obligation.predicate.0.self_ty().repr(self.tcx()));
820822

823+
// User-defined copy impls are permitted, but only for
824+
// structs and enums.
821825
try!(self.assemble_candidates_from_impls(obligation, &mut candidates));
822826

827+
// For other types, we'll use the builtin rules.
823828
try!(self.assemble_builtin_bound_candidates(ty::BoundCopy,
824829
stack,
825830
&mut candidates));
826831
}
827832
Some(bound @ ty::BoundSized) => {
828-
// Sized and Copy are always automatically computed.
833+
// Sized is never implementable by end-users, it is
834+
// always automatically computed.
829835
try!(self.assemble_builtin_bound_candidates(bound, stack, &mut candidates));
830836
}
831837

832-
_ => {
833-
// For the time being, we ignore user-defined impls for builtin-bounds, other than
834-
// `Copy`.
835-
// (And unboxed candidates only apply to the Fn/FnMut/etc traits.)
838+
Some(ty::BoundSend) |
839+
Some(ty::BoundSync) |
840+
None => {
836841
try!(self.assemble_closure_candidates(obligation, &mut candidates));
837842
try!(self.assemble_fn_pointer_candidates(obligation, &mut candidates));
838843
try!(self.assemble_candidates_from_impls(obligation, &mut candidates));
@@ -1178,7 +1183,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11781183
if data.bounds.builtin_bounds.contains(&bound) {
11791184
debug!("assemble_candidates_from_object_ty: matched builtin bound, \
11801185
pushing candidate");
1181-
candidates.vec.push(BuiltinCandidate(bound));
1186+
candidates.vec.push(BuiltinObjectCandidate);
11821187
return;
11831188
}
11841189
}
@@ -1272,6 +1277,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12721277
(&ImplCandidate(..), &ParamCandidate(..)) |
12731278
(&ClosureCandidate(..), &ParamCandidate(..)) |
12741279
(&FnPointerCandidate(..), &ParamCandidate(..)) |
1280+
(&BuiltinObjectCandidate(..), &ParamCandidate(_)) |
12751281
(&BuiltinCandidate(..), &ParamCandidate(..)) => {
12761282
// We basically prefer always prefer to use a
12771283
// where-clause over another option. Where clauses
@@ -1359,7 +1365,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13591365
Ok(If(Vec::new()))
13601366
}
13611367

1362-
ty::ty_uniq(referent_ty) => { // Box<T>
1368+
ty::ty_uniq(_) => { // Box<T>
13631369
match bound {
13641370
ty::BoundCopy => {
13651371
Err(Unimplemented)
@@ -1369,26 +1375,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13691375
Ok(If(Vec::new()))
13701376
}
13711377

1372-
ty::BoundSync |
1373-
ty::BoundSend => {
1374-
Ok(If(vec![referent_ty]))
1378+
ty::BoundSync | ty::BoundSend => {
1379+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
13751380
}
13761381
}
13771382
}
13781383

13791384
ty::ty_ptr(..) => { // *const T, *mut T
13801385
match bound {
1381-
ty::BoundCopy |
1382-
ty::BoundSized => {
1386+
ty::BoundCopy | ty::BoundSized => {
13831387
Ok(If(Vec::new()))
13841388
}
13851389

1386-
ty::BoundSync |
1387-
ty::BoundSend => {
1388-
self.tcx().sess.bug(
1389-
&format!(
1390-
"raw pointers should have a negative \
1391-
impl for `Send` and `Sync`")[]);
1390+
ty::BoundSync | ty::BoundSend => {
1391+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
13921392
}
13931393
}
13941394
}
@@ -1398,7 +1398,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13981398
ty::BoundSized => {
13991399
Err(Unimplemented)
14001400
}
1401-
ty::BoundCopy | ty::BoundSync | ty::BoundSend => {
1401+
ty::BoundCopy => {
14021402
if data.bounds.builtin_bounds.contains(&bound) {
14031403
Ok(If(Vec::new()))
14041404
} else {
@@ -1417,6 +1417,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14171417
Err(Unimplemented)
14181418
}
14191419
}
1420+
ty::BoundSync | ty::BoundSend => {
1421+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
1422+
}
14201423
}
14211424
}
14221425

@@ -1441,9 +1444,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14411444
Ok(If(Vec::new()))
14421445
}
14431446

1444-
ty::BoundSync |
1445-
ty::BoundSend => {
1446-
Ok(If(vec![referent_ty]))
1447+
ty::BoundSync | ty::BoundSend => {
1448+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
14471449
}
14481450
}
14491451
}
@@ -1472,23 +1474,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14721474
}
14731475
}
14741476

1475-
ty::BoundSync |
1476-
ty::BoundSend => {
1477-
Ok(If(vec![element_ty]))
1477+
ty::BoundSync | ty::BoundSend => {
1478+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
14781479
}
14791480
}
14801481
}
14811482

14821483
ty::ty_str => {
14831484
// Equivalent to [u8]
14841485
match bound {
1485-
ty::BoundSync |
1486-
ty::BoundSend => {
1487-
Ok(If(Vec::new()))
1486+
ty::BoundSync | ty::BoundSend => {
1487+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
14881488
}
14891489

1490-
ty::BoundCopy |
1491-
ty::BoundSized => {
1490+
ty::BoundCopy | ty::BoundSized => {
14921491
Err(Unimplemented)
14931492
}
14941493
}
@@ -1576,15 +1575,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15761575
// "opened" unsized/existential type (one that has
15771576
// been dereferenced)
15781577
match bound {
1579-
ty::BoundCopy |
1580-
ty::BoundSync |
1581-
ty::BoundSend => {
1578+
ty::BoundCopy => {
15821579
Ok(If(vec!(ty)))
15831580
}
15841581

15851582
ty::BoundSized => {
15861583
Err(Unimplemented)
15871584
}
1585+
1586+
ty::BoundSync |
1587+
ty::BoundSend => {
1588+
self.tcx().sess.bug("Send/Sync shouldn't occur in builtin_bounds()");
1589+
}
15881590
}
15891591
}
15901592
ty::ty_err => {
@@ -1606,16 +1608,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16061608
{
16071609
// First check for markers and other nonsense.
16081610
match bound {
1609-
ty::BoundCopy => {
1610-
return Ok(ParameterBuiltin)
1611-
}
1611+
// Fallback to whatever user-defined impls exist in this case.
1612+
ty::BoundCopy => Ok(ParameterBuiltin),
16121613

1613-
ty::BoundSend |
1614-
ty::BoundSync |
1615-
ty::BoundSized => { }
1616-
}
1614+
// Sized if all the component types are sized.
1615+
ty::BoundSized => Ok(If(types)),
16171616

1618-
Ok(If(types))
1617+
// Shouldn't be coming through here.
1618+
ty::BoundSend | ty::BoundSync => unreachable!(),
1619+
}
16191620
}
16201621
}
16211622

@@ -1739,6 +1740,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17391740
Ok(VtableClosure(closure_def_id, substs))
17401741
}
17411742

1743+
BuiltinObjectCandidate => {
1744+
// This indicates something like `(Trait+Send) :
1745+
// Send`. In this case, we know that this holds
1746+
// because that's what the object type is telling us,
1747+
// and there's really no additional obligations to
1748+
// prove and no types in particular to unify etc.
1749+
Ok(VtableParam(Vec::new()))
1750+
}
1751+
17421752
ObjectCandidate => {
17431753
let data = self.confirm_object_candidate(obligation);
17441754
Ok(VtableObject(data))
@@ -2449,6 +2459,7 @@ impl<'tcx> Repr<'tcx> for SelectionCandidate<'tcx> {
24492459
PhantomFnCandidate => format!("PhantomFnCandidate"),
24502460
ErrorCandidate => format!("ErrorCandidate"),
24512461
BuiltinCandidate(b) => format!("BuiltinCandidate({:?})", b),
2462+
BuiltinObjectCandidate => format!("BuiltinObjectCandidate"),
24522463
ParamCandidate(ref a) => format!("ParamCandidate({})", a.repr(tcx)),
24532464
ImplCandidate(a) => format!("ImplCandidate({})", a.repr(tcx)),
24542465
DefaultImplCandidate(t) => format!("DefaultImplCandidate({:?})", t),

branches/tmp/src/librustc_typeck/coherence/overlap.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ use util::ppaux::Repr;
2525
pub fn check(tcx: &ty::ctxt) {
2626
let mut overlap = OverlapChecker { tcx: tcx };
2727
overlap.check_for_overlapping_impls();
28+
29+
// this secondary walk specifically checks for impls of defaulted
30+
// traits, for which additional overlap rules exist
2831
visit::walk_crate(&mut overlap, tcx.map.krate());
2932
}
3033

0 commit comments

Comments
 (0)