-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnostic doesn't align properly in span where line number increases by one digit #11715
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Comments
bors
added a commit
that referenced
this issue
Jan 24, 2014
A mutable and immutable borrow place some restrictions on what you can with the variable until the borrow ends. This commit attempts to convey to the user what those restrictions are. Also, if the original borrow is a mutable borrow, the error message has been changed (more specifically, i. "cannot borrow `x` as immutable because it is also borrowed as mutable" and ii. "cannot borrow `x` as mutable more than once" have been changed to "cannot borrow `x` because it is already borrowed as mutable"). In addition, this adds a (custom) span note to communicate where the original borrow ends. ```rust fn main() { match true { true => { let mut x = 1; let y = &x; let z = &mut x; } false => () } } test.rs:6:21: 6:27 error: cannot borrow `x` as mutable because it is already borrowed as immutable test.rs:6 let z = &mut x; ^~~~~~ test.rs:5:21: 5:23 note: previous borrow of `x` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `x` until the borrow ends test.rs:5 let y = &x; ^~ test.rs:7:10: 7:10 note: previous borrow ends here test.rs:3 true => { test.rs:4 let mut x = 1; test.rs:5 let y = &x; test.rs:6 let z = &mut x; test.rs:7 } ^ ``` ```rust fn foo3(t0: &mut &mut int) { let t1 = &mut *t0; let p: &int = &**t0; } fn main() {} test.rs:3:19: 3:24 error: cannot borrow `**t0` because it is already borrowed as mutable test.rs:3 let p: &int = &**t0; ^~~~~ test.rs:2:14: 2:22 note: previous borrow of `**t0` as mutable occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `**t0` until the borrow ends test.rs:2 let t1 = &mut *t0; ^~~~~~~~ test.rs:4:2: 4:2 note: previous borrow ends here test.rs:1 fn foo3(t0: &mut &mut int) { test.rs:2 let t1 = &mut *t0; test.rs:3 let p: &int = &**t0; test.rs:4 } ^ ``` For the "previous borrow ends here" note, if the span is too long (has too many lines), then only the first and last lines are printed, and the middle is replaced with dot dot dot: ```rust fn foo3(t0: &mut &mut int) { let t1 = &mut *t0; let p: &int = &**t0; } fn main() {} test.rs:3:19: 3:24 error: cannot borrow `**t0` because it is already borrowed as mutable test.rs:3 let p: &int = &**t0; ^~~~~ test.rs:2:14: 2:22 note: previous borrow of `**t0` as mutable occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `**t0` until the borrow ends test.rs:2 let t1 = &mut *t0; ^~~~~~~~ test.rs:7:2: 7:2 note: previous borrow ends here test.rs:1 fn foo3(t0: &mut &mut int) { ... test.rs:7 } ^ ``` (Sidenote: the `span_end_note` currently also has issue #11715)
This still happens. Here's a full test case with proper whitespace:
|
kmcallister
added
the
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
label
Feb 4, 2015
I'm going to poke around with this. |
How would you actually get a test to look for this, since compile-fail doesn't seem quite right. Also, what happens if #3533 goes through? That'll require undoing these changes... |
tbelaire
added a commit
to tbelaire/rust
that referenced
this issue
May 1, 2015
nham
pushed a commit
to nham/rust
that referenced
this issue
May 29, 2015
oli-obk
pushed a commit
to oli-obk/rust
that referenced
this issue
Jun 24, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
For example, in this case there should be two spaces between
8
andfn
instead of one.The text was updated successfully, but these errors were encountered: