Rust versions / 1.40
Rust release · Dec 19, 2019
Rust 1.40: what's new, what was stabilized
Short answerRust 1.40 was released on Dec 19, 2019: 21 newly stable APIs (BTreeMap::get_key_value, HashMap::get_key_value, Option::as_deref_mut, Option::as_deref, ...); 3 compatibility notes that can affect existing code.
← Rust 1.39All versionsRust 1.41 →
21 APIs stabilized
BTreeMap::get_key_value, HashMap::get_key_value, Option::as_deref_mut, Option::as_deref, Option::flatten, UdpSocket::peer_addr, f32::to_be_bytes, f32::to_le_bytes, f32::to_ne_bytes, f64::to_be_bytes, f64::to_le_bytes, f64::to_ne_bytes, f32::from_be_bytes, f32::from_le_bytes, f32::from_ne_bytes, f64::from_be_bytes, f64::from_le_bytes, f64::from_ne_bytes, mem::take, slice::repeat, todo!
Can it break my build?
The release lists these compatibility notes. Most only affect rare code, but read them before you raise your toolchain in CI:
- [As previously announced, any previous NLL warnings in the 2015 edition are
- [The
include!macro will now warn if it failed to include the - [Using
#[inline]on function prototypes and consts now emits a warning under
Use it
rustup update stable # get the newest release
rustup install 1.40 # or exactly this one
rustup override set 1.40 # pin a project to itTo require at least this version from users of your crate, set rust-version = "1.40" under [package] in Cargo.toml. Cargo then refuses to build it on older compilers with a clear message, and with resolver 3 (the default on the 2024 edition, Rust 1.85+) it also prefers dependency versions that support it.
Full release notes
Language
- [You can now use tuple
structs and tupleenumvariant's constructors inconstcontexts.][65188] e.g.
```rust pub struct Point(i32, i32);
const ORIGIN: Point = { let constructor = Point;
constructor(0, 0) }; ```
- [You can now mark
structs,enums, andenumvariants with the#[non_exhaustive]attribute to indicate that there may be variants or fields added in the future.][64639] For example this requires adding a wild-card branch (_ => {}) to any match statements on a non-exhaustiveenum. [(RFC 2008)] - [You can now use function-like procedural macros in
externblocks and in type positions.][63931] e.g.type Generated = macro!(); - [Function-like and attribute procedural macros can now emit
macro_rules!items, so you can now have your macros generate macros.][64035] - [The
metapattern matcher inmacro_rules!now correctly matches the modern attribute syntax.][63674] For example(#[$m:meta])now matches#[attr],#[attr{tokens}],#[attr[tokens]], and#[attr(tokens)].
Compiler
- [Added tier 3 support\* for the
thumbv7neon-unknown-linux-musleabihftarget.][66103] - [Added tier 3 support for the
aarch64-unknown-none-softfloattarget.][64589] - [Added tier 3 support for the
mips64-unknown-linux-muslabi64, andmips64el-unknown-linux-muslabi64targets.][65843]
\* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.
Libraries
- [The
is_power_of_twomethod on unsigned numeric types is now aconstfunction.][65092]
Stabilized APIs
- [
BTreeMap::get_key_value] - [
HashMap::get_key_value] - [
Option::as_deref_mut] - [
Option::as_deref] - [
Option::flatten] - [
UdpSocket::peer_addr] - [
f32::to_be_bytes] - [
f32::to_le_bytes] - [
f32::to_ne_bytes] - [
f64::to_be_bytes] - [
f64::to_le_bytes] - [
f64::to_ne_bytes] - [
f32::from_be_bytes] - [
f32::from_le_bytes] - [
f32::from_ne_bytes] - [
f64::from_be_bytes] - [
f64::from_le_bytes] - [
f64::from_ne_bytes] - [
mem::take] - [
slice::repeat] - [
todo!]
Cargo
- [Cargo will now always display warnings, rather than only on fresh builds.][cargo/7450]
- [Feature flags (except
--all-features) passed to a virtual workspace will now produce an error.][cargo/7507] Previously these flags were ignored. - [You can now publish
dev-dependencieswithout including aversion.][cargo/7333]
Misc
- [You can now specify the
#[cfg(doctest)]attribute to include an item only when running documentation tests withrustdoc.][63803]
Compatibility Notes
- As previously announced, any previous NLL warnings in the 2015 edition are now hard errors.
- The
include!macro will now warn if it failed to include the entire file. Theinclude!macro unintentionally only includes the first _expression_ in a file, and this can be unintuitive. This will become either a hard error in a future release, or the behavior may be fixed to include all expressions as expected. - [Using
#[inline]on function prototypes and consts now emits a warning underunused_attributelint.]65294 Using#[inline]anywhere else inside traits orexternblocks now correctly emits a hard error.
Release notes from the Rust project's RELEASES.md (MIT or Apache-2.0); summaries above are ours.
Up next
Next releaseRust 1.41Released Jan 30, 2020.Read it next →Also worth your time
Did this answer your question?