diff --git a/book.toml b/book.toml index 37984f1..fa3715f 100644 --- a/book.toml +++ b/book.toml @@ -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" diff --git a/src/lifetime-mismatch.md b/src/lifetime-mismatch.md index 005396e..eeac382 100644 --- a/src/lifetime-mismatch.md +++ b/src/lifetime-mismatch.md @@ -2,7 +2,7 @@ Given the following code: -```rust,edition2018,compile_fail +```rust,compile_fail #[derive(Debug)] struct Foo; @@ -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, key: K) -> &'m mut V diff --git a/src/lifetimes.md b/src/lifetimes.md index 1fd43ab..9d466c7 100644 --- a/src/lifetimes.md +++ b/src/lifetimes.md @@ -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); @@ -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); @@ -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]; @@ -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];