Skip to content

Commit b758688

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35552 - theypsilon:master, r=jonathandturner
Update error message E0384 to new format Part of rust-lang#35233 Fixes rust-lang#35184 r? @jonathandturner
2 parents 08d5df8 + 71a34d7 commit b758688

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
@@ -760,12 +760,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
760760
lp: &LoanPath<'tcx>,
761761
assign:
762762
&move_data::Assignment) {
763-
struct_span_err!(
763+
let mut err = struct_span_err!(
764764
self.tcx.sess, span, E0384,
765765
"re-assignment of immutable variable `{}`",
766-
self.loan_path_to_string(lp))
767-
.span_note(assign.span, "prior assignment occurs here")
768-
.emit();
766+
self.loan_path_to_string(lp));
767+
err.span_label(span, &format!("re-assignment of immutable variable"));
768+
if span != assign.span {
769+
err.span_label(assign.span, &format!("first assignment to `{}`",
770+
self.loan_path_to_string(lp)));
771+
}
772+
err.emit();
769773
}
770774

771775
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)