E3043
E3043 — Aforloop over a reference to a type with no method to iterate it by. The loop callsiter()forfor x in &canditer_mut()forfor x in &mut c, as Rust's collections do, so the type needs the one the loop asks for.
What the compiler reports
Error[E3043] at {{.*}}for_loop_over_a_reference_without_iter.vx:24:13: a `for` loop over a reference to Bag calls its `iter()` method, and Bag has none
Error[E3043] at {{.*}}for_loop_over_a_reference_without_iter.vx:31:12: a `for` loop over a reference to Bag calls its `iter_mut()` method, and Bag has none
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
//
//
// `for x in &b` calls `b.iter()`, and `Bag` has no such method, so the loop is refused.
// The same through a variable that holds the reference.
struct Bag {
n : i64,
}
fn main() -> i32 {
let mut b = Bag {
n : 3i64
};
let mut s = 0i64;
for x in &b {
s = s + 1i64;
}
let mut c = Bag {
n : 4i64
};
let r = &mut c;
for x in r {
s = s + 1i64;
}
return 0;
}
From tests/frontend/fail/for_loop_over_a_reference_without_iter.vx, which asserts this diagnostic on every commit.
Related
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3042A bound on a type parameter,
T : Name, where no trait called Name is declared or imported. Usually a misspelling or a missing import.
E3044A top-level const whose value is not known while compiling, or does not fit its declared type. A const holds a number or a bool: a literal, or arithmetic on literals and other consts. A const table holds a list of number literals, and is read one number at a time, as TABLE[i].