E3055

E3055 — A 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.

What the compiler reports

Error[E3055] at {{.*}}tasks_cannot_share_a_slice_of_cells.vx:[[@LINE+1]]:5: the task reads 's'

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
//
//
// A `Slice<T>` is `Sync` only when `T` is. A `SharedCell` can change through a shared reference,
// so two tasks cannot read a slice of cells at the same time.

import core::cell;
import core::slice;
import std::vec;

fn main() -> i32 {
  let mut v = Vec<SharedCell<i64>>::new();
  v.push(SharedCell<i64>::new(1));
  let s = v.slice(0, 1);
  tasks {
    spawn {
      let _n = s.len();
    };
    let _m = s.len();
  };
  return 0;
}

From tests/frontend/fail/tasks_cannot_share_a_slice_of_cells.vx, which asserts this diagnostic on every commit.

Related