Lines Matching full:layout
19 /// The layout of a type which might be dynamically-sized.
21 /// `DstLayout` describes the layout of sized types, slice types, and "slice
28 /// the layout of real Rust types or instances of types.
125 /// \[1\] Per <https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers>:
155 /// Assumes that this layout lacks static shallow padding.
205 /// Unsafe code may assume that `DstLayout` is the correct layout for `T`.
229 /// Unsafe code may assume that `DstLayout` is the correct layout for `T`.
241 /// Unsafe code may assume that `DstLayout` is the correct layout for `[T]`.
267 /// This method cannot be used to match the layout of a record with the
274 /// resulting `DstLayout` will correctly encode the layout of that struct.
285 let mut layout = DstLayout::new_zst(repr_align); in for_repr_c_struct() localVariable
292 layout = layout.extend(field, repr_packed); in for_repr_c_struct()
296 layout = layout.pad_to_align(); in for_repr_c_struct()
298 // SAFETY: `layout` accurately describes the layout of a `repr(C)` in for_repr_c_struct()
300 // the given `fields`. The `layout` is constructed using a sequence of in for_repr_c_struct()
310 layout in for_repr_c_struct()
313 /// Like `Layout::extend`, this creates a layout that describes a record
314 /// whose layout consists of `self` followed by `next` that includes the
317 /// In order to match the layout of a `#[repr(C)]` struct, this method
319 /// padding, call `DstLayout::pad_to_align` after extending the layout for
324 /// This method cannot be used to match the layout of a record with the
330 /// fields whose layout are `self`, and those fields are immediately
331 /// followed by a field whose layout is `field`, then unsafe code may rely
332 /// on `self.extend(field, repr_packed)` producing a layout that correctly
368 // [1] Per https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers: in extend()
380 // If the layout is already a DST, we panic; DSTs cannot be extended in extend()
389 … // [1] Per https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers: in extend()
397 // if the layout components can correspond to a leading layout in extend()
410 // If the trailing field is sized, the resulting layout in extend()
412 // preceding layout, the size of the new field, and the in extend()
416 // panic) if the layout components can correspond to a in extend()
417 // leading layout fragment of a valid Rust type, but may in extend()
432 // will the resulting layout. The offset of the trailing in extend()
438 // panic) if the layout components can correspond to a in extend()
439 // leading layout fragment of a valid Rust type, but may in extend()
461 /// Like `Layout::pad_to_align`, this routine rounds the size of this layout
470 /// In order to match the layout of a `#[repr(C)]` struct, this method
475 /// This method cannot be used to match the layout of a record with the
481 /// whose layout are `self` followed only by zero or more bytes of trailing
483 /// `self.pad_to_align(repr_packed)` producing a layout that correctly
484 /// encapsulates the layout of that type.
508 // offset or element size of the layout, so we leave `size_info` in pad_to_align()
525 /// Produces `true` if there exists any metadata for which a type of layout
543 /// Validates that a cast is sound from a layout perspective.
546 /// layout described in `self` would not be violated by performing a
827 // - `S_OFF = Src::LAYOUT.size_info.offset` in project()
828 // - `S_ELEM = Src::LAYOUT.size_info.elem_size` in project()
829 // - `D_OFF = Dst::LAYOUT.size_info.offset` in project()
830 // - `D_ELEM = Dst::LAYOUT.size_info.elem_size` in project()
1075 match CastParams::try_compute(&Src::LAYOUT, &Dst::LAYOUT) { in project()
1109 let layout = DstLayout::for_slice::<u32>(); in test_dst_layout_for_slice() localVariable
1110 match layout.size_info { in test_dst_layout_for_slice()
1117 assert_eq!(layout.align.get(), 4); in test_dst_layout_for_slice()
1124 // This macro constructs a layout corresponding to a `u8` and extends it in test_dst_layout_extend_sized_with_sized()
1126 // tests that the resulting layout has both size and alignment `min(n, in test_dst_layout_extend_sized_with_sized()
1190 // layout. in test_dst_layout_extend_sized_with_dst()
1232 // For all valid alignments `align`, construct a one-byte layout aligned in test_dst_layout_pad_to_align_with_sized()
1234 // resulting layout is equal to `align`. in test_dst_layout_pad_to_align_with_sized()
1236 let layout = DstLayout { in test_dst_layout_pad_to_align_with_sized() localVariable
1243 layout.pad_to_align(), in test_dst_layout_pad_to_align_with_sized()
1301 let layout = DstLayout { in test_dst_layout_pad_to_align_with_dst() localVariable
1306 assert_eq!(layout.pad_to_align(), layout); in test_dst_layout_pad_to_align_with_dst()
1332 fn layout<S: Into<SizeInfo>>(s: S, align: usize) -> DstLayout { in test_validate_cast_and_convert_metadata() function
1342 /// layout(_, _).validate(_, _, _), Ok(Some((_, _))) in test_validate_cast_and_convert_metadata()
1384 layout($size:tt, $align:tt) in test_validate_cast_and_convert_metadata()
1406 … layout(size_info, align).validate_cast_and_convert_metadata(addr, bytes_len, cast_type) in test_validate_cast_and_convert_metadata()
1416 …"layout({:?}, {}).validate_cast_and_convert_metadata({}, {}, {:?})" ,size_info, align, addr, bytes… in test_validate_cast_and_convert_metadata()
1460 layout(((1..8) | ((1..8), (1..8))), _).validate([0], [0], _), in test_validate_cast_and_convert_metadata()
1464 layout(((2..8) | ((2..8), (2..8))), _).validate([0], [1], Prefix), in test_validate_cast_and_convert_metadata()
1468 layout(((2..8) | ((2..8), (2..8))), _).validate([0x1000_0000 - 1], [1], Suffix), in test_validate_cast_and_convert_metadata()
1473 test!(layout(_, [2]).validate(ODDS, _, Prefix), Ok(Err(MetadataCastError::Alignment))); in test_validate_cast_and_convert_metadata()
1474 test!(layout(_, [2]).validate(ODDS, _, Prefix), Ok(Err(MetadataCastError::Alignment))); in test_validate_cast_and_convert_metadata()
1477 test!(layout(_, [2]).validate(EVENS, ODDS, Suffix), Ok(Err(MetadataCastError::Alignment))); in test_validate_cast_and_convert_metadata()
1478 test!(layout(_, [2]).validate(EVENS, ODDS, Suffix), Ok(Err(MetadataCastError::Alignment))); in test_validate_cast_and_convert_metadata()
1496 test!(layout((_, [0]), _).validate(_, _, _), Err(Some(msgs::TRAILING) | None),); in test_validate_cast_and_convert_metadata()
1499 test!(layout(_, _).validate([usize::MAX], (1..100), _), Err(Some(msgs::OVERFLOW) | None)); in test_validate_cast_and_convert_metadata()
1500 test!(layout(_, _).validate((1..100), [usize::MAX], _), Err(Some(msgs::OVERFLOW) | None)); in test_validate_cast_and_convert_metadata()
1502 layout(_, _).validate( in test_validate_cast_and_convert_metadata()
1514 (layout, addr, bytes_len, cast_type): (DstLayout, usize, usize, CastType), in test_validate_cast_and_convert_metadata() argument
1517 layout.validate_cast_and_convert_metadata(addr, bytes_len, cast_type) in test_validate_cast_and_convert_metadata()
1519 let (size_info, align) = (layout.size_info, layout.align); in test_validate_cast_and_convert_metadata()
1521 "layout({:?}, {}).validate_cast_and_convert_metadata({}, {}, {:?}) => ({}, {})", in test_validate_cast_and_convert_metadata()
1529 let sized = matches!(layout.size_info, SizeInfo::Sized { .. }); in test_validate_cast_and_convert_metadata()
1532 let resulting_size = match layout.size_info { in test_validate_cast_and_convert_metadata()
1563 let min_size = match layout.size_info { in test_validate_cast_and_convert_metadata()
1566 offset + util::padding_needed_for(offset, layout.align) in test_validate_cast_and_convert_metadata()
1578 let misaligned = (base + addr) % layout.align != 0; in test_validate_cast_and_convert_metadata()
1592 .map(|(size_info, align)| layout(size_info, align)); in test_validate_cast_and_convert_metadata()
1608 // built-in APIs to confirm that Rust makes decisions about type layout in test_validate_rust_layout()
1632 let layout = { in test_validate_rust_layout() localVariable
1685 // understanding of how Rust determines the layout of repr(C) in test_validate_rust_layout()
1706 let (got_elems, got_split_at) = layout in test_validate_rust_layout()
1954 use core::alloc::Layout;
1968 // `Layout` to verify that our `DstLayout` satisfies the validity in any()
1972 SizeInfo::Sized { size } => Layout::from_size_align(size, align.get()), in any()
1976 Layout::from_size_align(offset, align.get()) in any()
2017 let layout: DstLayout = kani::any(); in prove_requires_dynamic_padding() localVariable
2019 let SizeInfo::SliceDst(size_info) = layout.size_info else { in prove_requires_dynamic_padding()
2044 let trailing_padding = util::padding_needed_for(unpadded_size, layout.align); in prove_requires_dynamic_padding()
2046 if !layout.requires_dynamic_padding() { in prove_requires_dynamic_padding()
2078 // [1] Per https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers: in prove_dst_layout_extend()
2093 // [1] Per https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers: in prove_dst_layout_extend()
2100 // For testing purposes, we'll also construct `alloc::Layout` in prove_dst_layout_extend()
2103 let base_analog = Layout::from_size_align(base_size, base.align.get()).unwrap(); in prove_dst_layout_extend()
2108 // If the trailing field is sized, the resulting layout will in prove_dst_layout_extend()
2110 // layout, the size of the new field, and the size of in prove_dst_layout_extend()
2115 Layout::from_size_align(field_size, field_align.get()).unwrap(); in prove_dst_layout_extend()
2126 // the basic invariants of a valid Rust layout. At in prove_dst_layout_extend()
2128 // permissive than `Layout`, so we don't assert in prove_dst_layout_extend()
2152 Layout::from_size_align(field_offset, field_align.get()).unwrap(); in prove_dst_layout_extend()
2163 // the basic invariants of a valid Rust layout. At in prove_dst_layout_extend()
2165 // permissive than `Layout`, so we don't assert in prove_dst_layout_extend()
2169 panic!("The extension of a layout with a DST must result in a DST.") in prove_dst_layout_extend()
2196 let layout: DstLayout = kani::any(); in prove_dst_layout_pad_to_align() localVariable
2198 let padded = layout.pad_to_align(); in prove_dst_layout_pad_to_align()
2201 assert_eq!(padded.align, layout.align); in prove_dst_layout_pad_to_align()
2203 if let SizeInfo::Sized { size: unpadded_size } = layout.size_info { in prove_dst_layout_pad_to_align()
2205 // If the layout is sized, it will remain sized after padding is in prove_dst_layout_pad_to_align()
2209 let padding = padding_needed_for(unpadded_size, layout.align); in prove_dst_layout_pad_to_align()
2213 // identically to `Layout::pad_to_align`. in prove_dst_layout_pad_to_align()
2215 Layout::from_size_align(unpadded_size, layout.align.get()).unwrap(); in prove_dst_layout_pad_to_align()
2217 assert_eq!(padded_analog.align(), layout.align.get()); in prove_dst_layout_pad_to_align()
2220 panic!("The padding of a sized layout must result in a sized layout.") in prove_dst_layout_pad_to_align()
2223 // If the layout is a DST, padding cannot be statically added. in prove_dst_layout_pad_to_align()
2224 assert_eq!(padded.size_info, layout.size_info); in prove_dst_layout_pad_to_align()