Skip to content

Commit

Permalink
Rollup merge of rust-lang#35552 - theypsilon:master, r=jonathandturner
Browse files Browse the repository at this point in the history
Update error message E0384 to new format

Part of rust-lang#35233
Fixes rust-lang#35184

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 10, 2016
2 parents ebaadb9 + 71a34d7 commit 15221b3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
lp: &LoanPath<'tcx>,
assign:
&move_data::Assignment) {
struct_span_err!(
let mut err = struct_span_err!(
self.tcx.sess, span, E0384,
"re-assignment of immutable variable `{}`",
self.loan_path_to_string(lp))
.span_note(assign.span, "prior assignment occurs here")
.emit();
self.loan_path_to_string(lp));
err.span_label(span, &format!("re-assignment of immutable variable"));
if span != assign.span {
err.span_label(assign.span, &format!("first assignment to `{}`",
self.loan_path_to_string(lp)));
}
err.emit();
}

pub fn span_err(&self, s: Span, m: &str) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/asm-out-assign-imm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ fn foo(x: isize) { println!("{}", x); }
target_arch = "aarch64"))]
pub fn main() {
let x: isize;
x = 1; //~ NOTE prior assignment occurs here
x = 1; //~ NOTE first assignment
foo(x);
unsafe {
asm!("mov $1, $0" : "=r"(x) : "r"(5));
//~^ ERROR re-assignment of immutable variable `x`
//~| NOTE re-assignment of immutable
//~| NOTE in this expansion of asm!
}
foo(x);
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/assign-imm-local-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

fn test() {
let v: isize;
v = 1; //~ NOTE prior assignment occurs here
v = 1; //~ NOTE first assignment
println!("v={}", v);
v = 2; //~ ERROR re-assignment of immutable variable
//~| NOTE re-assignment of immutable
println!("v={}", v);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/liveness-assign-imm-local-in-loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test() {
let v: isize;
loop {
v = 1; //~ ERROR re-assignment of immutable variable
//~^ NOTE prior assignment occurs here
//~^ NOTE re-assignment of immutable variable
v.clone(); // just to prevent liveness warnings
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

fn test() {
let v: isize;
v = 2; //~ NOTE prior assignment occurs here
v = 2; //~ NOTE first assignment
v += 1; //~ ERROR re-assignment of immutable variable
//~| NOTE re-assignment of immutable
v.clone();
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/liveness-assign-imm-local-with-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
// except according to those terms.

fn test() {
let v: isize = 1; //~ NOTE prior assignment occurs here
let v: isize = 1; //~ NOTE first assignment
v.clone();
v = 2; //~ ERROR re-assignment of immutable variable
//~| NOTE re-assignment of immutable
v.clone();
}

Expand Down

0 comments on commit 15221b3

Please sign in to comment.