Skip to content

Commit dbd936b

Browse files
authored
Merge pull request #160 from ehuss/improved-error-fix
Fix error example for modern compilers.
2 parents 30d1578 + f2f5e88 commit dbd936b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/rust-2018/the-compiler/improved-error-messages.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,43 @@ error message system was created.
88

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

11-
```rust,ignore
11+
```rust,compile_fail
1212
fn main() {
1313
let mut x = 5;
14-
1514
let y = &x;
16-
1715
x += 1;
16+
println!("{} {}", x, y);
1817
}
1918
```
2019

2120
Here's the error in Rust 1.11:
2221

2322
```text
24-
foo.rs:6:5: 6:11 error: cannot assign to `x` because it is borrowed [E0506]
25-
foo.rs:6 x += 1;
23+
foo.rs:4:5: 4:11 error: cannot assign to `x` because it is borrowed [E0506]
24+
foo.rs:4 x += 1;
2625
^~~~~~
27-
foo.rs:4:14: 4:15 note: borrow of `x` occurs here
28-
foo.rs:4 let y = &x;
26+
foo.rs:3:14: 3:15 note: borrow of `x` occurs here
27+
foo.rs:3 let y = &x;
2928
^
30-
foo.rs:6:5: 6:11 help: run `rustc --explain E0506` to see a detailed explanation
29+
foo.rs:4:5: 4:11 help: run `rustc --explain E0506` to see a detailed explanation
30+
error: aborting due to previous error
3131
```
3232

3333
Here's the error in Rust 1.28:
3434

3535
```text
3636
error[E0506]: cannot assign to `x` because it is borrowed
37-
--> foo.rs:6:5
37+
--> foo.rs:4:5
3838
|
39-
4 | let y = &x;
39+
3 | let y = &x;
4040
| - borrow of `x` occurs here
41-
5 |
42-
6 | x += 1;
41+
4 | x += 1;
4342
| ^^^^^^ assignment to borrowed `x` occurs here
4443
4544
error: aborting due to previous error
45+
46+
For more information about this error, try `rustc --explain E0506`.
4647
```
4748

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

0 commit comments

Comments
 (0)