1
Fork 0

Rollup merge of #137601 - davidtwco:deduplicate-type-has-metadata, r=fmease,bjorn3

ssa/mono: deduplicate `type_has_metadata`

The implementation of the `type_has_metadata` function is duplicated in `rustc_codegen_ssa` and `rustc_monomorphize`, so move this to `rustc_middle`.
This commit is contained in:
León Orell Valerian Liehr 2025-02-26 04:15:05 +01:00 committed by GitHub
commit 51085b21ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 30 deletions

View file

@ -1043,18 +1043,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
) -> (Ty<'tcx>, Ty<'tcx>) {
let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| {
let typing_env = ty::TypingEnv::fully_monomorphized();
let type_has_metadata = |ty: Ty<'tcx>| -> bool {
if ty.is_sized(tcx.tcx, typing_env) {
return false;
}
let tail = tcx.struct_tail_for_codegen(ty, typing_env);
match tail.kind() {
ty::Foreign(..) => false,
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
_ => bug!("unexpected unsized tail: {:?}", tail),
}
};
if type_has_metadata(inner_source) {
if tcx.type_has_metadata(inner_source, typing_env) {
(inner_source, inner_target)
} else {
tcx.struct_lockstep_tails_for_codegen(inner_source, inner_target, typing_env)