Rust Language

What’s new in Rust 1.72

Rust was designed to make it easy to develop fast and safe system-level software. Here’s what’s new.

1 2 3 4 5 Page 4
Page 4 of 5

Announced April 23, 2020, Rust 1.43.0 was considered a fairly minor release, with no major features introduced. Changes include:

  • Developers can use item fragments to interpolate items into the body of trait, impl, and extern blocks.
  • The type inference around primitives, references, and binary operations was improved.
  • To help integration testing, Cargo will set some new environment variables for tests to find executables.
  • In the Rust library, developers can use associated constants on floats and integers directly without having to import the module. Also, there is a new primitive module that re-exports Rust primitive types, which is useful when writing a macro and developers want to ensure types are not shadowed.
  • Several APIs in the library were stabilized: Once::is_completed, f32::LOG10_2, f32::LOG2_10, f32::LOG10_2, f64::LOG10_2, f64::LOG2_10, and iter::once_with.

The new features in Rust 1.41

Rust 1.41.0, announced January 30, 2020, contains the following new features and improvements:

  • Restrictions are relaxed when implementing traits. Prior to Rust 1.41.0, the orphan rule was unnecessarily strict, obstructing composition. The rule was enforced to prevent breakages when a dependency adds a new trait, impl, with the gist being that a trait impl was only permitted if either the trait or the type being implemented is local to the current crate as opposed to a foreign crate.
  • The cargo install command, for installing binary crates and Rust-based CLI tools, now will update existing installations of the crate if a new release has been published.
  • For lock files, which are used to ensure consistent builds, a new format is introduced to avoid unnecessary merge conflicts when changing dependencies in separate branches. The new format will be used for all new lock files while existing lock files still rely on the previous format.
  • More guarantees are offered when using a Box<T> in FFI (Foreign Function Interface). Box<T>, referred to as a box, provides Rust’s simplest form of heap allocation. If developers have an extern “C” Rust function, called from C, the Rust function now can use Box<T> for some specific T, while using T* in C for the corresponding function. However, developers for now should avoid using Box<T> types for functions that are defined in C but invoked in Rust. In these cases, developers should directly mirror the C types as closely as possible.
  • Additions to the library were made, such as stabilizing the Result::map_or and Result:map_or_else. Also stabilized were the weak_count and strong_count methods. NonZero* numerics now implement From<NonZero*> if it is a smaller integer width.
  • Rust 1.41.0 will be the last version with the current level of compiler support for 32-bit Apple targets.

The new features in Rust 1.40

Rust 1.40, released in December 2019, contained the following improvements and changes:

  • It’s now possible to allow macros to themselves generate macros. This allows for far more sophisticated metaprogramming using Rust than was previously possible, except perhaps by manual code generation. It’s now also possible to use procedural macros to define types, and to use them in extern blocks. And the new todo!() macro can be used in place of the more verbose unimplemented!().
  • A new attribute, #[non_exhaustive], lets you decorate a type to indicate it might have more fields or other changes in the future. This keeps other code from overriding the definition or using it as part of an exhaustive pattern match, which might break unexpectedly later on when the type is changed.
  • Code that would have compiled under the old borrow checker, but generates a warning under the new borrow checker, will now generate hard errors. This is both to encourage cleanup of older Rust code and to allow the old borrow checker code to be phased out entirely.
  • Several new compiler targets have been added, such as Arm’s Thumb-2 Neon (version 7) and MIPS64 platforms that use the musl lightweight standard library.

The new features in Rust 1.38

Rust 1.38, released in September 2019, contains the following new features and improvements:

  • The Cargo package manager will take advantage of pipelined compilation automatically with Rust 1.38. With pipelined compilation, the compiler does not need dependencies fully built when compiling a crate. All that is needed is their metadata, such as the list of types of dependencies. Metadata is produced early in the compilation process. Some tests have shown compilation speed increases of 10 to 20 percent for optimized, clean builds of some crate graphs. 
  • Linting of some incorrect uses of mem::{unitialized, zeroed}. With this release, the rustc compiler will provide a lint for a narrow class of incorrect initializations using mem::uninitialized or mem::zeroed.
  • Extension of the #[deprecated] attribute to macros. This attribute has allowed crate authors to notify users that an item of their crate is to be deprecated and removed in a future release.
  • Developers can use std::any::type_name to get the name of a type.
  • Stabilization of a number of functions including <*const T>::cast and <*mutT>::cast.

The new features in Rust 1.37

Rust 1.37, released in August 2019, has the following new features and improvements:

  • An ability to refer to enum variants through type. Developers also can refer to enum variants with Self::Variant.
  • The cargo vendor command, previously a separate crate, is now built in to the language. The command fetches project dependencies, unpacks them into the vendordirectory, and displays the configuration snippet needed to use the vendored code during builds.
  • The rustc compiler supports profile-guided optimization, an optimizing technique for ahead-of-time compilers, via -C profile-generate and -C profile-use.
  • Developers can create unnamed const items.

The new features in Rust 1.36

Version 1.36 of the Rust systems programming language was released in July 2019. Rust 1.36 includes the following new features and enhancements:

  • The Future trait, used for declaring asynchronous work, is now stable. Asynchronous operations in Rust have been coming together in bits and pieces for several versions now, with async and await being the last important remaining pieces.
  • The alloc crate, used for managing memory, is now stable. This crate collects all of the pieces of Rust’s standard library that depend on a global memory allocation mechanism, such as Vec<T>. This way, crates that don’t use the standard library can still make use of the allocator by importing alloc separately—useful for environments where you want code sizes to be as lean as possible.
  • A new type, MaybeUninit<T>, allows you to define objects that may consist of uninitialized memory, such as a lazily allocated array. Rust’s previous mechanism for doing this was a function, mem::uninitialized, that posed many hazards in casual use. MaybeUninit<T> provides a safer way to do this that uses the constraints of Rust’s type system.
  • Non-lexical lifetimes, a feature for recent editions of Rust, has been backported to earlier editions. Non-lexical lifetimes make Rust’s borrow-checking mechanism less difficult to work with (in essence, letting you write a broader range of programs that are still valid Rust), and better able to catch problems that the borrow checker missed.

