Release Rust 1.29

Original author: The Rust Core Team
  • Transfer

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. With the detailed release notes Rust 1.29.0 is available 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 automatically corrects warnings in code
  • cargo clippy - Rust code static analyzer to help catch common errors and simply improve the code

cargo fix


With the release of Rust 1.29 from 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:


fndo_something() {}
fnmain() {
    for i in0..100 {
        do_something();
    }
}

In it, we call a do_somethinghundred times, but never use a 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 with 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:


fndo_something() {}
fnmain() {
    for _i in0..100 {
        do_something();
    }
}

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


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


cargo clippy


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


For example:


letmut 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 called dropfor _link to lock_guard_, and not for the link itself lock_guard. Calling dropfor 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.github.io/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 component clippyas 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 together 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 сравнивать &strandOsString .


See the release notes for details .


Improvements in Cargo


Above, we have already described two new Cargo subcommands. Also Cargo теперь будет автоматически пытаться починить Cargo.lock файлы, испорченные git mergeom . This behavior can be disabled with a flag --locked.


cargo docI got a new flag: --document-private-items. By default, cargo doconly documents 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, it --document-private-itemswill 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.


Also popular now: