@@ -22,16 +22,185 @@ appropriate page on our website, and check out the [detailed release notes for
22
22
23
23
### What's in 1.21.0 stable
24
24
25
+ This release contains some very minor, but nice-to-have features, as well as
26
+ some new documentation.
27
+
28
+ First up, a small change to literals. Consider code like this:
29
+
30
+ ``` rust
31
+ let x = & 5 ;
32
+ ```
33
+
34
+ In Rust, this code is synonymous with:
35
+
36
+ ``` rust
37
+ let _x = 5 ;
38
+ let x = & x ;
39
+ ```
40
+
41
+ That is, the ` 5 ` here will be stored on the stack, or possibly in registers.
42
+ ` x ` will be a reference to it.
43
+
44
+ However, given that it's a literal integer, there's no reason that it * has*
45
+ to be local like this. Imagine we had a function that took a ` 'static ` argument,
46
+ like ` std::thread::spawn ` . You might use ` x ` like this:
47
+
48
+
49
+ ``` rust
50
+ use std :: thread;
51
+
52
+ fn main () {
53
+ let x = & 5 ;
54
+
55
+ thread :: spawn (move || {
56
+ println! (" {}" , x );
57
+ });
58
+
59
+ }
60
+ ```
61
+
62
+ In previous versions of Rust, this would fail to compile:
63
+
64
+ ``` text
65
+ error[E0597]: borrowed value does not live long enough
66
+ --> src/main.rs:4:14
67
+ |
68
+ 4 | let x = &5;
69
+ | ^ does not live long enough
70
+ ...
71
+ 10 | }
72
+ | - temporary value only lives until here
73
+ |
74
+ = note: borrowed value must be valid for the static lifetime...
75
+ ```
76
+
77
+ Because the ` 5 ` is local, so is its borrow, which doesn't satisfy the
78
+ requirements for ` spawn ` .
79
+
80
+ However, if you compile this on Rust 1.21, it will work. Why? Well,
81
+ if the thing being referred to is okay to put into a ` static ` , we could
82
+ instead de-sugar ` let x = &5; ` like this:
83
+
84
+ ``` rust
85
+ static FIVE : i32 = 5 ;
86
+
87
+ let x = & FIVE ;
88
+ ```
89
+
90
+ Here, since the ` FIVE ` is ` static ` , ` x ` is a ` &'static i32 ` . And so this
91
+ is what Rust will now do in this kind of case. For full details, see [ RFC 1414] ,
92
+ which was accepted in January, but started in December of 2015!
93
+
94
+ [ RFC 1414 ] : https://github.com/rust-lang/rfcs/blob/master/text/1414-rvalue_static_promotion.md
95
+
96
+ We [ now run LLVM in parallel while generating
97
+ code] ( https://github.com/rust-lang/rust/pull/43506 ) , which should reduce peak
98
+ memory usage.
99
+
100
+ The [ RLS] ( https://github.com/rust-lang-nursery/rls/ ) can now be installed
101
+ [ through rustup] ( https://github.com/rust-lang/rust/pull/44204 ) by invoking
102
+ ` rustup component add rls-preview ` . In general, many useful Rust developer
103
+ tools such as the RLS, Clippy, and ` rustfmt ` need nightly Rust; this is the
104
+ first steps toward having them work on stable Rust. Please check out the
105
+ preview, and you'll hear more about these plans in the future.
106
+
107
+ Finally, a few documentation improvements. First up, if you visit [ the docs
108
+ for ` std::os ` ] (https://doc.rust-lang.org/stable/std/os/ ), which contains
109
+ operating-system specific functionality, you'll now see more than just ` linux ` ,
110
+ the platform we build the documentation on. We've long regretted that the hosted
111
+ version of the documentation has been Linux-specific; this is a first step towards
112
+ rectifying that. This is [ specific to the standard
113
+ library] ( https://github.com/rust-lang/rust/pull/43348 ) and not for general use;
114
+ we'll hope to improve this further in the future.
115
+
116
+ Next, [ Cargo's docs are moving!] ( https://github.com/rust-lang/rust/pull/43916 )
117
+ Historically, Cargo's docs were hosted on doc.crates.io, which doesn't follow
118
+ the release train model, even though Cargo itself does. This lead to situations
119
+ where a feature would land in Cargo nightly, the docs would be updated, and
120
+ then for up to twelve weeks, users would * think* that it should work, but it
121
+ wouldn't yet. [ https://doc.rust-lang.org/cargo ] ( https://doc.rust-lang.org/cargo )
122
+ will be the new home of Cargo's docs, though for now, that URL is a redirect to
123
+ doc.crates.io. Future releases will move Cargo's docs over, and at that point,
124
+ doc.crates.io will redirect to doc.rust-lang.org/cargo. Cargo's docs have long
125
+ needed a refreshing, so expect to hear more news about Cargo's docs generally
126
+ through the end of the year.
127
+
128
+ Finally, until now, ` rustdoc ` did not have any documentation. This is now
129
+ [ fixed] ( https://github.com/rust-lang/rust/pull/43863 ) , with a new "` rustdoc `
130
+ Book," located at
131
+ [ https://doc.rust-lang.org/rustdoc ] ( https://doc.rust-lang.org/rustdoc ) . These
132
+ docs are fairly bare-bones at the moment, but we'll be improving them over
133
+ time.
25
134
26
135
See the [ detailed release notes] [ notes ] for more.
27
136
28
137
#### Library stabilizations
29
138
139
+ Not too many stabilizations this release, but there's one really great
140
+ quality of life change: due to the lack of type-level integers, arrays only
141
+ supported various traits up to size 32. This [ has now been fixed for the
142
+ ` Clone ` trait] ( https://github.com/rust-lang/rust/pull/43690 ) , which also
143
+ caused a lot of ICEs at times, when a type would be ` Copy ` but not ` Clone ` .
144
+ For other traits, [ an RFC for type-level integers was accepted
145
+ recently] ( https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md ) ,
146
+ which may help with this situation. That change has yet to be implemented, however,
147
+ though pre-requisite work is ongoing at the moment.
148
+
149
+ [ ` Rc<T> ` and ` Arc<T> ` now implement ` From<&[T]> where T: Clone ` , ` From<str> ` ,
150
+ ` From<String> ` , ` From<Box<T>> where T: ?Sized ` , and
151
+ ` From<Vec<T>> ` .] ( https://github.com/rust-lang/rust/pull/42565 )
152
+
153
+ Finally, [ ` std::mem::discriminant ` has been
154
+ stabilized] ( https://doc.rust-lang.org/std/mem/fn.discriminant.html ) , allowing
155
+ you to see what variant an ` enum ` is.
30
156
31
157
See the [ detailed release notes] [ notes ] for more.
32
158
33
159
#### Cargo features
34
160
161
+ Beyond the documentation features listed above, Cargo is gaining one major
162
+ feature in this release:
163
+ [ ` [patch] ` ] ( https://github.com/rust-lang/cargo/pull/4123 ) . Designed in [ RFC
164
+ 1969] ( https://github.com/rust-lang/rfcs/blob/master/text/1969-cargo-prepublish.md ) ,
165
+ the ` [patch] ` section of your ` Cargo.toml ` can be used when you want to
166
+ override certain parts of your dependency graph. We also have a feature,
167
+ ` [replace] ` that has similar functionality. In many ways, ` [patch] ` is the new
168
+ ` [replace] ` , and while we have no plans to deprecate or remove ` [replace] ` ,
169
+ at this point, you should use ` [patch] ` instead of ` [replace] ` .
170
+
171
+ So what's it look like? Let's say we have a ` Cargo.toml ` that looks like this:
172
+
173
+ ``` toml
174
+ [dependencies ]
175
+ foo = " 1.2.3"
176
+ ```
177
+
178
+ In addition, our ` foo ` crate depends on a ` bar ` crate, and we find a bug in
179
+ ` bar ` . To test this out, we'd download the source code for ` bar ` , and then
180
+ update our ` Cargo.toml ` :
181
+
182
+ ``` toml
183
+ [dependencies ]
184
+ foo = " 1.2.3"
185
+
186
+ [patch .crates-io ]
187
+ bar = { path = ' /path/to/bar' }
188
+ ```
189
+
190
+ Now, when you ` cargo build ` , it will use the local version of ` bar ` , rather
191
+ than the one from ` crates.io ` that ` foo ` depends on.
192
+
193
+ For more details, see the
194
+ [ documentation] ( http://doc.crates.io/manifest.html#the-patch-section ) .
195
+
196
+ Additionally:
197
+
198
+ * [ you can now ` cargo install ` multiple crates at
199
+ once] ( https://github.com/rust-lang/cargo/pull/4216 )
200
+ * [ If you're in a virtual workspace, ` --all ` is now
201
+ applied automatically] ( https://github.com/rust-lang/cargo/pull/4335 ) .
202
+ * [ ` include ` and ` exclude ` fields in your ` Cargo.toml ` accepts patterns similar
203
+ to a ` .gitignore ` ] ( https://github.com/rust-lang/cargo/pull/4270 ) .
35
204
36
205
See the [ detailed release notes] [ notes ] for more.
37
206
0 commit comments