Skip to content

Commit f2d28fe

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

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
@@ -8,16 +8,6 @@ LL | #[derive(Copy, Clone)]
88
|
99
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
1010

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

31-
error: aborting due to 3 previous errors
21+
error: aborting due to 2 previous errors
3222

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

0 commit comments

Comments
 (0)