Skip to content

Commit 0e8ec43

Browse files
committed
Update error message E0384 to new format
Part of #35233 Fixes #35184
1 parent 877dfeb commit 0e8ec43

6 files changed

+17
-9
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
758758
lp: &LoanPath<'tcx>,
759759
assign:
760760
&move_data::Assignment) {
761-
struct_span_err!(
761+
let mut err = struct_span_err!(
762762
self.tcx.sess, span, E0384,
763763
"re-assignment of immutable variable `{}`",
764-
self.loan_path_to_string(lp))
765-
.span_note(assign.span, "prior assignment occurs here")
766-
.emit();
764+
self.loan_path_to_string(lp));
765+
err.span_label(span, &format!("re-assignment of immutable variable"));
766+
if span != assign.span {
767+
err.span_label(assign.span, &format!("first assignment to `{}`",
768+
self.loan_path_to_string(lp)));
769+
}
770+
err.emit();
767771
}
768772

769773
pub fn span_err(&self, s: Span, m: &str) {

src/test/compile-fail/asm-out-assign-imm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ fn foo(x: isize) { println!("{}", x); }
1818
target_arch = "aarch64"))]
1919
pub fn main() {
2020
let x: isize;
21-
x = 1; //~ NOTE prior assignment occurs here
21+
x = 1; //~ NOTE first assignment
2222
foo(x);
2323
unsafe {
2424
asm!("mov $1, $0" : "=r"(x) : "r"(5));
2525
//~^ ERROR re-assignment of immutable variable `x`
26+
//~| NOTE re-assignment of immutable
2627
//~| NOTE in this expansion of asm!
2728
}
2829
foo(x);

src/test/compile-fail/assign-imm-local-twice.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
fn test() {
1212
let v: isize;
13-
v = 1; //~ NOTE prior assignment occurs here
13+
v = 1; //~ NOTE first assignment
1414
println!("v={}", v);
1515
v = 2; //~ ERROR re-assignment of immutable variable
16+
//~| NOTE re-assignment of immutable
1617
println!("v={}", v);
1718
}
1819

src/test/compile-fail/liveness-assign-imm-local-in-loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn test() {
1212
let v: isize;
1313
loop {
1414
v = 1; //~ ERROR re-assignment of immutable variable
15-
//~^ NOTE prior assignment occurs here
15+
//~^ NOTE re-assignment of immutable variable
1616
v.clone(); // just to prevent liveness warnings
1717
}
1818
}

src/test/compile-fail/liveness-assign-imm-local-in-op-eq.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

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

src/test/compile-fail/liveness-assign-imm-local-with-init.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
// except according to those terms.
1010

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

0 commit comments

Comments
 (0)