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:
commit
51085b21ce
5 changed files with 24 additions and 30 deletions
|
@ -208,6 +208,20 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
tcx.struct_tail_raw(ty, |ty| tcx.normalize_erasing_regions(typing_env, ty), || {})
|
||||
}
|
||||
|
||||
/// Returns true if a type has metadata.
|
||||
pub fn type_has_metadata(self, ty: Ty<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
|
||||
if ty.is_sized(self, typing_env) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let tail = self.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),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the deeply last field of nested structures, or the same type if
|
||||
/// not a structure at all. Corresponds to the only possible unsized field,
|
||||
/// and its type can be used to determine unsizing strategy.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue