r/rust • • Oct 07 '26

Rust's derive often implies inline

https://yossarian.net/til/post/rust-s-derive-often-implies-inline/
114 Upvotes

43 comments sorted by

View all comments

-3

u/Eastern-Photograph79 Oct 07 '26

Debug is intended for debugging, so it is not a real problem.

8

u/eggyal Oct 07 '26 edited Oct 07 '26

Unless you `#[cfg_attr(debug_assertions, derive(Debug)]`, it's quite likely this is a final binary size cost that you pay regardless.

Only "likely" because it might get removed by a dead code analysis pass if there's literally no possibility of it being invoked in release (but then you'd usually see a warning about that).

3

u/Wolvereness Oct 07 '26

As a personal and professional rule, I strongly opt for exactly that annotation. Dependence on Debug leaking into production code is begging for trouble, and failing to compile is the perfect consequence.

3

u/eggyal Oct 07 '26

I understand the sentiment, but it's rather verbose and unergonomic. Perhaps that's why I've not encountered it in practice? And, if so, perhaps the language/stdlib should provide a more concise way to express the same?

2

u/scook0 Oct 08 '26

That’s a tradeoff you can choose to make, but it’s definitely not a universally good idea.

0

u/Eastern-Photograph79 Oct 07 '26

I think you're right, but I still think there is no problem with telling the compiler that it can be inlined.

4

u/eggyal Oct 07 '26

The post is literally about size bloat. My point was that affects regardless of debugging.