Skip to content

Commit 3796990

Browse files
Mark-SimulacrumCentrilpetrochenkov
committed
Apply suggestions from code review
Co-Authored-By: Mazdak Farrokhzad <[email protected]> Co-Authored-By: Vadim Petrochenkov <[email protected]>
1 parent 975b2e9 commit 3796990

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

posts/2020-03-12-Rust-1.42.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ This behavior is made possible by an annotation, `#[track_caller]`. This annotat
4848

4949
### Subslice patterns
5050

51-
In Rust 1.26, we stabilzed "slice patterns," which let you `match` on slices. They looked like this:
51+
[slice patterns]: https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#basic-slice-patterns
52+
53+
In Rust 1.26, we stabilized "[slice patterns]," which let you `match` on slices. They looked like this:
5254

5355
```rust
5456
fn foo(words: &[&str]) {
@@ -81,13 +83,13 @@ The `..` is called a "rest pattern," because it matches the rest of the slice. T
8183
```rust
8284
fn foo(words: &[&str]) {
8385
match words {
84-
// ignore everything but the last element, which must be "!"
86+
// Ignore everything but the last element, which must be "!".
8587
[.., "!"] => println!("!!!"),
86-
87-
// start is a slice of everything except the last element, which must be "z"
88+
89+
// `start` is a slice of everything except the last element, which must be "z".
8890
[start @ .., "z"] => println!("starts with: {:?}", start),
89-
90-
// end is a slice of everything but the first element, which must be "a"
91+
92+
// `end` is a slice of everything but the first element, which must be "a".
9193
["a", end @ ..] => println!("ends with: {:?}", end),
9294

9395
rest => println!("{:?}", rest),
@@ -103,17 +105,17 @@ If you're interested in learning more, we published [a post on the Inside Rust b
103105
This release of Rust stabilizes a new macro, [`matches!`](https://doc.rust-lang.org/nightly/std/macro.matches.html). This macro accepts an expression and a pattern, and returns true if the pattern matches the expression. In other words:
104106

105107
```rust
106-
// with the match keyword
108+
// Using a match expression:
107109
match self.partial_cmp(other) {
108110
Some(Less) => true,
109111
_ => false,
110112
}
111113

112-
// with the matches! macro
114+
// Using the `matches!` macro:
113115
matches!(self.partial_cmp(other), Some(Less))
114116
```
115117

116-
You can also use features like `|` patterns and `if` clauses:
118+
You can also use features like `|` patterns and `if` guards:
117119

118120
```rust
119121
let foo = 'f';
@@ -127,7 +129,7 @@ assert!(matches!(bar, Some(x) if x > 2));
127129

128130
In Rust 2018, we [removed the need for `extern crate`](https://doc.rust-lang.org/stable/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate). But procedural macros were a bit special, and so when you were writing a procedural macro, you still needed to say `extern crate proc_macro;`.
129131

130-
In this release, [you no longer need this line when working with the 2018 edition; you can use `use` like any other crate][cargo/7700]. Given that most projects will already have a line similar to `use proc_macro::TokenStream;`, this change will mean that you can delete the `extern crate proc_macro;` line and your code will still work. This change is small, but brings procedural macros closer to regular code.
132+
In this release, if you are using Cargo, [you no longer need this line when working with the 2018 edition; you can use `use` like any other crate][cargo/7700]. Given that most projects will already have a line similar to `use proc_macro::TokenStream;`, this change will mean that you can delete the `extern crate proc_macro;` line and your code will still work. This change is small, but brings procedural macros closer to regular code.
131133

132134
### Libraries
133135

@@ -160,8 +162,10 @@ We have two notable compatibility notes this release: a deprecation in the stand
160162

161163
Sometimes, mistakes are made. The `Error::description` method is now considered to be one of those mistakes. The problem is with its type signature:
162164

163-
fn description(&self) -> &str {
164-
165+
```rust
166+
fn description(&self) -> &str
167+
```
168+
165169
Because `description` returns a `&str`, it is not nearly as useful as we wished it would be. This means that you basically need to return the contents of an `Error` verbatim; if you wanted to say, use formatting to produce a nicer description, that is impossible: you'd need to return a `String`. Instead, error types should implement the `Display`/`Debug` traits to provide the description of the error.
166170

167171
This API has existed since Rust 1.0. We've been working towards this goal for a long time: back in Rust 1.27, we ["soft deprecated" this method](https://github.com/rust-lang/rust/pull/50163). What that meant in practice was, we gave the function a default implementation. This means that users were no longer forced to implement this method when implementing the `Error` trait. In this release, [we mark it as *actually* deprecated][66919], and took some steps to de-emphasize the method in `Error`'s documentation. Due to our stability policy, `description` will never be removed, and so this is as far as we can go.
@@ -172,4 +176,4 @@ Apple is no longer supporting 32-bit targets, and so, neither are we. They have
172176

173177
## Contributors to 1.42.0
174178

175-
Many people came together to create Rust 1.42.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.42.0/)
179+
Many people came together to create Rust 1.42.0. We couldn't have done it without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.42.0/)

0 commit comments

Comments
 (0)