]> git.proxmox.com Git - rustc.git/blobdiff - src/test/ui/traits/reservation-impl/ok.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / traits / reservation-impl / ok.rs
diff --git a/src/test/ui/traits/reservation-impl/ok.rs b/src/test/ui/traits/reservation-impl/ok.rs
new file mode 100644 (file)
index 0000000..611c8d8
--- /dev/null
@@ -0,0 +1,28 @@
+// run-pass
+
+// rpass test for reservation impls. Not 100% required because `From` uses them,
+// but still.
+
+#![feature(rustc_attrs)]
+
+use std::mem;
+
+trait MyTrait<S> {
+    fn foo(&self, s: S) -> usize;
+}
+
+#[rustc_reservation_impl = "foo"]
+impl<T> MyTrait<u64> for T {
+    fn foo(&self, _x: u64) -> usize { 0 }
+}
+
+// reservation impls don't create coherence conflicts, even with
+// non-chain overlap.
+impl<S> MyTrait<S> for u32 {
+    fn foo(&self, _x: S) -> usize { mem::size_of::<S>() }
+}
+
+fn main() {
+    // ...and the non-reservation impl gets picked.XS
+    assert_eq!(0u32.foo(0u64), mem::size_of::<u64>());
+}