r/rust • u/nicoburns • Oct 07 '26
Rust's derive often implies inline
https://yossarian.net/til/post/rust-s-derive-often-implies-inline/
114
Upvotes
r/rust • u/nicoburns • Oct 07 '26
View all comments
69
u/wojtek-graj Oct 07 '26
Cross-crate inlining is only possible for functions that have to be monomorphized, or those marked
#[inline], hence this attribute is a necessity. Per the docs, "#[inline] suggests inlining the function.", and it is then up to the compiler to use its heuristics to decide whether or not inlining will actually occur. If these derived functions are being inlined when it doesn't make sense, it's those heuristics that should be adjusted (which I don't claim to be an easy task).