E3053

E3053 — An 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 {}.

What the compiler reports

Error[E3053]: `impl Send for Handle` must be `unsafe impl`: the compiler derives `Send` from the fields, and cannot check this claim
Error[E3053]: `impl Sync for Handle` must be `unsafe impl`
Error[E3054]: `unsafe impl Describe for Handle`: only `Send` and `Sync` take `unsafe impl`. Remove `unsafe`
Error[E3054]: `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