Back to Home

Rust 1.21 Release

programming · rust · release · release

Rust 1.21 Release

Original author: The Rust Core Team
  • Transfer

The Rust team is pleased to announce the release of Rust 1.21.0. Rust is a system programming language that focuses on speed, security, and parallel code execution.


If you have a previous version of Rust installed, just upgrade:


$ rustup update stable

If you haven’t installed it yet rustup, you can install it from the corresponding page of our website. With detailed notes to Rust 1.21.0 release is available on GitHub.


What is included in the stable version 1.21.0


This release contains several small but useful language changes and new documentation.


The first change concerns literals. Consider the code:


let x = &5;

In Rust, it is similar to the following:


let _x = 5;
let x = &_x;

That is, it 5will be put on the stack or possibly in registers, but xwill be a link to it.


However, given that this is an integer literal, there is no reason to make the value so local. Imagine that we have a function that takes an 'staticargument like std::thread::spawn. Then you could use xlike this:


use std::thread;
fn main() {
    let x = &5;
    thread::spawn(move || {
        println!("{}", x);
    });
}

This code will not build in previous versions of Rust:


error[E0597]: borrowed value does not live long enough
  --> src/main.rs:4:14
   |
4  |     let x = &5;
   |              ^ does not live long enough
...
10 | }
   | - temporary value only lives until here
   |
   = note: borrowed value must be valid for the static lifetime...

Due to the locality 5, the link to it also lives too little to satisfy the requirements spawn.


But if you build it with Rust 1.21, it will work. Why? If something that the link was created to can be put in static, we could "sugarless" let x = &5;into something like:


static FIVE: i32 = 5;
let x = &FIVE;

And once FIVEis static, then xis &'static i32. So Rust will now work in such cases. See RFC 1414 , which was adopted in January 2017, but started back in December 2015 for details !


Now we run LLVM in parallel with code generation , which should reduce peak memory consumption.


RLS can now be installed through a rustup call rustup component add rls-preview. Many useful tools, such as RLS, Clippy and rustfmt, still require Rust at night, but this is the first step to their work on a stable channel. Expect further improvements in the future, but for now take a look at the preview version.


Now for the documentation improvements. First: if you look at the документацию модуля std::osfunctional of working with operating systems, you will see not only the Linuxplatform on which the documentation was compiled. We were upset for a long time that the official documentation was only for Linux. This is the first step to correcting the situation,
although so far it is available only for the standard library , and not for any package (crate). We hope to fix this in the future.


Next, the Cargo documentation is moving! Historically, the Cargo documentation was posted on doc.crates.io, which did not follow the release train model, although Cargo itself followed. This led to situations where some functionality was soon to "merge" into the night Cargo, the documentation was updated, and over the next 12 weeks, users thought that everything worked, although this was not yet true.https://doc.rust-lang.org/cargo will be the new home for Cargo documentation, although now this address simply redirects to doc.crates.io. Future releases will move the current Cargo documentation, and then doc.crates.io will redirect to doc.rust-lang.org/cargo. Cargo documentation has long been in need of updating, so expect more news about it in the near future!


Finally, prior to this release, rustdocthere was no documentation. Now this has been fixed : a new book, rustdocBook, is available at https://doc.rust-lang.org/rustdoc . Now this documentation is very primitive, but over time it will improve.


See the release notes for more details .


Stabilization in the standard library


There are not many stabilizations in this release, but there is something that makes life much easier: due to the lack of generalization regarding type-level integers, arrays only supported traits up to size 32. Now это исправлено для типажа Clone. By the way, this caused a lot of ICE (internal compiler errors) when the type implemented only Copy, but not Clone.
For other types , the RFC recently adopted on generalization regarding integers , which should correct the situation. This change has not yet been implemented, but preparatory work is already underway.


Then it was stabilized Iterator::for_each, making it possible to absorb an iterator for side effects without a forloop:


// старый способ
for i in 0..10 {
    println!("{}", i);
}
// новый способ
(0..10).for_each(|i| println!("{}", i));

Which method is better depends on the situation. In the code above, the forloop is simple, but if you build a chain of iterators, version c for_eachmay be clearer:


// старый способ
for i in (0..100).map(|x| x + 1).filter(|x| x % 2 == 0) {
    println!("{}", i);
}
// новый способ
(0..100)
    .map(|x| x + 1)
    .filter(|x| x % 2 == 0)
    .for_each(|i| println!("{}", i));

Rcand is now implementing , , , , and .ArcFrom<&[T]> where T: CloneFromFromFrom> where T: ?SizedFrom>


Stabilized функции maxand mintraitOrd .


Stabilized встроенная функция (intrinsic) needs_drop.


Finally, был стабилизирован std::mem::discriminantallowing you to find out the active enumeration option without using an matchoperator.


See the release notes for more details .


Functionality Cargo


In addition to the changes mentioned above, Cargo documentation in this release gets a big update: [patch]. Developed in RFC 1969 , [patch]your section Cargo.tomlcan be used when you want to replace parts of your dependency graph. This could have been done before, by [relace]. In short, it [patch]is new and more convenient [replace]. And although we have no plans to clean or declare obsolete [replace], you most likely should use it [patch].


How does it work [patch]? Let's say we have this Cargo.toml:


[dependencies]
foo = "1.2.3"

Also, our package (crate) foodepends on the package bar, and we found an error in bar. To verify this, we download the source code barand update our Cargo.toml:


[dependencies]
foo = "1.2.3"
[patch.crates-io]
bar = { path = '/path/to/bar' }

Now, when executed cargo build, our local version will be used bar, and not the version from crates.io, on which it actually depends foo.


See the documentation for details .


Also:



See the release notes for more details .


Developers 1.21.0


A lot of people participated in the development of Rust 1.21. We could not have achieved this without each of you. Thanks!


From the translator: Thank sasha_gav and vitvakatu for their help in translating

Read Next