Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix error example for modern compilers.
  • Loading branch information
ehuss committed May 20, 2019
commit f2f5e88b91c197f6e0644fcd90c87e9bc81c77d4
27 changes: 14 additions & 13 deletions src/rust-2018/the-compiler/improved-error-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,43 @@ error message system was created.

For example, here's some code that produces an error:

```rust,ignore
```rust,compile_fail
fn main() {
let mut x = 5;

let y = &x;

x += 1;
println!("{} {}", x, y);
}
```

Here's the error in Rust 1.11:

```text
foo.rs:6:5: 6:11 error: cannot assign to `x` because it is borrowed [E0506]
foo.rs:6 x += 1;
foo.rs:4:5: 4:11 error: cannot assign to `x` because it is borrowed [E0506]
foo.rs:4 x += 1;
^~~~~~
foo.rs:4:14: 4:15 note: borrow of `x` occurs here
foo.rs:4 let y = &x;
foo.rs:3:14: 3:15 note: borrow of `x` occurs here
foo.rs:3 let y = &x;
^
foo.rs:6:5: 6:11 help: run `rustc --explain E0506` to see a detailed explanation
foo.rs:4:5: 4:11 help: run `rustc --explain E0506` to see a detailed explanation
error: aborting due to previous error
```

Here's the error in Rust 1.28:

```text
error[E0506]: cannot assign to `x` because it is borrowed
--> foo.rs:6:5
--> foo.rs:4:5
|
4 | let y = &x;
3 | let y = &x;
| - borrow of `x` occurs here
5 |
6 | x += 1;
4 | x += 1;
| ^^^^^^ assignment to borrowed `x` occurs here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0506`.
```

This error isn't terribly different, but shows off how the format has changed. It shows
off your code in context, rather than just showing the text of the lines themselves.
off your code in context, rather than just showing the text of the lines themselves.