📜 ⬆️ ⬇️

Release Rust 1.17

The Rust team is pleased to present the release of Rust 1.17.0. Rust is a system programming language aimed at security, speed, and parallel code execution.


If you have a previous version of Rust installed, then it’s enough to upgrade:


$ rustup update stable 

If you have not yet installed Rust, then you can rustup from the corresponding page of our website and read the detailed release notes for 1.17.0 on GitHub.


What is included in the stable version 1.17.0


The release of Rust 1.17.0 mainly introduces minor improvements, mainly regarding usability. For example, 'static now automatically implied for constants or static variables . When creating a constant or static variable:



 const NAME: &'static str = "Ferris"; static NAME: &'static str = "Ferris"; 

Rust 1.17 will allow you to no longer write 'static , since this is the only lifetime that makes sense:


 const NAME: &str = "Ferris"; static NAME: &str = "Ferris"; 

In some situations, this will get rid of unnecessary repetitions:


 //  const NAMES: &'static [&'static str; 2] = &["Ferris", "Bors"]; //  const NAMES: &[&str; 2] = &["Ferris", "Bors"]; 

Another similar cosmetic enhancement is the "short field initialization". Like ECMAScript 6, which calls this the "Object Literal Property Value Shorthand" Value Reduction, duplication can be removed when declaring structures, for example:


 //  struct Point { x: i32, y: i32, } let x = 5; let y = 6; //  let p = Point { x: x, y: y, }; //  let p = Point { x, y, }; 

That is, the entry form x, y will assume that the values ​​of x and y correspond to variables with similar names that are in a given scope.


Another small but useful improvement concerns mostly newcomers to Rust, who try to use + to connect the two &str together. But it does not work, you can connect only String + &str . Therefore, a new error message has been added to help users who make this error:


 //  "foo" + "bar" //  error[E0369]: binary operation `+` cannot be applied to type `&'static str` --> <anon>:2:5 | 2 | "foo" + "bar" | ^^^^^ | note: an implementation of `std::ops::Add` might be missing for `&'static str` --> <anon>:2:5 | 2 | "foo" + "bar" | ^^^^^ //  error[E0369]: binary operation `+` cannot be applied to type `&'static str` --> <anon>:2:5 | 2 | "foo" + "bar" | ^^^^^ | = note: `+` can't be used to concatenate two `&str` strings help: to_owned() can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left. | "foo".to_owned() + "bar" 

When using Cargo Cargo.toml scripts, you must specify the location of the script in your Cargo.toml . However, the vast majority of people wrote build = "build.rs" , thereby using the build.rs file located in the project root. Now this agreement is supported by Cargo itself , and will be used by default if the file build.rs . We have warned about this change in the last few issues. You can also use build = false to opt out of this agreement.


In this release, the old Makefile based build system has been removed . The new system, announced in Rust 1.15, is written in Rust and mainly uses Cargo to manage the assembly. At the moment, it is already mature enough to be the only assembly system.


As part of this change, packages from crates.io can now be used in the Rust build system. The first mdBook was added, and it is now used to build our various book documentation:



Note the links to the relevant repositories; Documents have been moved from the main tree. In addition, we added the fourth book, which is still located in the main tree: The book "Unstable Rust Opportunities . " It describes unstable features, contains links to tasks related to their stabilization, and may contain source documentation. If there is an opportunity that you want to see stabilized, then please participate in its discussion!


A few issues ago, rustup stopped installing documentation by default. We made this change to relieve the feed a bit, and also because not all users really want to keep a local copy of the documentation. However, this created a trap: some users were not aware that a change had taken place, and would have noticed it only if their Internet connection was lost. In addition, some users wanted to have a local copy of the documentation, regardless of their connection. Thus, we rolled back this change , and the documentation is again set to default.


Finally, although this release is full of improvements, there is one small step back that we want to inform you about with regret. On Windows, Visual Studio 2017 was released, and Microsoft changed the software installation structure. Rust cannot automatically determine its location , and although we worked on the necessary changes, we did not have time for this release. Until then, Visual Studio 2015 is still working fine, or you can run vcvars.bat on the command line. We hope that this work will be completed as soon as possible.


See the release notes for details.


Library stabilization


21 new interfaces have been stabilized:



As for the other changes, many Cell<T> methods required the T: Copy constraint, but now this requirement has been greatly relaxed .


Box<T> now implements over a dozen new transformations using From .


