summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-types/associated-types-coherence-failure.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/associated-types/associated-types-coherence-failure.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/associated-types/associated-types-coherence-failure.rs')
-rw-r--r--src/test/ui/associated-types/associated-types-coherence-failure.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/ui/associated-types/associated-types-coherence-failure.rs b/src/test/ui/associated-types/associated-types-coherence-failure.rs
new file mode 100644
index 000000000..c33f2ac96
--- /dev/null
+++ b/src/test/ui/associated-types/associated-types-coherence-failure.rs
@@ -0,0 +1,49 @@
+// Test that coherence detects overlap when some of the types in the
+// impls are projections of associated type. Issue #20624.
+
+use std::marker::PhantomData;
+use std::ops::Deref;
+
+pub struct Cow<'a, B: ?Sized>(PhantomData<(&'a (),B)>);
+
+/// 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 <B as ToOwned>::Owned where B: ToOwned {
+ fn into_cow(self) -> Cow<'a, B> {
+ Cow(PhantomData)
+ }
+}
+
+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 &'a B where B: ToOwned {
+//~^ ERROR E0119
+ fn into_cow(self) -> Cow<'a, B> {
+ Cow(PhantomData)
+ }
+}
+
+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;
+
+ /// Creates owned data from borrowed data, usually by copying.
+ fn to_owned(&self) -> Self::Owned;
+}
+
+
+fn main() {}