How Go detects struct copies with sync.noCopy

(func25.dev)

5 points | by func25 4 days ago

2 comments

  • CamouflagedKiwi 1 minute ago
    This feels like it should ideally be something public in the structs package so anyone can leverage it, not just a specially blessed internal thing for the sync package.
  • woadwarrior01 33 minutes ago
    > noCopy is a special marker for types that must not be copied after their first use.

    if it looks like a hack, walks like a hack, and quacks like a hack...

    • neilalexander 24 minutes ago
      It's not really a hack. It's a hint to a static analyser, that's all.
      • woadwarrior01 20 minutes ago
        Most languages would encode such behavior in a trait or a protocol instead of a zero-length struct field. It's type information and ought to be encoded in the type. From that perspective, I think it is a hack.
    • never_inline 15 minutes ago
      Every language can't be rust.