Chapter 5. Changes in Rust Toolset in Red Hat Developer Tools 2019.1
This chapter lists some notable changes in Rust Toolset since its previous release.
5.1. Rust
Rust has been updated from version 1.29.0 to 1.31.1. Notable changes include:
New capabilities with defining procedural macros
-
Attribute macros let you define custom
#[name]
annotations. -
Function macros work like those defined by
macro_rules!
, but have more flexibility being implemented in Rust. -
Macros can now be imported in
use
statements, removing the need for the#[macro_use]
crate attribute. -
The
proc_macro
crate is now stable, to help write these new macros.
-
Attribute macros let you define custom
Module improvements
- External crates are now in the prelude, which allows a crate name to serve as the root of a path from anywhere.
-
The
crate
keyword now serves as the root of your own crate in paths anduse
statements.
2018 edition
-
The new 2018 edition marks a collective milestone of the last 3 years of Rust development, while also making a few opt-in breaking changes. Existing code will default to 2015 edition, with no breaking changes, and crates from different editions are fully interoperable.
cargo new
will specifyedition = "2018"
inCargo.toml
for new projects. -
async
,await
, andtry
are reserved keywords in 2018, anddyn
is now a strict keyword. - Non-lexical lifetimes are a refinement of the previous block-based lifetime system, allowing borrowed values to be released sooner in many cases to be reused elsewhere. This is initially exclusive to the 2018 edition, but planned for 2015 as well.
-
Module changes: Explicit
extern crate
declarations are unnecessary in most cases in 2018.use
paths can now be relative from the current scope, rather than always starting from the root scope as in 2015.
-
The new 2018 edition marks a collective milestone of the last 3 years of Rust development, while also making a few opt-in breaking changes. Existing code will default to 2015 edition, with no breaking changes, and crates from different editions are fully interoperable.
-
Lifetimes can now be left implicit in more cases, especially using the new
'_
placeholder. -
const fn
— Functions can be declared constant, which allows them to be used in restricted contexts, like the initialization of aconst
orstatic
value. Stable tools:
clippy
,rls
, andrustfmt
. We have been shipping these tools as preview already, but now they are officially supported.-
clippy
adds extra lints for code/style issues. -
rls
implements the Language Server protocol for IDE integration. -
rustfmt
formats your code, also integrated with thecargo fmt
subcommand.
-
-
Tool lints allow you to add warning annotations for custom lints, especially for those added by
clippy
. For example,#[allow(clippy::bool_comparison)]
will silence that warning on an item for which you deem it acceptable.
5.2. cargo
The cargo
tool has been updated from version 1.29.0 to 1.31.0. Notable changes include:
- Cargo now shows a progress bar as it builds your crates and dependencies.
-
Cargo now allows renaming dependencies in
Cargo.toml
, affecting how they are referenced in your sources. Previously, you could only rename in source likeextern crate published_name as new_name;
.