




















The Rust team is happy to announce the latest version of Rust, 1.12. Rust is a systems programming language with the slogan "fast, reliable, productive: pick three."
As always, you can install Rust 1.12 from the appropriate page on our website, and check out the detailed release notes for 1.12 on GitHub. 1361 patches were landed in this release.
The release of 1.12 might be one of the most significant Rust releases since 1.0. We have a lot to cover, but if you don't have time for that, here's a summary:
The largest user-facing change in 1.12 stable is the new error message format
emitted by rustc. We've previously talked about this format and this is the
first stable release where they are broadly available. These error messages are
a result of the effort of many hours of volunteer effort to design, test, and
update every one of rustcs errors to the new format. We're excited to see
what you think of them:

The largest internal change in this release is moving to a new compiler backend based on the new Rust MIR. While this feature does not result in anything user-visible today, it paves the way for a number of future compiler optimizations, and for some codebases it already results in improvements to compile times and reductions in code size.
With 1.12 we're introducing a new error format which helps to surface a lot of the internal knowledge about why an error is occurring to you, the developer. It does this by putting your code front and center, highlighting the parts relevant to the error with annotations describing what went wrong.
For example, in 1.11 if a implementation of a trait didn't match the trait declaration, you would see an error like the one below:

In the new error format we represent the error by instead showing the points in the code that matter the most. Here is the relevant line in the trait declaration, and the relevant line in the implementation, using labels to describe why they don't match:

Initially, this error design was built to aid in understanding borrow-checking errors, but we found, as with the error above, the format can be broadly applied to a wide variety of errors. If you would like to learn more about the design, check out the previous blog post on the subject.
Finally, you can also get these errors as JSON with a flag. Remember that error
we showed above, at the start of the post? Here's an example of attempting to
compile that code while passing the --error-format=json flag:
$ rustc borrowck-assign-comp.rs --error-format=json
{"message":"cannot assign to `p.x` 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 `p.x` occurs here","suggested_replacement":null,"expansion":null}],"label":"assignment to borrowed `p.x` occurs here","suggested_replacement":null,"expansion":null}],"children":[],"rendered":null}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":null}
We've actually elided a bit of this for brevity's sake, but you get the idea. This output is primarily for tooling; we are continuing to invest in supporting IDEs and other useful development tools. This output is a small part of that effort.
The new Rust "mid-level IR", usually called "MIR", gives the compiler a simpler
way to think about Rust code than its previous way of operating entirely on the
Rust abstract syntax tree. It makes analysis and optimizations possible that
have historically been difficult to implement correctly. The first of many
upcoming changes to the compiler enabled by MIR is a rewrite of the pass that
generates LLVM IR, what rustc calls "translation", and after many months of
effort the MIR-based backend has proved itself ready for prime-time.
MIR exposes perfect information about the program's control flow, so the compiler knows exactly whether types are moved or not. This means that it knows statically whether or not the value's destructor needs to be run. In cases where a value may or may not be moved at the end of a scope, the compiler now simply uses a single bitflag on the stack, which is in turn easier for optimization passes in LLVM to reason about. The end result is less work for the compiler and less bloat at runtime. In addition, because MIR is a simpler 'language' than the full AST, it's also easier to implement compiler passes on, and easier to verify that they are correct.
rustc supports three new MUSL targets on ARM:
arm-unknown-linux-musleabi, arm-unknown-linux-musleabihf, and
armv7-unknown-linux-musleabihf.
These targets produce statically-linked binaries. There are no binary release
builds yet though.--test-threads argument to specify the number
of threads used to run tests, and which acts the same as the
RUST_TEST_THREADS environment variablerustup component add rust-src.
The resulting source code can be used by tools and IDES, located in the
sysroot under lib/rustlib/src.See the detailed release notes for more.
This release sees a number of small quality of life improvements for various types in the standard library:
Cell::as_ptr
and
RefCell::as_ptrIpAddr, Ipv4Addr, and Ipv6Addr have a few new methods.LinkedList
and
VecDeque
have a new contains method.iter::Product and
iter::SumOption implements From for its contained
typeCell, RefCell and UnsafeCell implement From for their contained
typeCow<str> implements FromIterator for char, &str and
StringSOCK_CLOEXECString implements
AddAssignSee the detailed release notes for more.
The biggest feature added to Cargo this cycle is
"workspaces." Defined in RFC
1525,
workspaces allow a group of Rust packages to share the same Cargo.lock file.
If you have a project that's split up into multiple packages, this makes it
much easier to keep shared dependencies on a single version. To enable this
feature, most multi-package projects need to add a single key, [workspace],
to their top-level Cargo.toml, but more complex setups may require more
configuration.
Another significant feature is the ability to override the source of a crate. Using this with tools like cargo-vendor and cargo-local-registry allow vendoring dependencies locally in a robust fashion. Eventually this support will be the foundation of supporting mirrors of crates.io as well.
There are some other improvements as well:
--lib flag to cargo new--dry-run to cargo publishSee the detailed release notes for more.
We had 176 individuals contribute to 1.12. Thank you so much!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。