Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the unstable book example for #[marker] trait #56402

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/doc/unstable-book/src/language-features/marker-trait-attr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
```

Expand Down