Skip to content

Commit

Permalink
Rollup merge of rust-lang#130384 - workingjubilee:document-what-abi-a…
Browse files Browse the repository at this point in the history
…nd-pref-align-is, r=compiler-errors

compiler: Document AbiAndPrefAlign

The mere existence of this struct is confusing, and the second field doubly so. It's easy to mistake the "preferred" alignment as semantically relevant somehow. Insofar as I am aware, it is not, and certainly not for Rust code.
  • Loading branch information
matthiaskrgr authored Sep 15, 2024
2 parents f0fb411 + 7b02be8 commit b3686b5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,14 @@ impl Align {
}

/// A pair of alignments, ABI-mandated and preferred.
///
/// The "preferred" alignment is an LLVM concept that is virtually meaningless to Rust code:
/// it is not exposed semantically to programmers nor can they meaningfully affect it.
/// The only concern for us is that preferred alignment must not be less than the mandated alignment
/// and thus in practice the two values are almost always identical.
///
/// An example of a rare thing actually affected by preferred alignment is aligning of statics.
/// It is of effectively no consequence for layout in structs and on the stack.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub struct AbiAndPrefAlign {
Expand Down

0 comments on commit b3686b5

Please sign in to comment.