Skip to content

Q023. Does copying a value mean that it has no ownership?

Short Answer

No. Copying creates a new value with its own owner while the source retains its original value. For scalars, the copies are independent. A copied reference or raw pointer may still refer to the same underlying object, but owning the pointer value does not imply owning its referent. Resource-owning handles with automatic cleanup are therefore generally non-Copy.

Deep Dive

Ownership applies to every Rust value, including Copy values. After copying an integer, there are two distinct integer values and each follows its own owning path. Their equal bits do not make them one shared value.

Pointer-like values require another layer of reasoning. Copying &T creates another shared reference value, but both references borrow the same T. Copying a raw pointer duplicates an address without establishing ownership or validity of the pointed-to object.

This distinction explains why a raw file descriptor represented as an integer is Copy, while an owning wrapper is not. Copying the number does not duplicate the kernel resource or its cleanup right. A type that automatically closes the handle must define one owner, explicit handle duplication, or shared ownership semantics.

Internal Model

For a Copy operand, compiler analysis leaves the source place initialized and initializes the destination with another value. No ownership metadata is created at runtime.

Because Copy types cannot implement Drop, copying them cannot silently duplicate custom destructor obligations. Any relationship to external data comes from the copied value's semantics, such as borrowing through a reference, not from Copy itself.

Example

rust
#[derive(Clone, Copy)]
struct Position {
    x: i32,
    y: i32,
}

fn main() {
    let mut first = Position { x: 10, y: 20 };
    let second = first;

    first.x = 99;

    println!("{}, {}", first.x, first.y);
    println!("{}, {}", second.x, second.y);
}

Common Mistakes

  • Saying Copy types are outside Rust's ownership model.
  • Treating two equal scalar values as two owners of one shared object.
  • Assuming a copied pointer automatically owns or extends the lifetime of its referent.

Follow-ups

  • What exactly is owned when a shared reference is copied?
  • Why does copying a raw pointer not make dereferencing it safe?
  • How do Rc<T> and Arc<T> represent real shared ownership?

References

  • The Rust Programming Language
  • Rust Reference
  • Rust Standard Library