]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-coherence-failure.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / associated-types / associated-types-coherence-failure.rs
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
14 use std::marker::PhantomData;
15 use std::ops::Deref;
16
17 pub struct Cow<'a, B: ?Sized>(PhantomData<(&'a (),B)>);
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
25 impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
26     fn into_cow(self) -> Cow<'a, B> {
27         Cow(PhantomData)
28     }
29 }
30
31 impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
32 //~^ ERROR E0119
33     fn into_cow(self) -> Cow<'a, B> {
34         self
35     }
36 }
37
38 impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
39 //~^ ERROR E0119
40     fn into_cow(self) -> Cow<'a, B> {
41         Cow(PhantomData)
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() {}