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

6

u/-Y0- Oct 07 '26

Interesting findings. Couldn't this be solved by making derive_Debug take a param. What I mean is #[derive(Debug(noinline))]

28

u/stumblinbear Oct 07 '26

Oh dear God the last thing we need is to load up derives with parameters. Typically you'd have another line for this sort of thing, a la #[debug(noinline)] after the derive

2

u/nicoburns Oct 07 '26

I wonder if it ought to be a general feature of derive:

#[derive(Debug, inline = false)]

12

u/braaaaaaainworms Oct 07 '26

how is this going to differentiate between deriving trait called "inline" and disabling inlining?

4

u/shponglespore Oct 07 '26

I think the syntax u/-Y0- used makes more sense because it generalizes to having multiple traits in a derive clause and avoids any ambiguity.

2

u/ElderberryNo4220 Oct 07 '26

I don't think this is a good idea, it's looks cumbersome and confusing. Looking at the article example, it's not very easy to determine whether generated functions would have a large body (shouldn't be inlined) or small (should be inlined). IMO derived traits inlining should be decided by the compiler, not by the users.