1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 pub use self::Integer::*;
12 pub use self::Primitive::*;
17 use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
21 /// Parsed [Data layout](http://llvm.org/docs/LangRef.html#data-layout)
22 /// for a target, which contains everything needed to compute layouts.
23 pub struct TargetDataLayout {
30 pub i128_align: Align,
33 pub pointer_size: Size,
34 pub pointer_align: Align,
35 pub aggregate_align: Align,
37 /// Alignments for vector types.
38 pub vector_align: Vec<(Size, Align)>
41 impl Default for TargetDataLayout {
42 /// Creates an instance of `TargetDataLayout`.
43 fn default() -> TargetDataLayout {
46 i1_align: Align::from_bits(8, 8).unwrap(),
47 i8_align: Align::from_bits(8, 8).unwrap(),
48 i16_align: Align::from_bits(16, 16).unwrap(),
49 i32_align: Align::from_bits(32, 32).unwrap(),
50 i64_align: Align::from_bits(32, 64).unwrap(),
51 i128_align: Align::from_bits(32, 64).unwrap(),
52 f32_align: Align::from_bits(32, 32).unwrap(),
53 f64_align: Align::from_bits(64, 64).unwrap(),
54 pointer_size: Size::from_bits(64),
55 pointer_align: Align::from_bits(64, 64).unwrap(),
56 aggregate_align: Align::from_bits(0, 64).unwrap(),
58 (Size::from_bits(64), Align::from_bits(64, 64).unwrap()),
59 (Size::from_bits(128), Align::from_bits(128, 128).unwrap())
65 impl TargetDataLayout {
66 pub fn parse(target: &Target) -> Result<TargetDataLayout, String> {
67 // Parse a bit count from a string.
68 let parse_bits = |s: &str, kind: &str, cause: &str| {
69 s.parse::<u64>().map_err(|err| {
70 format!("invalid {} `{}` for `{}` in \"data-layout\": {}",
75 // Parse a size string.
76 let size = |s: &str, cause: &str| {
77 parse_bits(s, "size", cause).map(Size::from_bits)
80 // Parse an alignment string.
81 let align = |s: &[&str], cause: &str| {
83 return Err(format!("missing alignment for `{}` in \"data-layout\"", cause));
85 let abi = parse_bits(s[0], "alignment", cause)?;
86 let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?;
87 Align::from_bits(abi, pref).map_err(|err| {
88 format!("invalid alignment for `{}` in \"data-layout\": {}",
93 let mut dl = TargetDataLayout::default();
94 let mut i128_align_src = 64;
95 for spec in target.data_layout.split('-') {
96 match spec.split(':').collect::<Vec<_>>()[..] {
97 ["e"] => dl.endian = Endian::Little,
98 ["E"] => dl.endian = Endian::Big,
99 ["a", ref a..] => dl.aggregate_align = align(a, "a")?,
100 ["f32", ref a..] => dl.f32_align = align(a, "f32")?,
101 ["f64", ref a..] => dl.f64_align = align(a, "f64")?,
102 [p @ "p", s, ref a..] | [p @ "p0", s, ref a..] => {
103 dl.pointer_size = size(s, p)?;
104 dl.pointer_align = align(a, p)?;
106 [s, ref a..] if s.starts_with("i") => {
107 let bits = match s[1..].parse::<u64>() {
110 size(&s[1..], "i")?; // For the user error.
114 let a = align(a, s)?;
116 1 => dl.i1_align = a,
117 8 => dl.i8_align = a,
118 16 => dl.i16_align = a,
119 32 => dl.i32_align = a,
120 64 => dl.i64_align = a,
123 if bits >= i128_align_src && bits <= 128 {
124 // Default alignment for i128 is decided by taking the alignment of
125 // largest-sized i{64...128}.
126 i128_align_src = bits;
130 [s, ref a..] if s.starts_with("v") => {
131 let v_size = size(&s[1..], "v")?;
132 let a = align(a, s)?;
133 if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
137 // No existing entry, add a new one.
138 dl.vector_align.push((v_size, a));
140 _ => {} // Ignore everything else.
144 // Perform consistency checks against the Target information.
145 let endian_str = match dl.endian {
146 Endian::Little => "little",
149 if endian_str != target.target_endian {
150 return Err(format!("inconsistent target specification: \"data-layout\" claims \
151 architecture is {}-endian, while \"target-endian\" is `{}`",
152 endian_str, target.target_endian));
155 if dl.pointer_size.bits().to_string() != target.target_pointer_width {
156 return Err(format!("inconsistent target specification: \"data-layout\" claims \
157 pointers are {}-bit, while \"target-pointer-width\" is `{}`",
158 dl.pointer_size.bits(), target.target_pointer_width));
164 /// Return exclusive upper bound on object size.
166 /// The theoretical maximum object size is defined as the maximum positive `isize` value.
167 /// This ensures that the `offset` semantics remain well-defined by allowing it to correctly
168 /// index every address within an object along with one byte past the end, along with allowing
169 /// `isize` to store the difference between any two pointers into an object.
171 /// The upper bound on 64-bit currently needs to be lower because LLVM uses a 64-bit integer
172 /// to represent object size in bits. It would need to be 1 << 61 to account for this, but is
173 /// currently conservatively bounded to 1 << 47 as that is enough to cover the current usable
174 /// address space on 64-bit ARMv8 and x86_64.
175 pub fn obj_size_bound(&self) -> u64 {
176 match self.pointer_size.bits() {
180 bits => panic!("obj_size_bound: unknown pointer bit size {}", bits)
184 pub fn ptr_sized_integer(&self) -> Integer {
185 match self.pointer_size.bits() {
189 bits => panic!("ptr_sized_integer: unknown pointer bit size {}", bits)
193 pub fn vector_align(&self, vec_size: Size) -> Align {
194 for &(size, align) in &self.vector_align {
195 if size == vec_size {
199 // Default to natural alignment, which is what LLVM does.
200 // That is, use the size, rounded up to a power of 2.
201 let align = vec_size.bytes().next_power_of_two();
202 Align::from_bytes(align, align).unwrap()
206 pub trait HasDataLayout: Copy {
207 fn data_layout(&self) -> &TargetDataLayout;
210 impl<'a> HasDataLayout for &'a TargetDataLayout {
211 fn data_layout(&self) -> &TargetDataLayout {
216 /// Endianness of the target, which must match cfg(target-endian).
217 #[derive(Copy, Clone)]
223 /// Size of a type in bytes.
224 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
230 pub const ZERO: Size = Self::from_bytes(0);
233 pub fn from_bits(bits: u64) -> Size {
234 // Avoid potential overflow from `bits + 7`.
235 Size::from_bytes(bits / 8 + ((bits % 8) + 7) / 8)
239 pub const fn from_bytes(bytes: u64) -> Size {
246 pub fn bytes(self) -> u64 {
251 pub fn bits(self) -> u64 {
252 self.bytes().checked_mul(8).unwrap_or_else(|| {
253 panic!("Size::bits: {} bytes in bits doesn't fit in u64", self.bytes())
258 pub fn abi_align(self, align: Align) -> Size {
259 let mask = align.abi() - 1;
260 Size::from_bytes((self.bytes() + mask) & !mask)
264 pub fn is_abi_aligned(self, align: Align) -> bool {
265 let mask = align.abi() - 1;
266 self.bytes() & mask == 0
270 pub fn checked_add<C: HasDataLayout>(self, offset: Size, cx: C) -> Option<Size> {
271 let dl = cx.data_layout();
273 let bytes = self.bytes().checked_add(offset.bytes())?;
275 if bytes < dl.obj_size_bound() {
276 Some(Size::from_bytes(bytes))
283 pub fn checked_mul<C: HasDataLayout>(self, count: u64, cx: C) -> Option<Size> {
284 let dl = cx.data_layout();
286 let bytes = self.bytes().checked_mul(count)?;
287 if bytes < dl.obj_size_bound() {
288 Some(Size::from_bytes(bytes))
295 // Panicking addition, subtraction and multiplication for convenience.
296 // Avoid during layout computation, return `LayoutError` instead.
301 fn add(self, other: Size) -> Size {
302 Size::from_bytes(self.bytes().checked_add(other.bytes()).unwrap_or_else(|| {
303 panic!("Size::add: {} + {} doesn't fit in u64", self.bytes(), other.bytes())
311 fn sub(self, other: Size) -> Size {
312 Size::from_bytes(self.bytes().checked_sub(other.bytes()).unwrap_or_else(|| {
313 panic!("Size::sub: {} - {} would result in negative size", self.bytes(), other.bytes())
318 impl Mul<Size> for u64 {
321 fn mul(self, size: Size) -> Size {
326 impl Mul<u64> for Size {
329 fn mul(self, count: u64) -> Size {
330 match self.bytes().checked_mul(count) {
331 Some(bytes) => Size::from_bytes(bytes),
333 panic!("Size::mul: {} * {} doesn't fit in u64", self.bytes(), count)
339 impl AddAssign for Size {
341 fn add_assign(&mut self, other: Size) {
342 *self = *self + other;
346 /// Alignment of a type in bytes, both ABI-mandated and preferred.
347 /// Each field is a power of two, giving the alignment a maximum value
348 /// of 2<sup>(2<sup>8</sup> - 1)</sup>, which is limited by LLVM to a
349 /// maximum capacity of 2<sup>29</sup> or 536870912.
350 #[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)]
357 pub fn from_bits(abi: u64, pref: u64) -> Result<Align, String> {
358 Align::from_bytes(Size::from_bits(abi).bytes(),
359 Size::from_bits(pref).bytes())
362 pub fn from_bytes(abi: u64, pref: u64) -> Result<Align, String> {
363 let log2 = |align: u64| {
364 // Treat an alignment of 0 bytes like 1-byte alignment.
369 let mut bytes = align;
371 while (bytes & 1) == 0 {
376 Err(format!("`{}` is not a power of 2", align))
378 Err(format!("`{}` is too large", align))
385 abi_pow2: log2(abi)?,
386 pref_pow2: log2(pref)?,
390 pub fn abi(self) -> u64 {
394 pub fn pref(self) -> u64 {
398 pub fn abi_bits(self) -> u64 {
402 pub fn pref_bits(self) -> u64 {
406 pub fn min(self, other: Align) -> Align {
408 abi_pow2: cmp::min(self.abi_pow2, other.abi_pow2),
409 pref_pow2: cmp::min(self.pref_pow2, other.pref_pow2),
413 pub fn max(self, other: Align) -> Align {
415 abi_pow2: cmp::max(self.abi_pow2, other.abi_pow2),
416 pref_pow2: cmp::max(self.pref_pow2, other.pref_pow2),
420 /// Compute the best alignment possible for the given offset
421 /// (the largest power of two that the offset is a multiple of).
423 /// NB: for an offset of `0`, this happens to return `2^64`.
424 pub fn max_for_offset(offset: Size) -> Align {
425 let pow2 = offset.bytes().trailing_zeros() as u8;
432 /// Lower the alignment, if necessary, such that the given offset
433 /// is aligned to it (the offset is a multiple of the aligment).
434 pub fn restrict_for_offset(self, offset: Size) -> Align {
435 self.min(Align::max_for_offset(offset))
439 /// Integers, also used for enum discriminants.
440 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
450 pub fn size(self) -> Size {
452 I8 => Size::from_bytes(1),
453 I16 => Size::from_bytes(2),
454 I32 => Size::from_bytes(4),
455 I64 => Size::from_bytes(8),
456 I128 => Size::from_bytes(16),
460 pub fn align<C: HasDataLayout>(self, cx: C) -> Align {
461 let dl = cx.data_layout();
468 I128 => dl.i128_align,
472 /// Find the smallest Integer type which can represent the signed value.
473 pub fn fit_signed(x: i128) -> Integer {
475 -0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8,
476 -0x0000_0000_0000_8000..=0x0000_0000_0000_7fff => I16,
477 -0x0000_0000_8000_0000..=0x0000_0000_7fff_ffff => I32,
478 -0x8000_0000_0000_0000..=0x7fff_ffff_ffff_ffff => I64,
483 /// Find the smallest Integer type which can represent the unsigned value.
484 pub fn fit_unsigned(x: u128) -> Integer {
486 0..=0x0000_0000_0000_00ff => I8,
487 0..=0x0000_0000_0000_ffff => I16,
488 0..=0x0000_0000_ffff_ffff => I32,
489 0..=0xffff_ffff_ffff_ffff => I64,
494 /// Find the smallest integer with the given alignment.
495 pub fn for_abi_align<C: HasDataLayout>(cx: C, align: Align) -> Option<Integer> {
496 let dl = cx.data_layout();
498 let wanted = align.abi();
499 for &candidate in &[I8, I16, I32, I64, I128] {
500 if wanted == candidate.align(dl).abi() && wanted == candidate.size().bytes() {
501 return Some(candidate);
507 /// Find the largest integer with the given alignment or less.
508 pub fn approximate_abi_align<C: HasDataLayout>(cx: C, align: Align) -> Integer {
509 let dl = cx.data_layout();
511 let wanted = align.abi();
512 // FIXME(eddyb) maybe include I128 in the future, when it works everywhere.
513 for &candidate in &[I64, I32, I16] {
514 if wanted >= candidate.align(dl).abi() && wanted >= candidate.size().bytes() {
523 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy,
530 impl fmt::Debug for FloatTy {
531 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
532 fmt::Display::fmt(self, f)
536 impl fmt::Display for FloatTy {
537 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
538 write!(f, "{}", self.ty_to_string())
543 pub fn ty_to_string(self) -> &'static str {
545 FloatTy::F32 => "f32",
546 FloatTy::F64 => "f64",
550 pub fn bit_width(self) -> usize {
558 /// Fundamental unit of memory access and layout.
559 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
561 /// The `bool` is the signedness of the `Integer` type.
563 /// One would think we would not care about such details this low down,
564 /// but some ABIs are described in terms of C types and ISAs where the
565 /// integer arithmetic is done on {sign,zero}-extended registers, e.g.
566 /// a negative integer passed by zero-extension will appear positive in
567 /// the callee, and most operations on it will produce the wrong values.
573 impl<'a, 'tcx> Primitive {
574 pub fn size<C: HasDataLayout>(self, cx: C) -> Size {
575 let dl = cx.data_layout();
578 Int(i, _) => i.size(),
579 Float(FloatTy::F32) => Size::from_bits(32),
580 Float(FloatTy::F64) => Size::from_bits(64),
581 Pointer => dl.pointer_size
585 pub fn align<C: HasDataLayout>(self, cx: C) -> Align {
586 let dl = cx.data_layout();
589 Int(i, _) => i.align(dl),
590 Float(FloatTy::F32) => dl.f32_align,
591 Float(FloatTy::F64) => dl.f64_align,
592 Pointer => dl.pointer_align
596 pub fn is_float(self) -> bool {
603 pub fn is_int(self) -> bool {
611 /// Information about one scalar component of a Rust type.
612 #[derive(Clone, PartialEq, Eq, Hash, Debug)]
614 pub value: Primitive,
616 /// Inclusive wrap-around range of valid values, that is, if
617 /// start > end, it represents `start..=max_value()`,
618 /// followed by `0..=end`.
620 /// That is, for an i8 primitive, a range of `254..=2` means following
623 /// 254 (-2), 255 (-1), 0, 1, 2
625 /// This is intended specifically to mirror LLVM’s `!range` metadata,
627 // FIXME(eddyb) always use the shortest range, e.g. by finding
628 // the largest space between two consecutive valid values and
629 // taking everything else as the (shortest) valid range.
630 pub valid_range: RangeInclusive<u128>,
634 pub fn is_bool(&self) -> bool {
635 if let Int(I8, _) = self.value {
636 self.valid_range == (0..=1)
642 /// Returns the valid range as a `x..y` range.
644 /// If `x` and `y` are equal, the range is full, not empty.
645 pub fn valid_range_exclusive<C: HasDataLayout>(&self, cx: C) -> Range<u128> {
646 // For a (max) value of -1, max will be `-1 as usize`, which overflows.
647 // However, that is fine here (it would still represent the full range),
648 // i.e., if the range is everything.
649 let bits = self.value.size(cx).bits();
650 assert!(bits <= 128);
651 let mask = !0u128 >> (128 - bits);
652 let start = *self.valid_range.start();
653 let end = *self.valid_range.end();
654 assert_eq!(start, start & mask);
655 assert_eq!(end, end & mask);
656 start..(end.wrapping_add(1) & mask)
660 /// Describes how the fields of a type are located in memory.
661 #[derive(PartialEq, Eq, Hash, Debug)]
662 pub enum FieldPlacement {
663 /// All fields start at no offset. The `usize` is the field count.
665 /// In the case of primitives the number of fields is `0`.
668 /// Array/vector-like placement, with all fields of identical types.
674 /// Struct-like placement, with precomputed offsets.
676 /// Fields are guaranteed to not overlap, but note that gaps
677 /// before, between and after all the fields are NOT always
678 /// padding, and as such their contents may not be discarded.
679 /// For example, enum variants leave a gap at the start,
680 /// where the discriminant field in the enum layout goes.
682 /// Offsets for the first byte of each field,
683 /// ordered to match the source definition order.
684 /// This vector does not go in increasing order.
685 // FIXME(eddyb) use small vector optimization for the common case.
688 /// Maps source order field indices to memory order indices,
689 /// depending how fields were permuted.
690 // FIXME(camlorn) also consider small vector optimization here.
691 memory_index: Vec<u32>
695 impl FieldPlacement {
696 pub fn count(&self) -> usize {
698 FieldPlacement::Union(count) => count,
699 FieldPlacement::Array { count, .. } => {
700 let usize_count = count as usize;
701 assert_eq!(usize_count as u64, count);
704 FieldPlacement::Arbitrary { ref offsets, .. } => offsets.len()
708 pub fn offset(&self, i: usize) -> Size {
710 FieldPlacement::Union(_) => Size::ZERO,
711 FieldPlacement::Array { stride, count } => {
716 FieldPlacement::Arbitrary { ref offsets, .. } => offsets[i]
720 pub fn memory_index(&self, i: usize) -> usize {
722 FieldPlacement::Union(_) |
723 FieldPlacement::Array { .. } => i,
724 FieldPlacement::Arbitrary { ref memory_index, .. } => {
725 let r = memory_index[i];
726 assert_eq!(r as usize as u32, r);
732 /// Get source indices of the fields by increasing offsets.
734 pub fn index_by_increasing_offset<'a>(&'a self) -> impl Iterator<Item=usize>+'a {
735 let mut inverse_small = [0u8; 64];
736 let mut inverse_big = vec![];
737 let use_small = self.count() <= inverse_small.len();
739 // We have to write this logic twice in order to keep the array small.
740 if let FieldPlacement::Arbitrary { ref memory_index, .. } = *self {
742 for i in 0..self.count() {
743 inverse_small[memory_index[i] as usize] = i as u8;
746 inverse_big = vec![0; self.count()];
747 for i in 0..self.count() {
748 inverse_big[memory_index[i] as usize] = i as u32;
753 (0..self.count()).map(move |i| {
755 FieldPlacement::Union(_) |
756 FieldPlacement::Array { .. } => i,
757 FieldPlacement::Arbitrary { .. } => {
758 if use_small { inverse_small[i] as usize }
759 else { inverse_big[i] as usize }
766 /// Describes how values of the type are passed by target ABIs,
767 /// in terms of categories of C types there are ABI rules for.
768 #[derive(Clone, PartialEq, Eq, Hash, Debug)]
772 ScalarPair(Scalar, Scalar),
778 /// If true, the size is exact, otherwise it's only a lower bound.
784 /// Returns true if the layout corresponds to an unsized type.
785 pub fn is_unsized(&self) -> bool {
789 Abi::ScalarPair(..) |
790 Abi::Vector { .. } => false,
791 Abi::Aggregate { sized } => !sized
795 /// Returns true if this is a single signed integer scalar
796 pub fn is_signed(&self) -> bool {
798 Abi::Scalar(ref scal) => match scal.value {
799 Primitive::Int(_, signed) => signed,
806 /// Returns true if this is an uninhabited type
807 pub fn is_uninhabited(&self) -> bool {
809 Abi::Uninhabited => true,
815 #[derive(PartialEq, Eq, Hash, Debug)]
817 /// Single enum variants, structs/tuples, unions, and all non-ADTs.
822 /// General-case enums: for each case there is a struct, and they all have
823 /// all space reserved for the tag, and their first field starts
824 /// at a non-0 offset, after where the tag would go.
827 variants: Vec<LayoutDetails>,
830 /// Multiple cases distinguished by a niche (values invalid for a type):
831 /// the variant `dataful_variant` contains a niche at an arbitrary
832 /// offset (field 0 of the enum), which for a variant with discriminant
833 /// `d` is set to `(d - niche_variants.start).wrapping_add(niche_start)`.
835 /// For example, `Option<(usize, &T)>` is represented such that
836 /// `None` has a null pointer for the second tuple field, and
837 /// `Some` is the identity function (with a non-null reference).
839 dataful_variant: usize,
840 niche_variants: RangeInclusive<usize>,
843 variants: Vec<LayoutDetails>,
847 #[derive(PartialEq, Eq, Hash, Debug)]
848 pub struct LayoutDetails {
849 pub variants: Variants,
850 pub fields: FieldPlacement,
857 pub fn scalar<C: HasDataLayout>(cx: C, scalar: Scalar) -> Self {
858 let size = scalar.value.size(cx);
859 let align = scalar.value.align(cx);
861 variants: Variants::Single { index: 0 },
862 fields: FieldPlacement::Union(0),
863 abi: Abi::Scalar(scalar),
870 /// The details of the layout of a type, alongside the type itself.
871 /// Provides various type traversal APIs (e.g. recursing into fields).
873 /// Note that the details are NOT guaranteed to always be identical
874 /// to those obtained from `layout_of(ty)`, as we need to produce
875 /// layouts for which Rust types do not exist, such as enum variants
876 /// or synthetic fields of enums (i.e. discriminants) and fat pointers.
877 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
878 pub struct TyLayout<'a, Ty> {
880 pub details: &'a LayoutDetails
883 impl<'a, Ty> Deref for TyLayout<'a, Ty> {
884 type Target = &'a LayoutDetails;
885 fn deref(&self) -> &&'a LayoutDetails {
894 fn layout_of(self, ty: Self::Ty) -> Self::TyLayout;
897 pub trait TyLayoutMethods<'a, C: LayoutOf<Ty = Self>>: Sized {
898 fn for_variant(this: TyLayout<'a, Self>, cx: C, variant_index: usize) -> TyLayout<'a, Self>;
899 fn field(this: TyLayout<'a, Self>, cx: C, i: usize) -> C::TyLayout;
902 impl<'a, Ty> TyLayout<'a, Ty> {
903 pub fn for_variant<C>(self, cx: C, variant_index: usize) -> Self
904 where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> {
905 Ty::for_variant(self, cx, variant_index)
907 pub fn field<C>(self, cx: C, i: usize) -> C::TyLayout
908 where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> {
909 Ty::field(self, cx, i)
913 impl<'a, Ty> TyLayout<'a, Ty> {
914 /// Returns true if the layout corresponds to an unsized type.
915 pub fn is_unsized(&self) -> bool {
916 self.abi.is_unsized()
919 /// Returns true if the type is a ZST and not unsized.
920 pub fn is_zst(&self) -> bool {
923 Abi::ScalarPair(..) |
924 Abi::Vector { .. } => false,
925 Abi::Uninhabited => self.size.bytes() == 0,
926 Abi::Aggregate { sized } => sized && self.size.bytes() == 0
930 pub fn size_and_align(&self) -> (Size, Align) {
931 (self.size, self.align)