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) {
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);
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);
}
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
}
}
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();
}
// 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();
}