Rust compiler marks derived trait methods #[inline] by default
Rust's #[derive(Debug)], #[derive(Clone)] and similar macros automatically attach an #[inline] attribute to the generated methods, as shown by expanding the macros or noted in the language reference. This behavior isn't formally guaranteed by the language specification but is consistently observed in current compiler output.
GoKawiil's interpretation of the reporting above, not reported fact.
The default inlining hint generally helps since derived implementations are typically trivial, but the author points out this can backfire for deeply nested structures, such as layered error types with many string fields, where inlining large derived Debug implementations could bloat compiled code. Because the behavior is implicit rather than guaranteed, developers relying on it for performance tuning may be surprised if it changes in future Rust versions.
- Rust's derive macros currently add #[inline] to generated trait implementations automatically.
- This default is not formally guaranteed in the language specification, only observed via macro expansion.
- Nested or complex derived types, like layered error structs, may suffer from unwanted code bloat due to automatic inlining.
Source: yossarian.net, 2026-10-04
Published there as: “Rust's derive often implies inline”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.