diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-12-18 15:24:06 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-12-18 15:24:06 +0000 |
| commit | c4567c18411bbe6d5a4510ba6ade4da06abc71ac (patch) | |
| tree | c29c7d322d44f5af62577d3f35e6ebc57e951dd9 | |
| parent | 697aa0a320653d004e5a477a8231320974d29785 (diff) | |
| download | rust-c4567c18411bbe6d5a4510ba6ade4da06abc71ac.tar.gz rust-c4567c18411bbe6d5a4510ba6ade4da06abc71ac.zip | |
Implement has_ptr_meta without computing type layout
This matches type_has_metadata in cg_ssa and doesn't require computing the layout of the type. It is also a bit faster.
| -rw-r--r-- | src/common.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/common.rs b/src/common.rs index 63562d33508..bd19a7ed059 100644 --- a/src/common.rs +++ b/src/common.rs @@ -98,11 +98,15 @@ fn clif_pair_type_from_ty<'tcx>( /// Is a pointer to this type a fat ptr? pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { - let ptr_ty = Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not }); - match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi { - Abi::Scalar(_) => false, - Abi::ScalarPair(_, _) => true, - abi => unreachable!("Abi of ptr to {:?} is {:?}???", ty, abi), + if ty.is_sized(tcx, ParamEnv::reveal_all()) { + return false; + } + + let tail = tcx.struct_tail_erasing_lifetimes(ty, ParamEnv::reveal_all()); + match tail.kind() { + ty::Foreign(..) => false, + ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, + _ => bug!("unexpected unsized tail: {:?}", tail), } } |
