]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/associated-types-coherence-failure.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / compile-fail / 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 Cow<'a, B> where B: ToOwned {
26 //~^ ERROR E0119
27 fn into_cow(self) -> Cow<'a, B> {
28 self
29 }
30 }
31
32 impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
33 //~^ ERROR E0119
34 fn into_cow(self) -> Cow<'a, B> {
35 Cow
36 }
37 }
38
39 impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
40 fn into_cow(self) -> Cow<'a, B> {
41 Cow
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() {}