Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMention Clone and refs in --explain E0382 #45082
Conversation
rust-highfive
assigned
eddyb
Oct 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
How do I keep getting assigned to suggestion PR?! r? @nikomatsakis |
rust-highfive
assigned
nikomatsakis
and unassigned
eddyb
Oct 7, 2017
nikomatsakis
reviewed
Oct 9, 2017
| ``` | ||
| #[derive(Clone)] | ||
| struct MyStruct { s: u32 } |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Oct 9, 2017
Contributor
I am trying to figure out how to tie in the copy vs clone dichotomy a bit better here. I think it's useful to explain when you would want what. I sometimes mention a three-level grouping here:
- Default: represents a unique resource
- Example: Money
- Implements Clone: represents a resource, but one that can be copied
- Example: Vector, String
- Implements Copy and Clone: represents a value with no ownership semantics
- Example: integer
I am torn between keeping the presentation as you did it -- with one type (MyStruct) that grows impls -- versus changing to give a bit more semantics context. For example, one could have struct MyStruct { values: Vec<u32> } for clone and change to struct Point { x: u32, y: u32 } or something as an example where Copy would be appropriate.
Really, I'd prefer to tag in somebody like @steveklabnik or @carols10cents here -- it seems like we should work hard to ensure that this extended error message ties in well with the way that the book explains things.
This comment has been minimized.
This comment has been minimized.
jacwah
Oct 9, 2017
Author
Contributor
Yeah, I think giving better examples is a good idea. Clone vs Copy is explained as heap vs stack data in the book. I'm not sure this is the best way to go about it though. I like your explanation better, focusing on semantics instead of low-level memory layout which may be less familiar to a newcomer.
This comment has been minimized.
This comment has been minimized.
steveklabnik
Oct 11, 2017
Member
I also like Niko's framing as well; the book tries to do a fairly low-level explanation, but once you grasp that, the higher-level one is better, IMO.
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
steveklabnik
and unassigned
nikomatsakis
Oct 9, 2017
carols10cents
added
the
S-waiting-on-review
label
Oct 9, 2017
This comment has been minimized.
This comment has been minimized.
|
Around here is where we first discuss Clone/Copy in the book. |
This comment has been minimized.
This comment has been minimized.
|
I'd be okay with merging this, but if you want to try something like @nikomatsakis suggested, I'd be open to it as well. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis @steveklabnik I updated some of the examples. They hopefully show the use cases for different strategies a bit better. |
kennytm
requested changes
Oct 14, 2017
| x.s = 6; | ||
| println!("{}", x.s); | ||
| let mut p1 = Point{ x: -1, y: 2 }; | ||
| let y = p2; |
This comment has been minimized.
This comment has been minimized.
kennytm
Oct 14, 2017
Member
You mean let p2 = p1; here?
[01:14:25] ---- /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index (line 6184) stdout ----
[01:14:25] error[E0425]: cannot find value `p2` in this scope
[01:14:25] --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:6:13
[01:14:25] |
[01:14:25] 6 | let y = p2;
[01:14:25] | ^^ did you mean `p1`?
[01:14:25]
[01:14:25] error[E0425]: cannot find value `p2` in this scope
[01:14:25] --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:9:28
[01:14:25] |
[01:14:25] 9 | println!("p2: {}, {}", p2.x, p2.y);
[01:14:25] | ^^ did you mean `p1`?
[01:14:25]
[01:14:25] error[E0425]: cannot find value `p2` in this scope
[01:14:25] --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:9:34
[01:14:25] |
[01:14:25] 9 | println!("p2: {}, {}", p2.x, p2.y);
[01:14:25] | ^^ did you mean `p1`?
[01:14:25]
[01:14:25] thread 'rustc' panicked at 'couldn't compile the test', /checkout/src/librustdoc/test.rs:283:12
kennytm
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Oct 14, 2017
This comment has been minimized.
This comment has been minimized.
|
|
kennytm
approved these changes
Oct 14, 2017
jacwah
force-pushed the
jacwah:explain-E0382
branch
from
3d2c35e
to
47ea51e
Oct 14, 2017
This comment has been minimized.
This comment has been minimized.
|
I squashed and rebased the work on master. Should be good to go :) |
kennytm
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
Oct 14, 2017
steveklabnik
approved these changes
Oct 17, 2017
This comment has been minimized.
This comment has been minimized.
|
Thanks a ton! @bors: r+ rollup |
This comment has been minimized.
This comment has been minimized.
|
|
jacwah commentedOct 7, 2017
I followed the discussion in #42446 and came up with these additions.
ClonebeforeCopy. Cloning has wider applicability and#derive[Copy, Clone]makes more sense after learning aboutClone.The language is not great, any suggestions there would be appreciated✨