Skip to content

Commit

Permalink
Make Clone::clone a lang item
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Jul 25, 2024
1 parent 92c6c03 commit 500db24
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ language_item_table! {
EffectsIntersectionOutput, sym::EffectsIntersectionOutput, effects_intersection_output, Target::AssocTy, GenericRequirement::None;
EffectsCompat, sym::EffectsCompat, effects_compat, Target::Trait, GenericRequirement::Exact(1);
EffectsTyCompat, sym::EffectsTyCompat, effects_ty_compat, Target::Trait, GenericRequirement::Exact(1);
CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
}

pub enum GenericRequirement {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
return;
}

let trait_def_id = self.tcx.trait_of_item(fn_def_id);
if trait_def_id.is_none() || trait_def_id != self.tcx.lang_items().clone_trait() {
if Some(fn_def_id) != self.tcx.lang_items().clone_fn() {
return;
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ symbols! {
clobber_abi,
clone,
clone_closures,
clone_fn,
clone_from,
closure,
closure_lifetime_binder,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub trait Clone: Sized {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "cloning is often expensive and is not expected to have side effects"]
#[cfg_attr(not(bootstrap), lang = "clone_fn")]
fn clone(&self) -> Self;

/// Performs copy-assignment from `source`.
Expand Down

0 comments on commit 500db24

Please sign in to comment.