E3054
E3054 —unsafe implof a trait other thanSend,SyncorOwned, or of no trait at all. Only those three traits make a claim that the compiler cannot check. Removeunsafe.
What the compiler reports
Error[E3054] at {{.*}}.vx:29:8: `unsafe impl Describe for Handle`: only `Send`, `Sync` and `Owned` take `unsafe impl`. Remove `unsafe`
Error[E3054] at {{.*}}.vx:31:8: `unsafe impl Handle`: an impl with no trait cannot be `unsafe`
{{^}}Semantic check failed on {{.*}}: 4 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
//
//
// An impl of `Send` or `Sync` must be `unsafe impl` (E3053). Any other impl must not be (E3054).
//
import core::marker;
trait Describe {}
struct Handle {
p : *mut i32,
}
impl Send for Handle {}
impl Sync for Handle {}
unsafe impl Describe for Handle {}
unsafe impl Handle {
fn id(self : &Handle) -> i32 {
return 1;
}
}
fn main() -> i32 {
return 0;
}
// The errors above are all the errors.
From tests/frontend/fail/unsafe_impl_only_for_send_and_sync.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.
E3053An impl of
Send or Sync with no unsafe, as in impl Send for Handle {}. The compiler derives both from the fields, and a raw pointer is neither. An impl claims one for a type that holds a raw pointer, and the compiler cannot check the claim. Write unsafe impl Send for Handle {}.
E3055A task takes a value that is not Send, or reads a variable whose type is not Sync. A task that moves a value, copies it or writes it needs Send. A task that reads a variable in place shares it with the code around the task, so it needs Sync. The error names the field that makes the type fail.