From 3932249249fa56dd1515c487a5a9eb02cb631775 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 19 Sep 2018 22:41:07 -0700 Subject: [PATCH] Add marker_trait_attr to the unstable book --- .../language-features/marker-trait-attr.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/doc/unstable-book/src/language-features/marker-trait-attr.md 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 new file mode 100644 index 00000000000..9dd7b6fae9b --- /dev/null +++ b/src/doc/unstable-book/src/language-features/marker-trait-attr.md @@ -0,0 +1,33 @@ +# `marker_trait_attr` + +The tracking issue for this feature is: [#29864] + +[#29864]: https://github.com/rust-lang/rust/issues/29864 + +------------------------ + +Normally, Rust keeps you from adding trait implementations that could +overlap with each other, as it would be ambiguous which to use. This +feature, however, carves out an exception to that rule: a trait can +opt-in to having overlapping implementations, at the cost that those +implementations are not allowed to override anything (and thus the +trait itself cannot have any associated items, as they're pointless +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 MyMarker {} + +impl MyMarker for T {} +impl MyMarker for T {} + +fn foo(t: T) -> T { + t +} +``` + +This is expected to replace the unstable `overlapping_marker_traits` +feature, which applied to all empty traits (without needing an opt-in).