Skip to content

Commit 5ac92d5

Browse files
committed
Make Clone::clone a lang item
1 parent 92c6c03 commit 5ac92d5

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

compiler/rustc_hir/src/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ language_item_table! {
162162
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;
163163
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);
164164
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
165+
CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
165166
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
166167
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
167168
/// The associated item of the `DiscriminantKind` trait.

compiler/rustc_mir_transform/src/instsimplify.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
271271
return;
272272
}
273273

274-
let trait_def_id = self.tcx.trait_of_item(fn_def_id);
275-
if trait_def_id.is_none() || trait_def_id != self.tcx.lang_items().clone_trait() {
274+
if Some(fn_def_id) != self.tcx.lang_items().clone_fn() {
276275
return;
277276
}
278277

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ symbols! {
557557
clobber_abi,
558558
clone,
559559
clone_closures,
560+
clone_fn,
560561
clone_from,
561562
closure,
562563
closure_lifetime_binder,

library/core/src/clone.rs

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ pub trait Clone: Sized {
160160
/// ```
161161
#[stable(feature = "rust1", since = "1.0.0")]
162162
#[must_use = "cloning is often expensive and is not expected to have side effects"]
163+
// Clone::clone is special because the compiler generates MIR to implement it for some types.
164+
// See InstanceKind::CloneShim.
165+
#[cfg_attr(not(bootstrap), lang = "clone_fn")]
163166
fn clone(&self) -> Self;
164167

165168
/// Performs copy-assignment from `source`.

0 commit comments

Comments
 (0)