Stable Release in branch 1.31
1.31.1
Released 20 Dec 2018
(7 years ago)
SoftwareRust
Version1.31
Initial release1.31.0
06 Dec 2018
(7 years ago)
Latest release1.31.1
20 Dec 2018
(7 years ago)
Support status18 Jan 2019
(Ended 7 years ago)
Release noteshttps://github.com/rust-lang/rust/releases/tag/1.31.1
Source codehttps://github.com/rust-lang/rust/tree/1.31.1
Downloadhttps://github.com/rust-lang/rust/releases/tag/1.31.1
Rust 1.31 ReleasesView full list

What Is New in Rust 1.31

Category Highlights
New Features Non-lexical lifetimes, 2018 module system changes, const fn, lifetime elision improvements, tool lints
Improvements Cargo parallel HTTP/2 downloads, Rustfmt 1.0 stability, Clippy 1.0, IDE support, crate renaming in Cargo.toml

What is the impact of non-lexical lifetimes in Rust 1.31?

Non-lexical lifetimes make the borrow checker smarter, allowing code that previously failed to compile.

In practice the compiler now tracks the exact point where a reference is last used instead of assuming the whole lexical scope.

fn main() {
    let mut x = 5;
    let y = &x;      // immutable borrow
    let z = &mut x;  // mutable borrow - now allowed because y is no longer used
    println!("y: {}", y);
}

This matters if you have short-lived borrows that overlap with later mutable borrows; the code compiles without refactoring.

How does the 2018 edition simplify the module system?

The 2018 edition removes the need for extern crate and mod.rs, and introduces crate-relative paths.

  • External crates are brought into scope automatically; you can use foo::Bar; directly.
  • Macros are imported with use instead of #[macro_use].
  • Absolute paths start with the crate name, and the keyword crate refers to the current crate.
  • A foo.rs file and a foo/ directory can coexist without a mod.rs.

Watch out for code that relied on the old mod.rs convention; a simple rename may be required when migrating.

What can I do with const fn in Rust 1.31?

const fn lets you evaluate functions at compile time in constant contexts.

Only a limited subset of operations is allowed, such as integer arithmetic, array construction, and calls to other const fns.

const fn add_one(x: i32) -> i32 {
    x + 1
}
const SIX: i32 = add_one(5);

This matters if you need compile-time computed values for array sizes, const generics, or static initialisation.

Which new tooling improvements are shipped with Rust 1.31?

Clippy and Rustfmt both reach 1.0 stability, and IDE support has been significantly upgraded.

  • Install Clippy with rustup component add clippy and run cargo clippy.
  • Install Rustfmt with rustup component add rustfmt and run cargo fmt. The formatter guarantees backwards-compatible output.
  • RLS-based editors now provide reliable type information, go-to-definition, and documentation look-ups.

Most teams will benefit from adding cargo fmt -- --check to CI pipelines to enforce a consistent style.

How does Cargo change in Rust 1.31?

Cargo now downloads dependencies in parallel using HTTP/2 and supports crate renaming directly in Cargo.toml.

[dependencies]
my_logger = { version = "0.2", package = "log" }

This matters for large dependency graphs where download time was a bottleneck, and for projects that need to avoid name clashes.

Frequently Asked Questions

Does Rust 1.31 require me to change my Cargo.toml to use the 2018 edition?
You only need to add edition = "2018" under [package] if you want the new edition; existing projects continue to work unchanged.

Can I use non-lexical lifetimes in a 2015 edition crate?
Non-lexical lifetimes are currently exclusive to the 2018 edition and will be back-ported later.

What syntax replaces extern crate in Rust 1.31?
You can simply write use foo::Bar; and the compiler will resolve the external crate automatically.

How do I declare a compile-time constant using const fn?
Write const fn add_one(x: i32) -> i32 { x + 1 } and then const RESULT: i32 = add_one(5);.

Is parallel downloading of crates enabled by default?
Yes, Cargo now automatically uses HTTP/2 to fetch dependencies in parallel without extra configuration.

Releases In Branch 1.31

VersionRelease date
1.31.120 Dec 2018
(7 years ago)
1.31.006 Dec 2018
(7 years ago)