SocketAddr and IpAddr also now have several new conversions . Before, you had to write code like this:


 "127.0.0.1:3000".parse().unwrap() 

Now you can write


 SocketAddr::from(([127, 0, 0, 1], 3000)) //  ([127, 0, 0, 1], 3000).into()) 

That will remove unnecessary parsing at runtime. Both options are about equally readable, it all depends on your preferences.


Reverse tracing now has more pleasant formatting , omitting some minor details by default. For example, a full back trace:


 thread 'main' panicked at 'explicit panic', foo.rs:2 stack backtrace: 1: 0x55c39a23372c - std::sys::imp::backtrace::tracing::imp::write::hf33ae72d0baa11ed at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42 2: 0x55c39a23571e - std::panicking::default_hook::{{closure}}::h59672b733cc6a455 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:351 3: 0x55c39a235324 - std::panicking::default_hook::h1670459d2f3f8843 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:367 4: 0x55c39a235afb - std::panicking::rust_panic_with_hook::hcf0ddb069e7beee7 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:555 5: 0x55c39a22e866 - std::panicking::begin_panic::heb433e9aa28a7408 6: 0x55c39a22e9bf - foo::main::hd216d4a160fcce19 7: 0x55c39a23d44a - __rust_maybe_catch_panic at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98 8: 0x55c39a236006 - std::rt::lang_start::hd7c880a37a646e81 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:436 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:361 at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57 9: 0x55c39a22e9e9 - main 10: 0x7f5e5ed3382f - __libc_start_main 11: 0x55c39a22e6b8 - _start 12: 0x0 - <unknown> 

now looks like


 thread 'main' panicked at 'explicit panic', foo.rs:2 stack backtrace: 0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::_print at /checkout/src/libstd/sys_common/backtrace.rs:71 2: std::panicking::default_hook::{{closure}} at /checkout/src/libstd/sys_common/backtrace.rs:60 at /checkout/src/libstd/panicking.rs:355 3: std::panicking::default_hook at /checkout/src/libstd/panicking.rs:371 4: std::panicking::rust_panic_with_hook at /checkout/src/libstd/panicking.rs:549 5: std::panicking::begin_panic 6: foo::main 7: __rust_maybe_catch_panic at /checkout/src/libpanic_unwind/lib.rs:98 8: std::rt::lang_start at /checkout/src/libstd/panicking.rs:433 at /checkout/src/libstd/panic.rs:361 at /checkout/src/libstd/rt.rs:57 9: main 10: __libc_start_main 11: _start 

default. You can set the environment variable RUST_BACKTRACE = full to get a complete back trace. In the future, we plan to remove even more unnecessary information; See this error .


See the release notes for details.


Cargo features


In addition to the previously mentioned changes regarding build.rs , Cargo has a few more new enhancements. cargo check --all and cargo run --package are two flags that were absent up to this point, which are now supported.


Now you can ignore SSL revocation checks . Of course, the default check is still done.


A new field in Cargo.toml , required-features , allows you to specify specific features that should be set for the goal to be collected . Here is an example: suppose we write a container that interacts with databases, and we want it to support several databases. We could do this in our Cargo.toml :


 [features] # ... postgres = [] sqlite = [] tools = [] 

The tools feature allows us to include additional tools, and the capabilities of postgres and sqlite indicate which databases we want to support.


Previously, cargo build tried to collect all the goals that you need. But what if we have the src/bin/postgres-tool.rs file, which is needed only if the postgres and tools features are enabled? We used to have to write something like this:


 #[cfg(not(all(feature = "postgres", feature = "tools")))] fn main() { println!("This tool requires the `postgres` and `tools` features to be enabled."); } #[cfg(all(feature = "postgres", feature = "tools"))] fn main() { //  } 

Too much sample code to work with cargo build . Even sadder was the case with examples/ , which should demonstrate how to use your library. But such frauds are possible only when working inside the package itself, so you will fail if you try to use the example outside of this package.


With the new required-features key, we can add the following:


 [[bin]] # ... required-features = ["postgres", "tools"] 

Now cargo build will build our postgres-tool only if we have two of these features enabled, and therefore we can write a normal fn main without any heaps of cfg .


See the release notes for details.


Developers version 1.17.0


Many people have contributed to the creation of Rust 1.17. We could not have done this without all of you. Thank!




Author translation: @kgv .
I thank vitvakatu for help with the translation.
If you are interested in Rust and you have questions, join us !


')

Source: https://habr.com/ru/post/327708/


All Articles