1
Fork 0

Rollup merge of #128170 - saethlin:clone-fn, r=compiler-errors

Make Clone::clone a lang item

I want to absorb all the logic for picking whether an Instance is LocalCopy or GloballyShared into one place. As part of this, I wanted to identify Clone shims inside `cross_crate_inlinable` and found that rather tricky. `@compiler-errors` suggested that I add a lang item for `Clone::clone` because that would produce other cleanups in the compiler.

That sounds good to me, but I have looked and I've only been able to find one.

r? compiler-errors
This commit is contained in:
Trevor Gross 2024-07-26 02:20:31 -04:00 committed by GitHub
commit 97eade42f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 2 deletions

View file

@ -3,6 +3,7 @@
use crate::simplify::simplify_duplicate_switch_targets;
use crate::take_array;
use rustc_ast::attr;
use rustc_hir::LangItem;
use rustc_middle::bug;
use rustc_middle::mir::*;
use rustc_middle::ty::layout;
@ -271,8 +272,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 !self.tcx.is_lang_item(fn_def_id, LangItem::CloneFn) {
return;
}