Large enums are they moved around during construction?

⚓ Rust    📅 2026-02-09    👤 surdeus    👁️ 2      

surdeus

Clippy gave me a couple of warnings on interator enums

For example:warning: large size difference between variants --> src/collections/btree_set/mod.rs:2144:1 | 2144 | / enum DifferenceInner<'a, T: 'a, A: Tuning> { 2145 | | / Stitch { 2146 | | | // iterate all of selfand some ofother, spotting matches along the way 2147 | | | self_iter: Iter<'a, T>, 2148 | | | other_iter: Peekable<Iter<'a, T>>, 2149 | | | }, | | |_____- the largest variant contains at least 1760 bytes 2150 | | / Search { 2151 | | | // iterate self, look up in other2152 | | | self_iter: Iter<'a, T>, 2153 | | | other_set: &'a BTreeSet<T, A>, 2154 | | | }, | | |_____- the second-largest variant contains at least 880 bytes 2155 | | Iterate(Iter<'a, T>), // simply produce all elements inself2156 | | } | |___^ the entire enum is at least 1760 bytes | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#large_enum_variant help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum | 2148 - other_iter: Peekable<Iter<'a, T>>, 2148 +

That got me wondering whether it mattered how large these are or not, do they (or the component structs) get moved around during construction of an iterator. I would hope not, but I haven't checked the code. Any idea what the compiler "normally" does?

5 posts - 3 participants

Read full topic

🏷️ Rust_feed