First, you can tell the compiler to inline a function using #[inline]
: Technically, this does not guarantee inlining, but it should work in reasonable situations. I would recommend using this.
Second, as noted in the comments, you have to do an optimised build to see such inlining. Maybe a better tool for this would be Compiler Explorer. Here is a slight modification of your example (notice the -O
flag in compiler options). As you can see, everything is inlined into one infinite loop, and the compiler can even eliminate some work done in the loop if it can prove that it is useless.
Overall, unless you use #[inline]
, the result will depend on the contents of a
and b
. So I would advise to create some kind of minimal-viable-implementation of what you are trying to achieve with a
and b
, and then test it in Compiler Explorer.