Improved error messages

Minimum Rust version: 1.12

We're always working on error improvements, and there are little improvementsin almost every Rust version, but in Rust 1.12, a significant overhaul of theerror message system was created.

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

  1. fn main() {
  2. let mut x = 5;
  3. let y = &x;
  4. x += 1;
  5. println!("{} {}", x, y);
  6. }

Here's the error in Rust 1.11:

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

Here's the error in Rust 1.28:

  1. error[E0506]: cannot assign to `x` because it is borrowed
  2. --> foo.rs:4:5
  3. |
  4. 3 | let y = &x;
  5. | - borrow of `x` occurs here
  6. 4 | x += 1;
  7. | ^^^^^^ assignment to borrowed `x` occurs here
  8. error: aborting due to previous error
  9. 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 showsoff your code in context, rather than just showing the text of the lines themselves.