Uh oh!
There was an error while loading. Please reload this page.
Add long diagnostics for "bind by-ref and by-move" - #24482
Conversation
rust-highfive
commented
Apr 15, 2015
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
nit: s/binded/bound
Preferably keep "Copy" between backticks
There was a problem hiding this comment.
I think it's also more natural if we leave off the "than the others".
Manishearth
commented
Apr 15, 2015
I'd prefer if code was marked as such, both with inline backticks and fences. It makes it easier to read. Aside from that and a couple of nits, r=me |
GuillaumeGomez
commented
Apr 15, 2015
@Manishearth, @michaelsproul: Thanks for your comments ! I corrected what you pointed. Do you see remaining things that could be improved ? |
There was a problem hiding this comment.
"The goal here is to avoid binding simultaneous by-move and by-ref"
Manishearth
commented
Apr 15, 2015
teensy bit |
michaelsproul
commented
Apr 15, 2015
I feel like this doesn't give a good reason for why bind by-move and by-ref are disallowed in the same pattern. Does anyone know? I've been unable to come up with an example that would violate memory safety. Partial moves are allowed by the compiler, which seem almost identical. Is this error due to a limitation in the compiler's ability to reason about data-overlap in patterns? |
Manishearth
commented
Apr 15, 2015
So if we have |
GuillaumeGomez
commented
Apr 15, 2015
@michaelsproul: Hum... Don't you think it would be too much ? I thought here was to give a help to the developer in order to make him understand what he made wrong and how to fix it. |
michaelsproul
commented
Apr 15, 2015
@GuillaumeGomez: I think meaningful justifications both help people learn and make them happier to follow recommendations. @Manishearth: I thought that too, but essentially the same thing works if you do it step by step: fnmain(){let p = ("x".to_string(),"y".to_string());let(_,ref y) = p;let(x, _) = p;println!("{} {}", x, y);} |
Manishearth
commented
Apr 15, 2015
Huh. That should work then. |
There was a problem hiding this comment.
This line is longer than 80 characters, might be best flowing across the next line:
There are two possible solutions.
1. Implement the `Copy` trait for the X structure:
// Code here
2. Bind the pattern's names the same way:
// Code here
(there's also a "the the" in the current version of the second case)
michaelsproul
commented
Apr 16, 2015
Thanks for doing this, sorry about the endless comments! 😄 (I avoided this error specifically because it looked hard) |
GuillaumeGomez
commented
Apr 16, 2015
@michaelsproul: No problem, it's very kind of you to help me like this ! I actually took this error because I didn't know what it was, I discovered a whole new type of errors haha. |
There was a problem hiding this comment.
I don't think this is a particularly good piece of advice. While it does indeed make the code in question compile, implementing Copy is often undesirable (such as for wide structures) and has its own set of ramifications that we should perhaps expand on here, or link to a document that does that.
There was a problem hiding this comment.
I see your point. Should I precise that it would be better to do the second solution ?
There was a problem hiding this comment.
Yes, and make the second solution the first solution.
GuillaumeGomez
commented
Apr 16, 2015
@jakub- @Manishearth: Done. Do you see anything else ? |
GuillaumeGomez
commented
Apr 16, 2015
And it's good. If anyone does see something else to change, please just ask ! |
alexcrichton
commented
Apr 16, 2015
Thanks! Could you squash the commits together as well? |
bd1e778 to
9a15234CompareGuillaumeGomez
commented
Apr 16, 2015
@alexcrichton: Done ! |
alexcrichton
commented
Apr 16, 2015
alexcrichton
commented
Apr 16, 2015
@bors: rollup |
bors
commented
Apr 17, 2015
☔ The latest upstream changes (presumably #24512) made this pull request unmergeable. Please resolve the merge conflicts. |
…=alexcrichton Part of rust-lang#24407.
9a15234 to
cf53f03CompareGuillaumeGomez
commented
Apr 17, 2015
I resolved the conflicts. |
alexcrichton
commented
Apr 17, 2015
alexcrichton
commented
Apr 18, 2015
Closing in favor of the merged version at #24542 |
I did a manual merge of all the extended error PRs as we were getting merge conflicts yesterday. I think this is preferable to merging separately as I ended up having to manually merge @nham and @GuillaumeGomez's commits. Rollup of rust-lang#24458, rust-lang#24482 and rust-lang#24488. rust-lang#24482 and rust-lang#24488 were already re-approved, and would need to be cancelled if this is merged instead.
Part of #24407.