Issue #1212: A Shared/SharedMut handle used after it was handed by value reaches rustc (“Rc does not implement Copy”)

Open and answer this issue on GitHub.

ready · opened 2026-11-03 · updated 2026-11-03 · 0 comments

Part I §6.2 says that handing a Shared or SharedMut by value duplicates the handle, not the data, and the compiler steps the owner count. Today the second handle is not made: the lowering moves the Rc, and the next use fails in rustc. A backend error reaching user code is a defect (§6.8).

Probe (target/fast/nikaia run):

struct Settings { name: String, retries: int }

fn show(s: Shared[Settings]) {
    println(s.name)
}

fn main() {
    let settings = Shared(Settings { name: "prod", retries: 3 })
    let for_log = settings
    show(for_log)
    println(settings.retries)
}
error: The type `Rc` does not implement `Copy`.
   --> e2.nika:11:5
    = note: Consider using `Rc::clone`.

The same with SharedMut, which blocks every structure whose parts point at one another:

struct Node { name: String, next: SharedMut[Node]? }

fn main() {
    let a = SharedMut(Node { name: "a", next: null })
    let b = SharedMut(Node { name: "b", next: a })
    a.update fn(mut n) { n.next = b }
    println("linked")
}

.clone() on a handle is refused (NK1171), so there is no way to write it in the source either (and per §6.2 none should be needed).

Found while writing the ownership part of the syntax tour (guide/syntax.md), which marks handle sharing as not built and links here.

To build

  1. Lowering: a Shared/SharedMut/Locked handle that is handed by value (a let, an argument, a field, a list element) and used again afterwards is written as Rc::clone/Arc::clone of the handle; the last use moves it.
  2. Tests in tests/compiler/ for both probes, and for a handle handed to a task.
  3. Decide and record how a cycle of handles (the second probe) is freed: today there is no weak handle, so an owner-count cycle is never released. Either a weak handle (a language question for the supervisor) or a documented limit in §6.2.

Back to Open Issues