Skip to content

Commit 4ede578

Browse files
Rollup merge of rust-lang#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.
2 parents 964d722 + a3b7a21 commit 4ede578

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/doc/unstable-book/src/language-features/marker-trait-attr.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ when they'd need to do the same thing for every type anyway).
1717
```rust
1818
#![feature(marker_trait_attr)]
1919

20-
use std::fmt::{Debug, Display};
20+
#[marker] trait CheapToClone: Clone {}
2121

22-
#[marker] trait MyMarker {}
22+
impl<T: Copy> CheapToClone for T {}
2323

24-
impl<T: Debug> MyMarker for T {}
25-
impl<T: Display> MyMarker for T {}
24+
// These could potentally overlap with the blanket implementation above,
25+
// so are only allowed because CheapToClone is a marker trait.
26+
impl<T: CheapToClone, U: CheapToClone> CheapToClone for (T, U) {}
27+
impl<T: CheapToClone> CheapToClone for std::ops::Range<T> {}
2628

27-
fn foo<T: MyMarker>(t: T) -> T {
28-
t
29+
fn cheap_clone<T: CheapToClone>(t: T) -> T {
30+
t.clone()
2931
}
3032
```
3133

0 commit comments

Comments
 (0)