What Is New in Rust 1.60
| Category | Highlights |
|---|---|
| New Features | Source-based code coverage, cargo --timings reports, namespaced and weak Cargo feature syntax, monotonic Instant guarantees. |
| Improvements | Incremental compilation re-enabled, performance tweaks to Instant, various stabilizations. |
How can I enable source-based code coverage in Rust 1.60?
The compiler now supports LLVM-based coverage instrumentation that can be turned on with -Cinstrument-coverage. In practice you add the flag via RUSTFLAGS="-C instrument-coverage" and rebuild.
RUSTFLAGS="-C instrument-coverage" cargo build
After running the binary a default.profraw file is emitted. You then use the llvm-tools-preview component to merge and display the report:
rustup component add llvm-tools-preview
$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse default.profraw -o default.profdata
$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show -Xdemangler=rustfilt target/debug/your-crate \
-instr-profile=default.profdata \
-show-line-counts-or-regions \
-show-instantiations
This matters if you need line-level coverage without third-party tools; the output format may evolve, so keep the LLVM tools version in sync with the compiler.
What does the new cargo --timings flag do and how do I use it?
cargo --timings generates an HTML report that visualizes how long each crate took to compile.
cargo build --timings
The report is saved to target/cargo-timings/cargo-timing-<timestamp>.html and also copied to target/cargo-timings/cargo-timing.html. Most teams use it to spot unexpectedly slow dependencies or to evaluate the impact of incremental compilation.
How have Cargo feature declarations changed in Rust 1.60?
Cargo now supports namespaced dependencies (dep:) and weak dependency features (?) to give finer control over optional crates.
[dependencies]
serde = { version = "1.0", optional = true }
rgb = { version = "0.8", optional = true }
[features]
serde = ["dep:serde", "rgb?/serde"]
In this example the serde feature pulls in the serde crate and only enables rgb's serde feature if the rgb crate is already activated. This helps keep your public feature surface clean and avoids unintentionally pulling in heavy optional dependencies.
What are the new monotonic guarantees for Instant in Rust 1.60?
Instant::duration_since, Instant::elapsed and Instant::sub now saturate to zero instead of panicking when the underlying clock appears to go backwards.
This matters on tier-1 platforms where the OS provides a monotonic clock; on rare hardware or virtualization bugs the functions will now return zero rather than crashing your program. Use Instant::checked_duration_since if you need to detect the anomaly explicitly.
Is incremental compilation back in Rust 1.60?
Yes, incremental compilation has been re-enabled for the stable channel.
Watch out for the usual incremental bugs, but most teams will see faster rebuilds without any migration work. The compiler team continues to invest in fixing remaining edge cases.
Frequently Asked Questions
Can I use the new coverage flags on Windows?
The coverage instrumentation works on any platform supported by LLVM, but you must install the matching llvm-tools-preview component for your host.
Do I need to change my Cargo.toml to use the new dep: syntax?
Only if you want to hide optional dependencies behind a custom feature name; otherwise existing syntax continues to work.
Will cargo build --timings slow down my compile?
The overhead is minimal, typically a few milliseconds, and the benefit of the report outweighs the cost for most CI pipelines.
How do I interpret a zero-duration result from Instant::elapsed?
A zero result indicates the clock moved backwards or the two instants were swapped; you can use Instant::checked_duration_since to detect this case.
Is there any extra configuration needed to re-enable incremental compilation?
No extra flags are required; just ensure you are on the stable 1.60 compiler.
What command generates the coverage HTML report?
Run llvm-profdata to merge the .profraw file and then llvm-cov show with the -instr-profile option to produce the annotated source view.