Skip to content

Commit

Permalink
Merge pull request #160 from ehuss/improved-error-fix
Browse files Browse the repository at this point in the history
Fix error example for modern compilers.
  • Loading branch information
Centril authored Jul 1, 2019
2 parents 30d1578 + f2f5e88 commit dbd936b
Showing 1 changed file with 14 additions and 13 deletions.
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.

0 comments on commit dbd936b

Please sign in to comment.