178. A field nothing reads is left out, with its stores (2026-11-21)
- Decision. §176 for every field type. A struct field that no
expression reads is left out of the emitted struct, its constructors and
its
cpl_tie. A read iss.f,mut s.fas an argument, a store that is not a plain=(s.f += 1readss.f), or any operation that sees the whole value: comparing, ordering, hashing, printing, reading from input, sorting naturally, or using the struct as a map key or set element, which keeps every field of that struct and of the structs inside it. A storeplace = vinto a dropped field writes nothing; it is left out only when the place cannot trap (every index is a position of the domain its array is over), andvis still evaluated as(void)(v);unless it runs nothing, so its traps and effects stay (reading an array at positions of its domains runs nothing). A local whose only uses are such stores,xs.push(v)of a value that runs nothing, and being placed in a dropped field is left out with them, which is what removes the work; repeated until nothing more goes, since a dropped store reads nothing. A parameter used only that way stays in the signature as[[maybe_unused]] const T&, so it is not copied. A method that is never called reads nothing.cpl explainlists each dropped field as[dropped] struct S.f. - Why. Result structs carry witnesses most callers never read:
Paths.backandPaths.orderin std.graph. g++ keeps the stores because the arrays escape through the returned struct. The interpreter still computes every field; since nothing reads a dropped field, both print the same and trap at the same place. - Reverse. Drop
drop_unread_fields/drop_dead_localsincrates/cpl-codegen/src/devirt.rs(back to fn fields only) and thedropped_storeskips incrates/cpl-codegen/src/stmt.rs.