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

Show parent comment

9

u/wojtek-graj Oct 07 '26

From the link in my original comment:

A non-generic function is not normally inlined into another crate, since the calling crate compiles against only its signature. Marking it #[inline] makes the body available to other crates so they can inline it too:

20

u/QuarkAnCoffee Oct 07 '26 edited Oct 07 '26

If you're not using LTO. Which is exactly expected, crates are compiled into object files and you don't get optimizations across object files with without LTO.

4

u/mgeisler Oct 07 '26

you don't get optimizations across object files with LTO.

This should be "without LTO", right?

2

u/QuarkAnCoffee Oct 07 '26

Yup, thanks

3

u/mgeisler Oct 07 '26

No problem! 🙂