rust-lang / rust-lang/rust-by-example

Ownership and moves page lacks explanation

Open Beginner friendly
#1,820 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

I would like to open a discussion about this page: Ownership and moves

The (paraphrased) code on the page says:

// _Stack_ allocated integer
let x = 5u32;
// *Copy* `x` into `y` - no resources are moved
let y = x;

// `a` is a pointer to a _heap_ allocated integer
let a = Box::new(5i32);
// *Move* `a` into `b`
let b = a;

The comment says // _Stack_ allocated integer. I thought that u32 is copied because it implements Trait std::marker::Copy, not because it happens to be on the stack. Am I unclear on the concept?

Copy vs. move is a super-important concept, and I think that there should be an explicit explanation here of WHY let y = x; is a copy and let b = a; is a move. That might mean one short paragraph mentioning Copy and why u32 implements by default it would be good. Also, a link to the trait Copy page. Even if this information is elsewhere in the book, I still think it still should be made explicitly clear here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Ownership and moves page linked in the issue and inspect its source. Clarify why the integer assignment is a copy and the boxed value assignment is a move, mention the Copy trait, and link to its documentation; done when the page explicitly explains both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.