📜 ⬆️ ⬇️

Release Rust 1.29

The Rust development team is pleased to announce the release of a new version of Rust: 1.29.0. Rust is a system programming language aimed at security, speed, and parallel code execution.


If you have a previous version of Rust installed using Rustup, then to update Rust to version 1.29.0 you just need to run:


$ rustup update stable 

If you have not yet installed Rustup, you can install it from the corresponding page of our website. Detailed notes for the release of Rust 1.29.0 can be found on GitHub.


What is included in the stable version 1.29.0


1.29 introduces very few changes. It is expected that Rust 1.30 and 1.31 will be very significant, so most of the 1.29 iteration went to prepare for future changes. The two most notable innovations of this release do not even concern the language itself: these are two new features of Cargo and both relate to warnings.



cargo fix


With the release of Rust 1.29, Cargo has a new subcommand: cargo fix . If you have ever written to Rust, then most likely you have come up with compiler warnings. For example, consider the following code:


 fn do_something() {} fn main() { for i in 0..100 { do_something(); } } 

In it, we call do_something hundred times, but never use the variable i . Rust warns us about this:


 > cargo build Compiling myprogram v0.1.0 (file:///path/to/myprogram) warning: unused variable: `i` --> src\main.rs:4:9 | 4 | for i in 1..100 { | ^ help: consider using `_i` instead | = note: #[warn(unused_variables)] on by default Finished dev [unoptimized + debuginfo] target(s) in 0.50s 

See the hint about renaming to _i ? We can automatically apply it using cargo fix :


 > cargo fix Checking myprogram v0.1.0 (file:///C:/Users/steve/tmp/fix) Fixing src\main.rs (1 fix) Finished dev [unoptimized + debuginfo] target(s) in 0.59s 

If we now open src\main.rs , we will see the corrected code:


 fn do_something() {} fn main() { for _i in 0..100 { do_something(); } } 

Now _i used in the code, and the warning is no longer issued.


The first version of cargo fix fixes not all warnings. For its work, cargo fix uses a special compiler API, which offers to fix only those warnings that we are absolutely sure of. Over time, their list will expand.


cargo clippy


More warnings: you can now try cargo-clippy via Rustup. Clippy is a static analyzer that performs many additional checks on your code.


For example:


 let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) operation_that_requires_mutex_to_be_unlocked(); 

Syntactically, this is the correct code, but we can get deadlock because we caused a drop for the _link to lock_guard _, and not for the lock_guard itself. Calling a drop on a link makes little sense and is almost certainly an error.


Install the Clippy preview version via Rustup:


 $ rustup component add clippy-preview 

and run it:


 $ cargo clippy error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing. --> src\main.rs:5:5 | 5 | std::mem::drop(&lock_guard); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: #[deny(drop_ref)] on by default note: argument has type &std::result::Result<std::sync::MutexGuard<'_, i32>, std::sync::PoisonError<std::sync::MutexGuard<'_, i32>>> --> src\main.rs:5:20 | 5 | std::mem::drop(&lock_guard); | ^^^^^^^^^^^ = help: for further information visit https://rust-lang-nursery.imtqy.com/rust-clippy/v0.0.212/index.html#drop_ref 

As can be seen from the notes to the message, you can get a complete list of all possible warnings by reference.


Please note that this is an evaluation version only; Clippy has not yet reached 1.0, so the set and behavior of checks can still change. We will release the clippy component as soon as it is stabilized, but for now we ask you to look at the preliminary version of the case and tell us about your experience.


Yes, there is another nuance: unfortunately, for now, clippy cannot be used with cargo-fix . Work on this is underway.


See the release notes for details.


Standard Library Stabilization


The following APIs have been stabilized in this release:



Also, now you can &str and OsString .


See the release notes for details.


Improvements in Cargo


Above, we have already described two new Cargo subcommands. Also, Cargo Cargo.lock , git merge . This behavior can be disabled with the --locked flag.


cargo doc got a new flag: --document-private-items . By default, cargo doc documents only public parts of the API, because it is intended to generate user documentation. But if you are working on your package and it has internal documentation, then --document-private-items will enable the generation of documentation in general for everything.


See the release notes for details.


Developers 1.29.0


A lot of people participated in the development of Rust 1.29. We could not complete the work without the participation of each of you. Thank!


From the translator: Thanks @Revertron for the help in translation.


')

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


All Articles