Skip to content

Commit 9695b80

Browse files
authored
Rollup merge of rust-lang#58615 - RalfJung:ref-to-place-alignment, r=oli-obk
miri: explain why we use static alignment in ref-to-place conversion @eddyb @oli-obk do you think this makes sense? Or should we use the run-time alignment (`align_of_val`)? I am a bit worried about custom DSTs, but that affects way more areas of Miri so I'd ignore them for now. r? @oli-obk
2 parents 59f1a56 + b01f81b commit 9695b80

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustc_mir/interpret/place.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ where
326326

327327
let mplace = MemPlace {
328328
ptr: val.to_scalar_ptr()?,
329+
// We could use the run-time alignment here. For now, we do not, because
330+
// the point of tracking the alignment here is to make sure that the *static*
331+
// alignment information emitted with the loads is correct. The run-time
332+
// alignment can only be more restrictive.
329333
align: layout.align.abi,
330334
meta: val.to_meta()?,
331335
};
@@ -385,9 +389,11 @@ where
385389
// above). In that case, all fields are equal.
386390
let field_layout = base.layout.field(self, usize::try_from(field).unwrap_or(0))?;
387391

388-
// Offset may need adjustment for unsized fields
392+
// Offset may need adjustment for unsized fields.
389393
let (meta, offset) = if field_layout.is_unsized() {
390-
// re-use parent metadata to determine dynamic field layout
394+
// Re-use parent metadata to determine dynamic field layout.
395+
// With custom DSTS, this *will* execute user-defined code, but the same
396+
// happens at run-time so that's okay.
391397
let align = match self.size_and_align_of(base.meta, field_layout)? {
392398
Some((_, align)) => align,
393399
None if offset == Size::ZERO =>

0 commit comments

Comments
 (0)