E8006
E8006 — A call does not meet the called function's precondition (requires)
What the compiler reports
Error[E8006] at {{.*}}.vx:[[@LINE+2]]: … this call to 'take_signed' may not meet its precondition
Error[E8006] at {{.*}}.vx:[[@LINE+2]]: … this call to 'take_unsigned' may not meet its precondition
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
//
// `x as usize` stops the program when x is out of range, so then the cast has no value.
// A precondition that uses the cast cannot hold for such an x: not -5 below, nor u64::MAX.
fn take_signed(x : i64) -> i64
requires (x as usize) < 10usize {
return x;
}
fn take_unsigned(x : u64) -> u64
requires (x as usize) > 5usize {
return x;
}
fn main() -> i32 {
// Values in range meet the precondition.
let small_signed = take_signed(5i64);
let large_unsigned = take_unsigned(9223372036854775807u64);
let negative = take_signed(-5i64);
let too_large = take_unsigned(18446744073709551615u64);
return 0;
}
From tests/frontend/fail/formal_verification/a_precondition_cannot_use_a_cast_that_stops_the_program.vx, which asserts this diagnostic on every commit.
Related
Contracts and verificationThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E8005Compile-time evaluation ran more loop iterations than the budget allows. A loop whose end condition is never reached is the usual cause; without this it hung the compiler.
E8007An access clause that does not hold: an
atomic(t) whose body uses t without an atomic operation, a reads_only(t) whose body may write t, or a writes_only() whose body may write memory