| ▲ | tialaramex a day ago | |||||||||||||
Thanks to Matt Godbolt, we can ask Compiler Explorer! https://rust.godbolt.org/z/dPn3Y4r59 The optimizer gives the exact same machine code for both functions, and so it just outputs a single function and gives it an alias. The compiler has a technique called "inlining" https://en.wikipedia.org/wiki/Inline_expansion The LLVM backend used by Rust is jokingly said to have a inlining heuristic of "yes" ie it will always try to inline everything because that's usually faster. | ||||||||||||||
| ▲ | xiej a day ago | parent [-] | |||||||||||||
Unfortunately it's not inlined in debug/no optimization mode so that's rough. | ||||||||||||||
| ||||||||||||||