about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-01-08 06:58:41 -0500
committerNiko Matsakis <niko@alum.mit.edu>2015-01-08 11:16:06 -0500
commitbb0c8ef373317843c1df7e9110e4bd0978ff47eb (patch)
treead4dd3af62ba2a048a6df3bc2a4870bd13161f57 /src/test
parent2f99a41fe1a27a48e96bc2616ec9faa6de924386 (diff)
downloadrust-bb0c8ef373317843c1df7e9110e4bd0978ff47eb.tar.gz
rust-bb0c8ef373317843c1df7e9110e4bd0978ff47eb.zip
Normalize types in impls, add test for coherence failure.
Fixes #20624.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/associated-types-coherence-failure.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/compile-fail/associated-types-coherence-failure.rs b/src/test/compile-fail/associated-types-coherence-failure.rs
new file mode 100644
index 00000000000..95a68dd6698
--- /dev/null
+++ b/src/test/compile-fail/associated-types-coherence-failure.rs
@@ -0,0 +1,59 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that coherence detects overlap when some of the types in the
+// impls are projections of associated type. Issue #20624.
+
+use std::ops::Deref;
+
+pub struct Cow<'a, B: ?Sized>;
+
+/// Trait for moving into a `Cow`
+pub trait IntoCow<'a, B: ?Sized> {
+    /// Moves `self` into `Cow`
+    fn into_cow(self) -> Cow<'a, B>;
+}
+
+impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
+//~^ ERROR E0119
+    fn into_cow(self) -> Cow<'a, B> {
+        self
+    }
+}
+
+impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
+//~^ ERROR E0119
+    fn into_cow(self) -> Cow<'a, B> {
+        Cow
+    }
+}
+
+impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
+    fn into_cow(self) -> Cow<'a, B> {
+        Cow
+    }
+}
+
+impl ToOwned for u8 {
+    type Owned = &'static u8;
+    fn to_owned(&self) -> &'static u8 { panic!() }
+}
+
+/// A generalization of Clone to borrowed data.
+pub trait ToOwned {
+    type Owned;
+
+    /// Create owned data from borrowed data, usually by copying.
+    fn to_owned(&self) -> Self::Owned;
+}
+
+
+fn main() {}
+