Skip to content

Commit dc3233e

Browse files
authored
Merge pull request #1041 from ehuss/edition2018
Default all examples to 2018 edition.
2 parents 83f44e3 + 6ab7817 commit dc3233e

10 files changed

+31
-15
lines changed

book.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ additional-css = ["theme/reference.css"]
88
git-repository-url = "https://github.com/rust-lang/reference/"
99

1010
[output.html.redirect]
11-
"/expressions/enum-variant-expr.html" = "struct-expr.html"
11+
"/expressions/enum-variant-expr.html" = "struct-expr.html"
12+
13+
[rust]
14+
edition = "2018"

src/expressions/block-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Similarly, if `<expr>?` propagates an error, that error is propagated as the res
109109
Finally, the `break` and `continue` keywords cannot be used to branch out from an async block.
110110
Therefore the following is illegal:
111111
112-
```rust,edition2018,compile_fail
112+
```rust,compile_fail
113113
loop {
114114
async move {
115115
break; // This would break out of the loop.

src/introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ These conventions are documented here.
109109
}
110110
```
111111

112+
All examples are written for the latest edition unless otherwise stated.
113+
112114
* The grammar and lexical structure is in blockquotes with either "Lexer" or "Syntax" in <sup>**bold superscript**</sup> as the first line.
113115

114116
> **<sup>Syntax</sup>**\

src/items/functions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ use the [`extern` function qualifier](#extern-function-qualifier).
227227
Functions may be qualified as async, and this can also be combined with the
228228
`unsafe` qualifier:
229229

230-
```rust,edition2018
230+
```rust
231231
async fn regular_example() { }
232232
async unsafe fn unsafe_example() { }
233233
```
@@ -240,7 +240,7 @@ An async function is roughly equivalent to a function
240240
that returns [`impl Future`] and with an [`async move` block][async-blocks] as
241241
its body:
242242

243-
```rust,edition2018
243+
```rust
244244
// Source
245245
async fn example(x: &str) -> usize {
246246
x.len()
@@ -249,7 +249,7 @@ async fn example(x: &str) -> usize {
249249

250250
is roughly equivalent to:
251251

252-
```rust,edition2018
252+
```rust
253253
# use std::future::Future;
254254
// Desugared
255255
fn example<'a>(x: &'a str) -> impl Future<Output = usize> + 'a {
@@ -285,7 +285,7 @@ resulting function is unsafe to call and (like any async function)
285285
returns a future. This future is just an ordinary future and thus an
286286
`unsafe` context is not required to "await" it:
287287

288-
```rust,edition2018
288+
```rust
289289
// Returns a future that, when awaited, dereferences `x`.
290290
//
291291
// Soundness condition: `x` must be safe to dereference until

src/items/traits.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ allowed, but it is deprecated and will become a hard error in the future.
251251
In the 2015 edition, the pattern for a trait function or method parameter is
252252
optional:
253253

254-
```rust
254+
```rust,edition2015
255+
// 2015 Edition
255256
trait T {
256257
fn f(i32); // Parameter identifiers are not required.
257258
}
@@ -269,7 +270,7 @@ Beginning in the 2018 edition, function or method parameter patterns are no
269270
longer optional. Also, all irrefutable patterns are allowed as long as there
270271
is a body. Without a body, the limitations listed above are still in effect.
271272

272-
```rust,edition2018
273+
```rust
273274
trait T {
274275
fn f1((a, b): (i32, i32)) {}
275276
fn f2(_: (i32, i32)); // Cannot use tuple pattern without a body.

src/items/type-aliases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let p: Point = (41, 68);
2020

2121
A type alias to a tuple-struct or unit-struct cannot be used to qualify that type's constructor:
2222

23-
```rust,edition2018,compile_fail
23+
```rust,compile_fail
2424
struct MyStruct(u32);
2525
2626
use MyStruct as UseAlias;

src/items/use-declarations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn main() {}
144144
> unambiguously select the crate name. This is to retain compatibility with
145145
> potential future changes. <!-- uniform_paths future-proofing -->
146146
>
147-
> ```rust,edition2018
147+
> ```rust
148148
> // use std::fs; // Error, this is ambiguous.
149149
> use ::std::fs; // Imports from the `std` crate, not the module below.
150150
> use self::std::fs as self_fs; // Imports the module below.

src/paths.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ the path must resolve to an item.
172172
> crates in the [extern prelude]. That is, they must be followed by the name of a crate.
173173
174174
```rust
175+
pub fn foo() {
176+
// In the 2018 edition, this accesses `std` via the extern prelude.
177+
// In the 2015 edition, this accesses `std` via the crate root.
178+
let now = ::std::time::Instant::now();
179+
println!("{:?}", now);
180+
}
181+
```
182+
183+
```rust,edition2015
184+
// 2015 Edition
175185
mod a {
176186
pub fn foo() {}
177187
}
@@ -353,11 +363,11 @@ mod without { // ::without
353363
fn g(&self) {} // None
354364
}
355365

356-
impl OtherTrait for ::a::Struct {
366+
impl OtherTrait for crate::a::Struct {
357367
fn g(&self) {} // None
358368
}
359369

360-
impl ::a::Trait for OtherStruct {
370+
impl crate::a::Trait for OtherStruct {
361371
fn f(&self) {} // None
362372
}
363373
}

src/trait-bounds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait is implemented for a type. For example, given `Ty: Trait`
4747
```rust
4848
# type Surface = i32;
4949
trait Shape {
50-
fn draw(&self, Surface);
50+
fn draw(&self, surface: Surface);
5151
fn name() -> &'static str;
5252
}
5353

src/visibility-and-privacy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn public_api() {}
110110
// Similarly to 'public_api', this module is public so external crates may look
111111
// inside of it.
112112
pub mod submodule {
113-
use crate_helper_module;
113+
use crate::crate_helper_module;
114114

115115
pub fn my_method() {
116116
// Any item in the local crate may invoke the helper module's public
@@ -161,7 +161,7 @@ to `pub(in self)` or not using `pub` at all.
161161
162162
Here's an example:
163163

164-
```rust
164+
```rust,edition2015
165165
pub mod outer_mod {
166166
pub mod inner_mod {
167167
// This function is visible within `outer_mod`

0 commit comments

Comments
 (0)