about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-12-03 18:07:10 +0800
committerGitHub <noreply@github.com>2018-12-03 18:07:10 +0800
commit65e67025c89bcae863f997a7a92da6ebeeb33cda (patch)
treede50479af982c0860fb2f22bb9cd6ae27c9bd6cf
parent2cbcd36ca90ba8442a660912d5d52720c94dadea (diff)
parenta3b7a21268edecc69267fd2b641b22d5bb7844b2 (diff)
downloadrust-65e67025c89bcae863f997a7a92da6ebeeb33cda.tar.gz
rust-65e67025c89bcae863f997a7a92da6ebeeb33cda.zip
Rollup merge of #56402 - scottmcm:better-marker-trait-example, r=Centril
Improve the unstable book example for #[marker] trait

The previous one didn't actually use the Display&Debug bounds in any way, so I think this one is a bit more meaningful.
-rw-r--r--src/doc/unstable-book/src/language-features/marker-trait-attr.md14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/doc/unstable-book/src/language-features/marker-trait-attr.md b/src/doc/unstable-book/src/language-features/marker-trait-attr.md
index 9dd7b6fae9b..dedc7d3015d 100644
--- a/src/doc/unstable-book/src/language-features/marker-trait-attr.md
+++ b/src/doc/unstable-book/src/language-features/marker-trait-attr.md
@@ -17,15 +17,17 @@ when they'd need to do the same thing for every type anyway).
 ```rust
 #![feature(marker_trait_attr)]
 
-use std::fmt::{Debug, Display};
+#[marker] trait CheapToClone: Clone {}
 
-#[marker] trait MyMarker {}
+impl<T: Copy> CheapToClone for T {}
 
-impl<T: Debug> MyMarker for T {}
-impl<T: Display> MyMarker for T {}
+// These could potentally overlap with the blanket implementation above,
+// so are only allowed because CheapToClone is a marker trait.
+impl<T: CheapToClone, U: CheapToClone> CheapToClone for (T, U) {}
+impl<T: CheapToClone> CheapToClone for std::ops::Range<T> {}
 
-fn foo<T: MyMarker>(t: T) -> T {
-    t
+fn cheap_clone<T: CheapToClone>(t: T) -> T {
+    t.clone()
 }
 ```