]> git.lizzy.rs Git - rust.git/commit
Auto merge of #45404 - giannicic:defaultimpl2, r=nikomatsakis
authorbors <bors@rust-lang.org>
Fri, 16 Feb 2018 00:03:10 +0000 (00:03 +0000)
committerbors <bors@rust-lang.org>
Fri, 16 Feb 2018 00:03:10 +0000 (00:03 +0000)
commitefda9bae8788fdc68ea1d05be3c5b66d3e291961
tree424f318bc35d961925a61831e2a30eba54fc2163
parent1670a532dd769763f1d6ad9e5d624ec31361a098
parent220bb22e1b621ad5a10a44080e3e1872d99f3e9f
Auto merge of #45404 - giannicic:defaultimpl2, r=nikomatsakis

#37653 support `default impl` for specialization

this commit implements the second part of the `default impl` feature:

>  - a `default impl` need not include all items from the trait
>  - a `default impl` alone does not mean that a type implements the trait

The first point allows rustc to compile and run something like this:

```
trait Foo {
    fn foo_one(&self) -> &'static str;
    fn foo_two(&self) -> &'static str;
}

default impl<T> Foo for T {
    fn foo_one(&self) -> &'static str {
        "generic"
    }
}

struct MyStruct;

fn  main() {
    assert!(MyStruct.foo_one() == "generic");
}
```

but it shows a proper error if trying to call `MyStruct.foo_two()`

The second point allows a `default impl` to be considered as not implementing the `Trait` if it doesn't implement all the trait items.
The tests provided (in the compile-fail section) should cover all the possible trait resolutions.
Let me know if some tests is missed.

See [referenced ](https://github.com/rust-lang/rust/issues/37653) issue for further info

r? @nikomatsakis
src/libcore/iter/mod.rs
src/librustc_typeck/check/mod.rs