]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-coherence-failure.rs
Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup
[rust.git] / src / test / ui / associated-types / associated-types-coherence-failure.rs
1 // Test that coherence detects overlap when some of the types in the
2 // impls are projections of associated type. Issue #20624.
3
4 use std::marker::PhantomData;
5 use std::ops::Deref;
6
7 pub struct Cow<'a, B: ?Sized>(PhantomData<(&'a (),B)>);
8
9 /// Trait for moving into a `Cow`
10 pub trait IntoCow<'a, B: ?Sized> {
11     /// Moves `self` into `Cow`
12     fn into_cow(self) -> Cow<'a, B>;
13 }
14
15 impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
16     fn into_cow(self) -> Cow<'a, B> {
17         Cow(PhantomData)
18     }
19 }
20
21 impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
22 //~^ ERROR E0119
23     fn into_cow(self) -> Cow<'a, B> {
24         self
25     }
26 }
27
28 impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
29 //~^ ERROR E0119
30     fn into_cow(self) -> Cow<'a, B> {
31         Cow(PhantomData)
32     }
33 }
34
35 impl ToOwned for u8 {
36     type Owned = &'static u8;
37     fn to_owned(&self) -> &'static u8 { panic!() }
38 }
39
40 /// A generalization of Clone to borrowed data.
41 pub trait ToOwned {
42     type Owned;
43
44     /// Creates owned data from borrowed data, usually by copying.
45     fn to_owned(&self) -> Self::Owned;
46 }
47
48
49 fn main() {}