We are pleased to introduce the new version of Rust 1.12. Rust is a system programming language aimed at the safe work with memory, speed and parallel code execution.
As usual, you can install Rust 1.12 from the corresponding page of the official site, and also get acquainted with the detailed list of changes in this version on GitHub. This release includes 1361 patches.
Release 1.12 is possibly the most significant since release 1.0. We have something to tell, but if you have little time, here is a brief summary.
The most noticeable change for users in 1.12 is the new error format issued by rustc
. We talked about it before and this is the first stable release, where the new format is available to all. These error messages are the result of numerous efforts by volunteers who designed, tested and updated every rustc
error in accordance with the new format. We are interested to know what you think about new bugs:
The biggest internal change is the transition to the use of a new compiler backend based on Rust MIR ( English Medium Intermediate Representation). Although this feature currently does not give us anything visible to users, it paves the way for several future compiler optimizations, and for some code bases it already provides an increase in compilation speed and a decrease in the size of the generated code.
At 1.12, we present a new error message format. It details the reasons why the compiler refuses to compile your code. To do this, we put your code in the spotlight and highlight the parts that are important in each case. We also annotate every erroneous place and describe in detail what went wrong.
For example, if the type implementation did not match its declaration in 1.11, you saw the following error:
In the new format, we first show the most important parts of the code. In this case, it is the type declaration line, its definition line, and labels indicating a mismatch:
')
Initially, we developed this type of error to help in understanding the problems reported by the borrowing analyzer. But along the way, we realized that this format can be applied to a variety of different errors - for example, as in the example above. If you would like to learn more about the new system errors, see the previous blog post on this topic .
Finally, you can also get these errors in JSON using the flag. Remember that mistake that we showed at the beginning of the post? This is how an attempt to compile that code looks like, passing it the flag --error-format=json
:
$ rustc borrowck-assign-comp.rs --error-format=json {"message":"cannot assign to `px` because it is borrowed","level":"error","spans":[{"file_name":"borrowck-assign-comp.rs","byte_start":562,"byte_end":563,"line_start":15,"line_end":15,"column_start":14,"column_end":15,"is_primary":false,"text":[{"text":" let q = &p;","highlight_start":14,"highlight_end":15}],"label":"borrow of `px` occurs here","suggested_replacement":null,"expansion":null}],"label":"assignment to borrowed `px` occurs here","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":null}
In fact, we omitted some details for the sake of brevity, but the idea is clear. This output is mainly for tools; we continue to work on supporting IDE and other useful developer tools. This kind of error output is a small part of this work.
A new intermediate representation of the intermediate level (mid-level IR), which we usually call "MIR", makes it easier for the compiler to work with the code on Rust than it was before - when it processed the abstract syntax tree Rust. MIR makes it possible to test and optimize, which were previously considered impossible. The first of the upcoming changes to the compiler, which became available through MIR - rewriting the pass, generating LLVM IR - what rustc
calls "translation". After many months of work, the MIR backend is finally ready to perform on the big stage.
MIR contains accurate information about the program’s control flow, so the compiler knows for certain whether the types have been moved or not. This means that he statically knows whether to destructor values. In cases where a value can be moved or not moved at the end of a block, the compiler uses a flag from just one bit on the stack, which is much better optimized by LLVM. The end result is less work for the compiler and less bloated code at runtime. It is also easier for MIR to implement new compiler passes and verify that they work correctly - because MIR is a simpler “language” than full AST.
rustc
now supports three new targets on ARM with MUSL: arm-unknown-linux-musleabi
, arm-unknown-linux-musleabihf
and armv7-unknown-linux-musleabihf
.--test-threads
argument, which indicates the number of threads used to run tests. This setting is also controlled by the environment variable. RUST_TEST_THREADS
rustup component add rust-src
command rustup component add rust-src
.lib/rustlib/src
directory.See the release notes for details.
In this issue, many types have become a bit more convenient to use.
Cell::as_ptr
and RefCell::as_ptr
IpAddr
, Ipv4Addr
and Ipv6Addr
have received several new methods.LinkedList
and VecDeque
received the method contains
.iter::Product
and iter::Sum
Option
implements From
for the type it contains.Cell
, RefCell
and UnsafeCell
implement From
for the type they contain.Cow<str>
implements FromIterator
for char
, &str
and String
SOCK_CLOEXEC
sockets on Linux are properly closed in subprocessesString
implements AddAssign
See the release notes for details.
The most interesting feature added to Cargo in this series is " workspaces ." They are defined in RFC 1525 , and allow a group of packages to share the same Cargo.lock
file. If you are engaged in a project that is divided into several packages, workspaces greatly simplify fixing a single version of common dependencies. In most projects, the inclusion of this feature will require the addition of a single line top level in Cargo.toml
, [workspace]
. More complex projects may require more tricky customization.
Another significant possibility is to overload the path to the source code of the container . You can easily distribute dependencies locally (vendoring), using it in conjunction with tools like cargo-vendor and cargo-local-registry . Over time, the crates.io mirror infrastructure will be built based on this.
There are some minor improvements:
cargo new
received flag --lib
cargo publish
received flag --dry-run
See the release notes for details.
176 people participated in the release of version 1.12. Thank you very much!
Source: https://habr.com/ru/post/311384/
All Articles