Skip to content

Commit b0c86ea

Browse files
committed
be clearer about when reordering fields would be a breaking change
1 parent 97622bc commit b0c86ea

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

reference/src/representation/structs-and-tuples.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,19 @@ proposal (and -- further -- it does not match our existing behavior):
341341
ahead of
342342
time](https://github.com/rust-rfcs/unsafe-code-guidelines/issues/11#issuecomment-420659840),
343343
so the user cannot do it manually.
344-
- If layout is defined, then it becomes part of your API, such taht
345-
reordering fields is a breaking change for your clients (if we
346-
consider unsafe code that may rely on the layout, then this applies
347-
[even to structs with named
348-
fields](https://github.com/rust-rfcs/unsafe-code-guidelines/issues/11#issuecomment-420117856).
344+
- If layout is defined, and a library exposes a struct with all public
345+
fields, then clients may be more likely to assume that the layout of
346+
that struct is stable. If they were to write unsafe code that relied
347+
on this assumption, that would break if fields were reordered. But
348+
libraries may well expect the freedom to reorder fields. This case
349+
is weakened because of the requirement to write unsafe code (after
350+
all, one can always write unsafe code that relies on virtually any
351+
implementation detail); if we were to permit **safe** casts that
352+
rely on the layout, then reordering fields would clearly be a
353+
breaking change (see also [this
354+
comment](https://github.com/rust-rfcs/unsafe-code-guidelines/issues/11#issuecomment-420117856)
355+
and [this
356+
thread](https://github.com/rust-rfcs/unsafe-code-guidelines/pull/31#discussion_r224955817)).
349357
- Many people would prefer the name ordering to be chosen for
350358
"readability" and not optimal layout.
351359

0 commit comments

Comments
 (0)