Other improvements:

  • A new implementation for the HashMap<K, V> type that runs faster and uses less memory.
  • Cargo can now run entirely offline if needed.

The new features in Rust 1.35

Version 1.35, released in May 2019, offers the following:

  • Implementation of the FnOnce, FnMut, and Fn closure traits for Box<dyn FnOnce>, Box<dyn FnMut>, and Box<dyn Fn>.
  • The dbg! macro introduced in Rust 1.32 now can be called without arguments.
  • Fn* closure traits now are implemented for Box<dyn Fn*>.
  • Stabilizations of the standard library.
  • Clippy, providing a collection of lints to catch common mistakes, added a lint, drop_bounds, which is triggered when adding a bound T: Drop to a generic function.
  • A ptr::hash function has been introduced, so developers can avoid hashing the pointed-to value of a reference and instead hash the address.
  • The value of a RefCell can be replaced through a closure. Developers can more ergonomically map and replace the current value of the cell and retrieve the old value.
  • Developers now can easily check whether a value exists in a range.
  • A number of changes have been made to the Cargo, such as the addition of a rustc-cdylib-link-arg key for build scripts to specify linker arguments for cdylib crates.

The new features in Rust 1.34

Released April 2019, Rust 1.34 includes the following new and changed features:

  • Cargo, the project and package management system for Rus, now works with registries other than the default (Crates.io), including self-hosted registries. Note that any Crates hosted on Crates.io can only depend on Crates also in Crates.io.
  • The ? operator, used for unpacking errors and valid values from Result types, can now be used in documentation tests. This makes it possible to write more fully fleshed out test examples alongside the code being documented.
  • Custom attributes can now accept arbitrary token streams. This allows custom attributes in procedural macros to be more succinct and use more idiomatic Rust code.
  • The TryFrom and TryInto traits can now allow type conversions that might allow failure.
  • Many library and API stabilizations have been added, such as support for a wider range of atomic integer types (which can be shared safely between threads).

The new features in Rust 1.33

Rust 1.33 debuted in late February 2019 with the following new features:

  • A new language concept, called pinning, is now available. Pinning allows the developer to specify an object in memory that is guaranteed not to move. The Pin type and the Unpin marker trait are used to implement this.
  • The const fn declaration, used to declare functions that can be called in constant expressions at compile time, has been expanded to cover many more use cases, such as let bindings (including mutable ones), assignment expressions, and expression statements. In short, the const fn declaration makes more of the language available in a compile-time context.
  • The use n as _ syntax allows you to import the impl of a trait without polluting the namespace it is imported into.
  • Many library elements have been stabilized by being made const.

The new features in Rust 1.32

The 1.32 version of Rust, released in January 2019, includes the following changes:

  • The dbg macro. Inserting dbg!() into a Rust application prints any println!-formattable expression to stderr, with a minimal amount of boilerplate. Inserting print statements as an aid to debugging is an old-school technique, but a reliable fallback when you just need to know the state of a variable at a given point in time.
  • The jemalloc memory allocator is no longer the default. Rust applications now use the system’s own memory allocator as the default, with jemalloc available via the jemallocator crate. Using the system allocator reduces the size of Rust binaries by about 300 KB, and makes the default behavior for Rust apps across platforms more consistent. (Rust apps built on Microsoft Windows have used the system allocator by default for some time now.)
  • Macros now have the ability to perform matching against all types of literals—strings, numerics, and char literals. This makes it easier to write macros that accept literals as parameters.
  • More refinements to the way module imports work, further reducing the amount of boilerplate needed for trivial apps.

The new features in Rust 1.31

Rust 1.31, released December 2018, marks the debut of “Rust 2018,” a new edition of the language with changes to syntax and concepts that are potentially backward incompatible.

By default, code compiled with Rust 1.31 uses the earlier Rust syntax rules, i.e. the “Rust 2015” rules. Code must be explicitly tagged with edition = ‘2018’ to use the new Rust 2018 rules.

New features in Rust 1.31 that are available only in Rust 2018 include:

  • Non-lexical lifetimes. In Rust, the compiler has strict rules for how values and variables can be defined and passed around (the “lifetimes” of variables), the better to prevent memory leaks or race conditions. With Rust 1.31, the accuracy of the compiler’s checks for those conditions have been improved. Previously, some code was rejected by the compiler even though it was technically valid and would not cause problems at runtime.
  • Module system changes. Modules, i.e. Rust’s system for managing code imports, have some counterintuitive and arcane rules. Some of these rules have been relaxed and simplified in Rust 1.31 to make it easier for newcomers to become proficient with more of the module system in a shorter time.
  • New and improved developer tools. Rust’s code linter, clippy, is now considered stable enough for production use. The same goes for rustfmt, which formats Rust code according to the official style guide.

New features in Rust 1.31 that are available to all editions of Rust include:

  • const fn. Use this feature to define a function that can be used in a constant context, and allow it to be evaluated at compile time and not run time. A const fn function has to be deterministic; i.e., it has to yield a constant of some kind.
  • Simpler lifetime syntax. The syntax rules for describing a variable’s lifetime require less boilerplate code in some common circumstances.
1 2 3 4 5 Page 4
Page 4 of 5