Skip to content

Commit ba97294

Browse files
committed
make TrivialClone a #[marker]-trait to keep it from appearing in error messages
1 parent 431ee82 commit ba97294

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

library/core/src/clone.rs

+4
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ pub trait Clone: Sized {
200200
// its invariant holds whenever `Clone` is implemented, even if the actual
201201
// `TrivialClone` bound would not be satisfied because of lifetime bounds.
202202
#[rustc_unsafe_specialization_marker]
203+
// If `#[derive(Clone, Clone, Copy)]` is written, there will be multiple
204+
// implementations of `TrivialClone`. To keep it from appearing in error
205+
// messages, make it a `#[marker]` trait.
206+
#[marker]
203207
pub unsafe trait TrivialClone: Clone {}
204208

205209
/// Derive macro generating an impl of the trait `Clone`.

tests/ui/derives/duplicate-derive-copy-clone-diagnostics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#[derive(Copy, Clone)]
77
//~^ ERROR conflicting implementations of trait `Clone` for type `E`
88
//~| ERROR conflicting implementations of trait `Copy` for type `E`
9-
//~| ERROR conflicting implementations of trait `TrivialClone` for type `E`
109
enum E {}
1110

1211
fn main() {}

tests/ui/derives/duplicate-derive-copy-clone-diagnostics.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ LL | #[derive(Copy, Clone)]
66
LL | #[derive(Copy, Clone)]
77
| ^^^^ conflicting implementation for `E`
88

9-
error[E0119]: conflicting implementations of trait `TrivialClone` for type `E`
10-
--> $DIR/duplicate-derive-copy-clone-diagnostics.rs:6:16
11-
|
12-
LL | #[derive(Copy, Clone)]
13-
| ----- first implementation here
14-
LL | #[derive(Copy, Clone)]
15-
| ^^^^^ conflicting implementation for `E`
16-
|
17-
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
18-
199
error[E0119]: conflicting implementations of trait `Clone` for type `E`
2010
--> $DIR/duplicate-derive-copy-clone-diagnostics.rs:6:16
2111
|
@@ -24,6 +14,6 @@ LL | #[derive(Copy, Clone)]
2414
LL | #[derive(Copy, Clone)]
2515
| ^^^^^ conflicting implementation for `E`
2616

27-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2818

2919
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)