rust/src/libcore
Niko Matsakis 6e68fd09ed Implement new orphan rule that requires that impls of remote traits meet the following two criteria:
- the self type includes some local type; and,
- type parameters in the self type must be constrained by a local type.

A type parameter is called *constrained* if it appears in some type-parameter of a local type.

Here are some examples that are accepted. In all of these examples, I
assume that `Foo` is a trait defined in another crate. If `Foo` were
defined in the local crate, then all the examples would be legal.

- `impl Foo for LocalType`
- `impl<T> Foo<T> for LocalType` -- T does not appear in Self, so it is OK
- `impl<T> Foo<T> for LocalType<T>` -- T here is constrained by LocalType
- `impl<T> Foo<T> for (LocalType<T>, T)` -- T here is constrained by LocalType

Here are some illegal examples (again, these examples assume that
`Foo` is not local to the current crate):

- `impl Foo for int` -- the Self type is not local
- `impl<T> Foo for T` -- T appears in Self unconstrained by a local type
- `impl<T> Foo for (LocalType, T)` -- T appears in Self unconstrained by a local type

This is a [breaking-change]. For the time being, you can opt out of
the new rules by placing `#[old_orphan_check]` on the trait (and
enabling the feature gate where the trait is defined). Longer term,
you should restructure your traits to avoid the problem. Usually this
means changing the order of parameters so that the "central" type
parameter is in the `Self` position.

As an example of that refactoring, consider the `BorrowFrom` trait:

```rust
pub trait BorrowFrom<Sized? Owned> for Sized? {
    fn borrow_from(owned: &Owned) -> &Self;
}
```

As defined, this trait is commonly implemented for custom pointer
types, such as `Arc`. Those impls follow the pattern:

```rust
impl<T> BorrowFrom<Arc<T>> for T {...}
```

Unfortunately, this impl is illegal because the self type `T` is not
local to the current crate. Therefore, we are going to change the order of the parameters,
so that `BorrowFrom` becomes `Borrow`:

```rust
pub trait Borrow<Sized? Borrowed> for Sized? {
    fn borrow_from(owned: &Self) -> &Borrowed;
}
```

Now the `Arc` impl is written:

```rust
impl<T> Borrow<T> for Arc<T> { ... }
```

This impl is legal because the self type (`Arc<T>`) is local.
2015-01-05 17:17:26 -05:00
..
fmt sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
hash sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
num Remove deprecated functionality 2015-01-03 23:43:57 -08:00
str Remove deprecated functionality 2015-01-03 23:43:57 -08:00
any.rs remove Any[Mut]RefExt traits in favor of impl Any 2015-01-03 23:01:33 -05:00
array.rs core: use assoc types in Deref[Mut] 2015-01-02 12:19:59 -05:00
atomic.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
borrow.rs Implement new orphan rule that requires that impls of remote traits meet the following two criteria: 2015-01-05 17:17:26 -05:00
cell.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
char.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
clone.rs Fix fallout from change, adding explicit Sized annotations where necessary. 2015-01-02 12:06:59 -05:00
cmp.rs Implement new orphan rule that requires that impls of remote traits meet the following two criteria: 2015-01-05 17:17:26 -05:00
default.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
finally.rs libcore: fix fallout in doc tests 2014-12-13 17:03:46 -05:00
intrinsics.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
iter.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
kinds.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
lib.rs Don't expose NonZero through libstd. 2014-12-28 19:40:48 -05:00
macros.rs Register new snapshots 2014-12-30 15:04:43 -08:00
mem.rs rollup merge of #19942: steveklabnik/doc_std_mem 2014-12-17 11:50:31 -08:00
nonzero.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
ops.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
option.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
panicking.rs Register new snapshots 2014-12-30 15:04:43 -08:00
prelude.rs sed -i -s 's/\bmod,/self,/g' **/*.rs 2015-01-03 22:42:21 -05:00
ptr.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
raw.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
result.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
simd.rs sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rs 2015-01-03 22:54:18 -05:00
slice.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
tuple.rs Remove deprecated functionality 2015-01-03 23:43:57 -08:00
ty.rs std: Stabilize unit, bool, ty, tuple, arc, any 2014-07-26 13:12:20 -07:00