Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention Clone and refs in --explain E0382 #45082

Merged
merged 1 commit into from Oct 18, 2017

Conversation

Projects
None yet
9 participants
@jacwah
Copy link
Contributor

jacwah commented Oct 7, 2017

I followed the discussion in #42446 and came up with these additions.

  • Mention references before going into traits. They're probably more likely solutions.
  • Mention Clone before Copy. Cloning has wider applicability and #derive[Copy, Clone] makes more sense after learning about Clone.

The language is not great, any suggestions there would be appreciated

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Oct 7, 2017

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.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Oct 7, 2017

How do I keep getting assigned to suggestion PR?! r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Oct 7, 2017

```
#[derive(Clone)]
struct MyStruct { s: u32 }

This comment has been minimized.

@nikomatsakis

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.

@jacwah

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.

@steveklabnik

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.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 9, 2017

@carols10cents

This comment has been minimized.

Copy link
Member

carols10cents commented Oct 9, 2017

Around here is where we first discuss Clone/Copy in the book.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 11, 2017

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.

@jacwah

This comment has been minimized.

Copy link
Contributor Author

jacwah commented Oct 13, 2017

@nikomatsakis @steveklabnik I updated some of the examples. They hopefully show the use cases for different strategies a bit better.

x.s = 6;
println!("{}", x.s);
let mut p1 = Point{ x: -1, y: 2 };
let y = p2;

This comment has been minimized.

@kennytm

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
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 14, 2017

☔️ The latest upstream changes (presumably #45167) made this pull request unmergeable. Please resolve the merge conflicts.

Improve E0382 extended help message
Mention Clone and refererences, and use more realistic examples (within
the constraints of a few lines :).

@jacwah jacwah force-pushed the jacwah:explain-E0382 branch from 3d2c35e to 47ea51e Oct 14, 2017

@jacwah

This comment has been minimized.

Copy link
Contributor Author

jacwah commented Oct 14, 2017

I squashed and rebased the work on master. Should be good to go :)

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 17, 2017

Thanks a ton!

@bors: r+ rollup

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 17, 2017

📌 Commit 47ea51e has been approved by steveklabnik

kennytm added a commit to kennytm/rust that referenced this pull request Oct 18, 2017

Rollup merge of rust-lang#45082 - jacwah:explain-E0382, r=steveklabnik
Mention Clone and refs in --explain E0382

I followed the discussion in rust-lang#42446 and came up with these additions.

- Mention references before going into traits. They're probably more likely solutions.
- Mention `Clone` before `Copy`. Cloning has wider applicability and `#derive[Copy, Clone]` makes more sense after learning about `Clone`.

The language is not great, any suggestions there would be appreciated 

bors added a commit that referenced this pull request Oct 18, 2017

Auto merge of #45368 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests

- Successful merges: #44138, #45082, #45098, #45181, #45217, #45281, #45325, #45326, #45340, #45354
- Failed merges:

@alexcrichton alexcrichton merged commit 47ea51e into rust-lang:master Oct 18, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.