]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // Test that coherence detects overlap when some of the types in the | |
12 | // impls are projections of associated type. Issue #20624. | |
13 | ||
85aaf69f | 14 | use std::marker::PhantomData; |
1a4d82fc JJ |
15 | use std::ops::Deref; |
16 | ||
85aaf69f | 17 | pub struct Cow<'a, B: ?Sized>(PhantomData<(&'a (),B)>); |
1a4d82fc JJ |
18 | |
19 | /// Trait for moving into a `Cow` | |
20 | pub trait IntoCow<'a, B: ?Sized> { | |
21 | /// Moves `self` into `Cow` | |
22 | fn into_cow(self) -> Cow<'a, B>; | |
23 | } | |
24 | ||
54a0048b | 25 | impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned { |
1a4d82fc | 26 | fn into_cow(self) -> Cow<'a, B> { |
54a0048b | 27 | Cow(PhantomData) |
1a4d82fc JJ |
28 | } |
29 | } | |
30 | ||
54a0048b | 31 | impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned { |
1a4d82fc JJ |
32 | //~^ ERROR E0119 |
33 | fn into_cow(self) -> Cow<'a, B> { | |
54a0048b | 34 | self |
1a4d82fc JJ |
35 | } |
36 | } | |
37 | ||
38 | impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned { | |
54a0048b | 39 | //~^ ERROR E0119 |
1a4d82fc | 40 | fn into_cow(self) -> Cow<'a, B> { |
9cc50fc6 | 41 | Cow(PhantomData) |
1a4d82fc JJ |
42 | } |
43 | } | |
44 | ||
45 | impl ToOwned for u8 { | |
46 | type Owned = &'static u8; | |
47 | fn to_owned(&self) -> &'static u8 { panic!() } | |
48 | } | |
49 | ||
50 | /// A generalization of Clone to borrowed data. | |
51 | pub trait ToOwned { | |
52 | type Owned; | |
53 | ||
54 | /// Create owned data from borrowed data, usually by copying. | |
55 | fn to_owned(&self) -> Self::Owned; | |
56 | } | |
57 | ||
58 | ||
59 | fn main() {} |