diff options
| author | bors <bors@rust-lang.org> | 2018-02-16 00:03:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-02-16 00:03:10 +0000 |
| commit | efda9bae8788fdc68ea1d05be3c5b66d3e291961 (patch) | |
| tree | 424f318bc35d961925a61831e2a30eba54fc2163 /src/libcore | |
| parent | 1670a532dd769763f1d6ad9e5d624ec31361a098 (diff) | |
| parent | 220bb22e1b621ad5a10a44080e3e1872d99f3e9f (diff) | |
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
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter/mod.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index d929d1d65a9..1a2da83429a 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -595,15 +595,15 @@ impl<'a, I, T: 'a> FusedIterator for Cloned<I> {} #[doc(hidden)] -default unsafe impl<'a, I, T: 'a> TrustedRandomAccess for Cloned<I> +unsafe impl<'a, I, T: 'a> TrustedRandomAccess for Cloned<I> where I: TrustedRandomAccess<Item=&'a T>, T: Clone { - unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item { + default unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item { self.it.get_unchecked(i).clone() } #[inline] - fn may_have_side_effect() -> bool { true } + default fn may_have_side_effect() -> bool { true } } #[doc(hidden)] |
