File tree 1 file changed +33
-0
lines changed
src/doc/unstable-book/src/language-features
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ` marker_trait_attr `
2
+
3
+ The tracking issue for this feature is: [ #29864 ]
4
+
5
+ [ #29864 ] : https://github.com/rust-lang/rust/issues/29864
6
+
7
+ ------------------------
8
+
9
+ Normally, Rust keeps you from adding trait implementations that could
10
+ overlap with each other, as it would be ambiguous which to use. This
11
+ feature, however, carves out an exception to that rule: a trait can
12
+ opt-in to having overlapping implementations, at the cost that those
13
+ implementations are not allowed to override anything (and thus the
14
+ trait itself cannot have any associated items, as they're pointless
15
+ when they'd need to do the same thing for every type anyway).
16
+
17
+ ``` rust
18
+ #![feature(marker_trait_attr)]
19
+
20
+ use std :: fmt :: {Debug , Display };
21
+
22
+ #[marker] trait MyMarker {}
23
+
24
+ impl <T : Debug > MyMarker for T {}
25
+ impl <T : Display > MyMarker for T {}
26
+
27
+ fn foo <T : MyMarker >(t : T ) -> T {
28
+ t
29
+ }
30
+ ```
31
+
32
+ This is expected to replace the unstable ` overlapping_marker_traits `
33
+ feature, which applied to all empty traits (without needing an opt-in).
You can’t perform that action at this time.
0 commit comments