Skip to content

Commit 388d3ce

Browse files
committed
refactor: use the default implementation of clone_from in impl const Clone
`Clone::clone_from` gained `#[default_method_body_is_const]` in [rust-lang/rust#91804][1]. n.b. `vec.rs` is shared by `r3_core` and `r3_kernel` (via a symbolic link), hence the lack of a scope in the commit message headline. [1]: rust-lang/rust#91804
1 parent 79e4d28 commit 388d3ce

File tree

5 files changed

+0
-49
lines changed

5 files changed

+0
-49
lines changed

doc/toolchain_limitations.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -632,30 +632,6 @@ const _: () = assert!(matches!((2..4).next(), Some(2)));
632632
```
633633

634634

635-
### `[tag:clone_from_default]` `Clone::clone_from` lacks `#[default_method_body_is_const]`
636-
637-
When implementing `const Clone`, you can't use the provided implementation of `Clone::clone_from`.
638-
639-
```rust
640-
#![feature(const_trait_impl)]
641-
#![feature(const_mut_refs)]
642-
struct A;
643-
impl const Clone for A {
644-
fn clone(&self) -> Self { A }
645-
fn clone_from(&mut self, source: &Self) {}
646-
}
647-
```
648-
649-
```rust,compile_fail
650-
#![feature(const_trait_impl)]
651-
struct A;
652-
impl const Clone for A {
653-
fn clone(&self) -> Self { A }
654-
// error: const trait implementations may not use non-const default functions
655-
}
656-
```
657-
658-
659635
### `[tag:iterator_const_default]` `Iterator`'s methods lack `#[default_method_body_is_const]`
660636

661637
Implementing `const Iterator` requires you to implement all of its methods, which is impossible to do correctly.

src/r3_core/src/bind.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ impl<System, T> const Clone for Bind<'_, System, T> {
235235
fn clone(&self) -> Self {
236236
*self
237237
}
238-
239-
// `clone_from` needed due to [ref:clone_from_default]
240-
#[inline]
241-
fn clone_from(&mut self, source: &Self) {
242-
*self = *source;
243-
}
244238
}
245239

246240
/// A [binder][1] that gives `&T` to a bound function.
@@ -296,12 +290,6 @@ impl<System, T> const Clone for BindRef<System, T> {
296290
fn clone(&self) -> Self {
297291
*self
298292
}
299-
300-
// `clone_from` needed due to [ref:clone_from_default]
301-
#[inline]
302-
fn clone_from(&mut self, source: &Self) {
303-
*self = *source;
304-
}
305293
}
306294

307295
// `BindDefiner` doesn't contain `T`, so this `impl` must use a concrete `T`

src/r3_core/src/utils/alloc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ impl const Clone for ConstAllocator {
193193
ref_count: self.ref_count,
194194
}
195195
}
196-
197-
fn clone_from(&mut self, source: &Self) {
198-
*self = source.clone();
199-
}
200196
}
201197

202198
impl const Drop for ConstAllocator {

src/r3_core/src/utils/freeze.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ impl<T: Copy> const Clone for Frozen<T> {
8282
// Don't use `T as Clone` because it could expose interior mutability.
8383
*self
8484
}
85-
86-
#[inline]
87-
fn clone_from(&mut self, source: &Self) {
88-
*self = *source;
89-
}
9085
}
9186

9287
impl<T: Copy + ~const fmt::Debug> const fmt::Debug for Frozen<T> {

src/r3_core/src/utils/vec.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ impl<T: ~const Clone + ~const Drop> const Clone for ComptimeVec<T> {
3535
}
3636
self.map(clone_shim)
3737
}
38-
39-
fn clone_from(&mut self, source: &Self) {
40-
*self = source.clone();
41-
}
4238
}
4339

4440
impl<T> const Drop for ComptimeVec<T>

0 commit comments

Comments
 (0)