E4010
E4010 — A change to a variable declared withoutmut: assigning it, or a field or element of it, borrowing it&mut, or calling a method that takes&mut selfon it. Declare itlet mut x, or for a parametermut x : T.
What the compiler reports
Error[E4010] at {{.*}}assigning_to_a_tuple_of_places.vx:18:{{.*}}`b`
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// Assigning a tuple to a tuple of places follows the rules of each assignment: a place that
// is not `mut` cannot be assigned.
//
fn main() -> i32 {
let mut a : i32 = 0;
let b : i32 = 0;
(a, b) = (1, 2);
return a + b;
}
From tests/frontend/fail/assigning_to_a_tuple_of_places.vx, which asserts this diagnostic on every commit.
Related
Ownership and borrowingThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E4009An assignment to a variable, or a field or element of it, while a
& borrow of it is still used afterwards: let r = &x; x = 2; and then a use of r. The borrow would see the value change under it.
E4011A view of a tensor (a row q[i] or a field h.t) used where a tensor of its own is held: stored in a variable that already exists (t = q[i]) or a struct field (h.t = q[i], Holder { t : q[i] }), passed to a function that takes the tensor by value (f(q[i])), or returned from a function that returns a tensor by value (return q[i]). A view shares its owner's memory and is not a copy. Bind it to a new variable with let, pass q[i].clone(), take the parameter by reference, or return a reference (-> &mut Tensor<..>).