E5003
E5003 — Trusted code in a package thatvxc --no-trusted-code NAMEnames: anunsafeblock orunsafe fn, anmlir!block, anexternfunction, anextern implor anunsafe impl. The program that uses the package gives the flag, so a new version of the package cannot add trusted code without an error.vxc --auditlists the trusted code of a program.
What the compiler reports
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:19:8: `--no-trusted-code tests` refuses trusted code in the package `tests`, and this is `unsafe impl Send for Handle`, a claim that the compiler does not check
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:21:8: {{.*}}and this is `extern impl Size for i64`, an impl outside the file of its type
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:28:3: {{.*}}and this is the `extern` function `abs`, which runs C code
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:31:11: {{.*}}and this is `unsafe fn first`
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:32:10: {{.*}}and this is an `unsafe` block
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:37:5: {{.*}}and this is an `unsafe` block
Error[E5003] at {{.*}}a_package_with_trusted_code.vx:42:16: {{.*}}and this is an `mlir!` block
Semantic check failed on '{{.*}}no_trusted_code_in_a_package.vx': 7 error(s) emitted
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
//
//
// `vxc --no-trusted-code tests` makes each use of trusted code in the package `tests` an error:
// an `unsafe impl`, an `extern impl`, an `extern` function, an `unsafe fn`, an `unsafe` block,
// one that a macro writes too, and an `mlir!` block. This file is not in the package, so its
// own `unsafe` block is not an error. Without the flag, the program runs.
import tests::modules::a_package_with_trusted_code;
fn main() -> i32 {
let n = 4i64;
let p = &n as *const i64;
let own = unsafe { p[0] };
print(checked_value() + own);
return 0;
}
// ALLOWED: {{^}}17{{$}}
// NAME: `--no-trusted-code test` names no package. Give the package with `--package test=DIR`
From tests/frontend/fail/no_trusted_code_in_a_package.vx, which asserts this diagnostic on every commit.
Related
Unsafe and FFIThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E5002An operation that only an
unsafe block allows, outside one. An access through a raw pointer, *p, p[i], p.field or a method call p.f(), is one: the compiler cannot know that the value is still at the address. So is assume.