Skip to content

Commit

Permalink
Upgrade to edition 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jun 17, 2021
1 parent f30bc44 commit 35f4209
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ description = "The Dark Arts of Advanced and Unsafe Rust Programming"

[output.html]
git-repository-url = "https://github.com/rust-lang/nomicon"

[rust]
edition = "2018"
4 changes: 2 additions & 2 deletions src/lifetime-mismatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Given the following code:

```rust,edition2018,compile_fail
```rust,compile_fail
#[derive(Debug)]
struct Foo;
Expand Down Expand Up @@ -76,7 +76,7 @@ The following code fails to compile, because Rust doesn't understand that the bo
is no longer needed and conservatively falls back to using a whole scope for it.
This will eventually get fixed.

```rust,edition2018,compile_fail
```rust,compile_fail
# use std::collections::HashMap;
# use std::hash::Hash;
fn get_default<'m, K, V>(map: &'m mut HashMap<K, V>, key: K) -> &'m mut V
Expand Down
8 changes: 4 additions & 4 deletions src/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ The following snippet compiles, because after printing `x`, it is no longer
needed, so it doesn't matter if it is dangling or aliased (even though the
variable `x` *technically* exists to the very end of the scope).

```rust,edition2018
```rust
let mut data = vec![1, 2, 3];
let x = &data[0];
println!("{}", x);
Expand All @@ -238,7 +238,7 @@ However, if the value has a destructor, the destructor is run at the end of the
scope. And running the destructor is considered a use ‒ obviously the last one.
So, this will *not* compile.

```rust,edition2018,compile_fail
```rust,compile_fail
#[derive(Debug)]
struct X<'a>(&'a i32);
Expand All @@ -258,7 +258,7 @@ One way to convince the compiler that `x` is no longer valid is by using `drop(x
Furthermore, there might be multiple possible last uses of the borrow, for
example in each branch of a condition.

```rust,edition2018
```rust
# fn some_condition() -> bool { true }
let mut data = vec![1, 2, 3];
let x = &data[0];
Expand All @@ -278,7 +278,7 @@ borrows just being tied to the same local variable. This often happens around
loops (writing a new value of a variable at the end of the loop and using it for
the last time at the top of the next iteration).

```rust,edition2018
```rust
let mut data = vec![1, 2, 3];
// This mut allows us to change where the reference points to
let mut x = &data[0];
Expand Down

0 comments on commit 35f4209

Please sign in to comment.