Skip to content

Commit 7fdf631

Browse files
committed
review comments
1 parent 2906893 commit 7fdf631

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

_posts/2018-10-25-Rust-1.30.md

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -132,56 +132,48 @@ This brings macros more in line with other items and removes the need for
132132
[externmacro]: https://github.com/rust-lang/rust/pull/50911/
133133
[Rust 1.15]: https://blog.rust-lang.org/2017/02/02/Rust-1.15.html
134134

135-
## Module system improvements
136-
137-
The module system has long been a pain point of new Rustaceans; several of
138-
its rules felt awkward in practice. These changes are the first steps we're
139-
taking to make the module system feel more straightforward.
135+
Finally, the [`proc_macro` crate](https://doc.rust-lang.org/stable/proc_macro/)
136+
is made stable, which gives you the needed APIs to write these sorts of macros.
137+
It also has significantly improved the APIs for errors, and crates like `syn` and
138+
`quote` are already using them. For example, before:
140139

141-
[`mod.rs` files are now optional][optionalmod]. Imagine we had a `foo`
142-
submodule with a `bar` submodule of its own. The directory layout would
143-
look like this:
144-
145-
```text
146-
.
147-
├── src
148-
│ ├── foo
149-
│ │ └── mod.rs
150-
│ │ └── bar.rs
151-
│ └── lib.rs
140+
```rust,ignore
141+
#[derive(Serialize)]
142+
struct Demo {
143+
ok: String,
144+
bad: std::thread::Thread,
145+
}
152146
```
153147

154-
In Rust 1.30, you can do this instead:
148+
used to give this error:
155149

156150
```text
157-
.
158-
├── src
159-
│ ├── foo
160-
│ │ └── bar.rs
161-
│ ├── foo.rs
162-
│ └── lib.rs
151+
error[E0277]: the trait bound `std::thread::Thread: _IMPL_SERIALIZE_FOR_Demo::_serde::Serialize` is not satisfied
152+
--> src/main.rs:3:10
153+
|
154+
3 | #[derive(Serialize)]
155+
| ^^^^^^^^^ the trait `_IMPL_SERIALIZE_FOR_Demo::_serde::Serialize` is not implemented for `std::thread::Thread`
163156
```
164157

165-
This means that you'll no longer have plenty of tabs all named `mod.rs` in
166-
your IDE! It also eases the process of adding a submodule; before `bar`
167-
existed, the project would look like this:
158+
Now it will give this one:
168159

169160
```text
170-
.
171-
├── src
172-
│ ├── foo.rs
173-
│ └── lib.rs
161+
error[E0277]: the trait bound `std::thread::Thread: serde::Serialize` is not satisfied
162+
--> src/main.rs:7:5
163+
|
164+
7 | bad: std::thread::Thread,
165+
| ^^^ the trait `serde::Serialize` is not implemented for `std::thread::Thread`
174166
```
175167

176-
Many users found the need to move `foo.rs` into `foo/mod.rs` to be an
177-
unncessary, strage requirement. With the new layout, you create `src/foo`,
178-
put `bar.rs` in it, and you're done.
168+
## Module system improvements
179169

180-
[optionalmod]: https://github.com/rust-lang/rust/pull/54072
170+
The module system has long been a pain point of new Rustaceans; several of
171+
its rules felt awkward in practice. These changes are the first steps we're
172+
taking to make the module system feel more straightforward.
181173

182-
There's two changes to `use` as well, in addition to the aforementioned change for
183-
macros. The first is that you can now always [`use` an extern crate without
184-
`::`][nocoloncolon], that is:
174+
There's two changes to `use` in addition to the aforementioned change for
175+
macros. The first is that [external crates are now in the
176+
prelude][nocoloncolon], that is:
185177

186178
```rust
187179
// old
@@ -313,13 +305,26 @@ Rust 2018.
313305

314306
[rawidents]: https://github.com/rust-lang/rust/pull/53236/
315307

316-
## Other things
308+
## `no_std` applications
317309

318-
Finally, you can [use the `#[panic_handler]`][panichandler] attribute to
319-
implement panics yourself, and you can now [match on visibility keywords,
320-
like `pub`, in macros][viskeyword] using the `vis` specifier.
310+
Back in Rust 1.6, we announced the [stabilization of `no_std` and
311+
`libcore`](https://blog.rust-lang.org/2016/01/21/Rust-1.6.html) for building
312+
projects without the standard library. There was a twist, though: you could
313+
only build libraries, but not applications.
314+
315+
With Rust 1.30, you can [use the `#[panic_handler]`][panichandler] attribute
316+
to implement panics yourself. This now means that you can build applications,
317+
not just libraries, that don't use the standard library.
321318

322319
[panichandler]: https://github.com/rust-lang/rust/pull/51366/
320+
## Other things
321+
322+
Finally, you can now [match on visibility keywords, like `pub`, in
323+
macros][viskeyword] using the `vis` specifier. Additionally, "tool
324+
attributes" like `#[rustfmt::skip]` [are now
325+
stable](https://github.com/rust-lang/rust/pull/53459/). Tool *lints*
326+
like `#[allow(clippy::something)]` are not yet stable, however.
327+
323328
[viskeyword]: https://github.com/rust-lang/rust/pull/53370/
324329

325330
See the [detailed release notes][notes] for more.

0 commit comments

Comments
 (0)