Merge pull request #90 from rylev/new-compiler-errors

Change compiler error message format to new format
pull/91/head
Steve Klabnik 6 years ago committed by GitHub
commit 7f7a597b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,21 +34,18 @@ println!("{} {}", a, b);
``` ```
```text ```text
<anon>:4:14: 4:18 error: cannot borrow `x[..]` as mutable more than once at a time error[E0499]: cannot borrow `x[..]` as mutable more than once at a time
<anon>:4 let b = &mut x[1]; --> src/lib.rs:4:18
^~~~ |
<anon>:3:14: 3:18 note: previous borrow of `x[..]` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x[..]` until the borrow ends 3 | let a = &mut x[0];
<anon>:3 let a = &mut x[0]; | ---- first mutable borrow occurs here
^~~~ 4 | let b = &mut x[1];
<anon>:6:2: 6:2 note: previous borrow ends here | ^^^^ second mutable borrow occurs here
<anon>:1 fn main() { 5 | println!("{} {}", a, b);
<anon>:2 let mut x = [1, 2, 3]; 6 | }
<anon>:3 let a = &mut x[0]; | - first borrow ends here
<anon>:4 let b = &mut x[1];
<anon>:5 println!("{} {}", a, b); error: aborting due to previous error
<anon>:6 }
^
error: aborting due to 2 previous errors
``` ```
While it was plausible that borrowck could understand this simple case, it's While it was plausible that borrowck could understand this simple case, it's

@ -12,9 +12,9 @@ fn main() {
``` ```
```text ```text
src/main.rs:3:20: 3:21 error: use of possibly uninitialized variable: `x` |
src/main.rs:3 println!("{}", x); 3 | println!("{}", x);
^ | ^ use of possibly uninitialized `x`
``` ```
This is based off of a basic branch analysis: every branch must assign a value This is based off of a basic branch analysis: every branch must assign a value
@ -50,8 +50,9 @@ fn main() {
``` ```
```text ```text
src/main.rs:6:17: 6:18 error: use of possibly uninitialized variable: `x` |
src/main.rs:6 println!("{}", x); 6 | println!("{}", x);
| ^ use of possibly uninitialized `x`
``` ```
while this does: while this does:

@ -58,7 +58,6 @@ fn foo<X: Trait>(t: X) {}
impl<'a> Trait for &'a i32 {} impl<'a> Trait for &'a i32 {}
fn main() { fn main() {
let t: &mut i32 = &mut 0; let t: &mut i32 = &mut 0;
foo(t); foo(t);
@ -66,7 +65,19 @@ fn main() {
``` ```
```text ```text
<anon>:10:5: 10:8 error: the trait bound `&mut i32 : Trait` is not satisfied [E0277] error[E0277]: the trait bound `&mut i32: Trait` is not satisfied
<anon>:10 foo(t); --> src/main.rs:9:5
^~~ |
9 | foo(t);
| ^^^ the trait `Trait` is not implemented for `&mut i32`
|
= help: the following implementations were found:
<&'a i32 as Trait>
note: required by `foo`
--> src/main.rs:3:1
|
3 | fn foo<X: Trait>(t: X) {}
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
``` ```

@ -80,14 +80,14 @@ fn main() {
``` ```
```text ```text
error: `days` does not live long enough error[E0597]: `days` does not live long enough
--> <anon>:15:1 --> src/main.rs:12:28
| |
12 | inspector = Inspector(&days); 12 | inspector = Inspector(&days);
| ---- borrow occurs here | ^^^^ borrowed value does not live long enough
... ...
15 | } 15 | }
| ^ `days` dropped here while still borrowed | - `days` dropped here while still borrowed
| |
= note: values in a scope are dropped in the opposite order they are created = note: values in a scope are dropped in the opposite order they are created

@ -24,19 +24,15 @@ would expect `foo.share()` to succeed as `foo` shouldn't be mutably borrowed.
However when we try to compile it: However when we try to compile it:
```text ```text
<anon>:11:5: 11:8 error: cannot borrow `foo` as immutable because it is also borrowed as mutable error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable
<anon>:11 foo.share(); --> src/lib.rs:11:5
^~~ |
<anon>:10:16: 10:19 note: previous borrow of `foo` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `foo` until the borrow ends 10 | let loan = foo.mutate_and_share();
<anon>:10 let loan = foo.mutate_and_share(); | --- mutable borrow occurs here
^~~ 11 | foo.share();
<anon>:12:2: 12:2 note: previous borrow ends here | ^^^ immutable borrow occurs here
<anon>:8 fn main() { 12 | }
<anon>:9 let mut foo = Foo; | - mutable borrow ends here
<anon>:10 let loan = foo.mutate_and_share();
<anon>:11 foo.share();
<anon>:12 }
^
``` ```
What happened? Well, we got the exact same reasoning as we did for What happened? Well, we got the exact same reasoning as we did for

Loading…
Cancel
Save