-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add marker_trait_attr to the unstable book
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/doc/unstable-book/src/language-features/marker-trait-attr.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T: Debug> MyMarker for T {} | ||
impl<T: Display> MyMarker for T {} | ||
|
||
fn foo<T: MyMarker>(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). |