From a3b7a21268edecc69267fd2b641b22d5bb7844b2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 1 Dec 2018 02:07:50 -0800 Subject: [PATCH] Improve the unstable book example for `#[marker]` The previous one didn't actually use the Display&Debug bounds in any way, so I think this one is a bit more meaningful. --- .../src/language-features/marker-trait-attr.md | 14 ++++++++------ 1 file 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 9dd7b6fae9bc6..dedc7d3015d4d 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 CheapToClone for T {} -impl MyMarker for T {} -impl MyMarker for T {} +// These could potentally overlap with the blanket implementation above, +// so are only allowed because CheapToClone is a marker trait. +impl CheapToClone for (T, U) {} +impl CheapToClone for std::ops::Range {} -fn foo(t: T) -> T { - t +fn cheap_clone(t: T) -> T { + t.clone() } ```