logoalt Hacker News

afdbcreid • today at 6:00 PM • 0 replies • view on HN

`#[inline]` in Rust is weird and not similar to `inline` in C or C++. It has two effects: it duplicates the MIR for every codegen unit that needs it instead of precompiling (which is what causes the laziness, and also why it's commonly recommended to avoid `#[inline]` on generic functions as this happens anyway for them), and also adds LLVM `inlinehint`. It is possible to avoid the second but not the first if you want to stay lazy, and that can also cause code duplication (unless you set `codegen-units = 1`) and LLVM deciding to inline things even without the hint.