Skip to content

Commit d79fdb3

Browse files
Merge pull request #268 from rust-lang/1.29-announcement
Announcing Rust 1.29
2 parents 51e0322 + bb62348 commit d79fdb3

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

_posts/2018-09-13-Rust-1.29.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.29"
4+
author: The Rust Core Team
5+
---
6+
7+
The Rust team is happy to announce a new version of Rust, 1.29.0. Rust is a
8+
systems programming language focused on safety, speed, and concurrency.
9+
10+
If you have a previous version of Rust installed via rustup, getting Rust
11+
1.29.0 is as easy as:
12+
13+
```bash
14+
$ rustup update stable
15+
```
16+
17+
If you don't have it already, you can [get `rustup`][install] from the
18+
appropriate page on our website, and check out the [detailed release notes for
19+
1.29.0][notes] on GitHub.
20+
21+
[install]: https://www.rust-lang.org/install.html
22+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1290-2018-09-13
23+
24+
## What's in 1.29.0 stable
25+
26+
The 1.29 release is fairly small; Rust 1.30 and 1.31 are going to have a lot
27+
in them, and so much of the 1.29 cycle was spent preparing for those
28+
releases. The two most significant things in this release aren't even language
29+
features: they're new abilities that Cargo has grown, and they're both about lints.
30+
31+
* `cargo fix` can automatically fix your code that has warnings
32+
* `cargo clippy` is a bunch of lints to catch common mistakes and improve your Rust code
33+
34+
### `cargo fix`
35+
36+
With the release of Rust 1.29, Cargo has a new subcommand: `cargo fix`. If you've written
37+
code in Rust before, you've probably seen a compiler warning before. For example, consider
38+
this code:
39+
40+
```rust
41+
fn do_something() {}
42+
43+
fn main() {
44+
for i in 0..100 {
45+
do_something();
46+
}
47+
}
48+
```
49+
50+
Here, we're calling `do_something` a hundred times. But we never use the variable `i`.
51+
And so Rust warns:
52+
53+
```text
54+
> cargo build
55+
Compiling myprogram v0.1.0 (file:///path/to/myprogram)
56+
warning: unused variable: `i`
57+
--> src\main.rs:4:9
58+
|
59+
4 | for i in 1..100 {
60+
| ^ help: consider using `_i` instead
61+
|
62+
= note: #[warn(unused_variables)] on by default
63+
64+
Finished dev [unoptimized + debuginfo] target(s) in 0.50s
65+
```
66+
67+
See how it suggests that we use `_i` as a name instead? We can automatically
68+
apply that suggestion with `cargo fix`:
69+
70+
```console
71+
> cargo fix
72+
Checking myprogram v0.1.0 (file:///C:/Users/steve/tmp/fix)
73+
Fixing src\main.rs (1 fix)
74+
Finished dev [unoptimized + debuginfo] target(s) in 0.59s
75+
```
76+
77+
If we look at `src\main.rs` again, we'll see that the code has changed:
78+
79+
```rust
80+
fn do_something() {}
81+
82+
fn main() {
83+
for _i in 0..100 {
84+
do_something();
85+
}
86+
}
87+
```
88+
89+
We're now using `_i`, and the warning will no longer appear.
90+
91+
This initial release of `cargo fix` only fixes up a small number of warnings.
92+
The compiler has an API for this, and it only suggests fixing lints that
93+
we're confident recommend correct code. Over time, as our suggestions
94+
improve, we'll be expanding this to automatically fix more warnings.
95+
96+
### `cargo clippy`
97+
98+
Speaking of warnings, you can now check out a preview of `cargo clippy` through Rustup.
99+
Clippy is a large number of additional warnings that you can run against your Rust code.
100+
101+
For example:
102+
103+
```rust
104+
let mut lock_guard = mutex.lock();
105+
106+
std::mem::drop(&lock_guard)
107+
108+
operation_that_requires_mutex_to_be_unlocked();
109+
```
110+
111+
This code is syntactically correct, but may have a deadlock! You see, we
112+
dropped *a reference to `lock_guard`*, not the guard itself. Dropping
113+
a reference is a no-op, and so this is almost certainly a bug.
114+
115+
We can get the preview of Clippy from Rustup:
116+
117+
```console
118+
$ rustup component add clippy-preview
119+
```
120+
121+
and then run it:
122+
123+
```console
124+
$ cargo clippy
125+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
126+
--> src\main.rs:5:5
127+
|
128+
5 | std::mem::drop(&lock_guard);
129+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
130+
|
131+
= note: #[deny(drop_ref)] on by default
132+
note: argument has type &std::result::Result<std::sync::MutexGuard<'_, i32>, std::sync::PoisonError<std::sync::MutexGuard<'_, i32>>>
133+
--> src\main.rs:5:20
134+
|
135+
5 | std::mem::drop(&lock_guard);
136+
| ^^^^^^^^^^^
137+
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#drop_ref
138+
```
139+
140+
As you can see from that help message, you can view all of the lints that
141+
clippy offers on the web.
142+
143+
Please note that this is a preview; clippy has not yet reached 1.0. As such,
144+
its lints may change. We'll release a `clippy` component once it has stabilized;
145+
please give the preview a try and let us know how it goes.
146+
147+
Oh, and one more thing: [you can't use clippy with `cargo-fix` yet,
148+
really](https://github.com/rust-lang-nursery/rustfix/issues/130). It's in the works!
149+
150+
See the [detailed release notes][notes] for more.
151+
152+
### Library stabilizations
153+
154+
Three APIs were stabilized this release:
155+
156+
* [`Arc<T>::downcast`](https://doc.rust-lang.org/std/sync/struct.Arc.html#method.downcast)
157+
* [`Rc<T>::downcast`](https://doc.rust-lang.org/std/rc/struct.Rc.html#method.downcast)
158+
* [`Iterator::flatten`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.flatten)
159+
160+
Additionally, you can [now compare `&str` and
161+
`OsString`](https://github.com/rust-lang/rust/pull/51178/).
162+
163+
See the [detailed release notes][notes] for more.
164+
165+
### Cargo features
166+
167+
We covered the two new subcommands to Cargo above, but additionally, [Cargo
168+
will now try to fix up lockfiles that have been corrupted by a `git
169+
merge`](https://github.com/rust-lang/cargo/pull/5831/). You can pass
170+
`--locked` to disable this behavior.
171+
172+
`cargo doc` has also grown a new flag:
173+
[`--document-private-items`](https://github.com/rust-lang/cargo/pull/5543). By
174+
default, `cargo doc` only documents public things, as the docs it produces are
175+
intended for end-users. But if you're working on your own crate, and you have
176+
internal documentation for yourself to refer to, `--document-private-items`
177+
will generate docs for all items, not just public ones.
178+
179+
See the [detailed release notes][notes] for more.
180+
181+
## Contributors to 1.29.0
182+
183+
Many people came together to create Rust 1.29. We couldn't have done it
184+
without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.29.0)

0 commit comments

Comments
 (0)