Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Rust Gets Incremental Compiler and Standard Code Formatter

Rust Gets Incremental Compiler and Standard Code Formatter

Leia em Português

This item in japanese


Rust 1.24 brings two new major features: incremental compilation and a standard code formatter, rustfmt.

The Rust core team started working on incremental compilation at the end of 2015 and had an alpha version ready by September 2016. Since then the team has been working on making it production-ready by fixing crashes and improving its correctness. Now, Rust 1.24 enables incremental compilation by default. If you do not want to use it, you can disable it on a per-project basis, using in Cargo.toml, or globally, using build.incremental in .cargo/config.

Incremental compilation is not the only change that Rust 1.24 includes to improve performance. Indeed, Rust 1.24 has stabilized codegen-units, which makes it possible to run multiple compiler code generation phases in parallel. One drawback of the new codegen-units behavior is that the final binary tends to be a bit slower. To disable the new behavior and ensure maximum runtime performance of your binary, you can set codegen-units to 1 in Cargo.toml.

Rust 1.24 also introduces a preview of rustfmt, a tool for formatting Rust code according to style guidelines. You can install rustfmt-preview by running rustup component add rustfmt-preview and then you can run it on a file with rustfmt filename, which will format all included modules as well.

rustfmt supports a number of output modes that can be set using the --write-mode flag on the command line. You can, for example, overwrite the original files, replace them after creating backups, just display the formatted output, and more. rustfmt can also be integrated with many editors, including Vim, Emacs, Sublime Text 3, Atom, and others.

For the full detail of what is new in Rust 1.24, please consult the release notes.

Rate this Article