diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-02-26 04:15:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-26 04:15:05 +0100 |
| commit | 51085b21ce50996a30c3c19c0b8b7be48e44e2ca (patch) | |
| tree | ebd2d266507ab553f9fdaaa4c1522ee62e92ac76 /compiler/rustc_middle/src/ty | |
| parent | f1923142c3b969a1b3e1ee6173d0407b186e8627 (diff) | |
| parent | 5afa6a111bcf8552b8de15d1aec060580add640f (diff) | |
| download | rust-51085b21ce50996a30c3c19c0b8b7be48e44e2ca.tar.gz rust-51085b21ce50996a30c3c19c0b8b7be48e44e2ca.zip | |
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`.
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index c153f6bb7d7..4d917963cd6 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -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. |
