-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Borrow check needs to consider moves into patterns #3024
Comments
I wonder if this is related to #2548... |
Interesting. There may be two bugs here. The first, I would think, is that this let assignment should not be legal. The liveness code would not ordinarily allow you to move from the inside of managed data. The second is the dtor running twice. This program exhibits the same behavior:
My guess is that the running twice part is a dup of #2548 or at least related. The other part is a shortcoming of liveness/borrowck... I'm not precisely sure where the check ought to be happening that prevents moving from the interior of a managed box, but it ought to happen somewhere. Probably borrowck since it already has the code to match up patterns and so forth. |
actually thinking more I think it's borrowck's responsibility to prevent moves from illegal places. |
Thinking more about this, I realised you should never be able to get a noncopyable out of an @-box once it's in - it's a similar problem as option::unwrap except @-boxes always "implicitly" have a loan out on their contents. Probably moving out of an @-box should always be illegal, and you should have to do it explicitly by It's interesting that the destructor runs twice in your example - that one seems more analogous to option::unwrap; seems like that should be allowed. Also interestingly, since let is by-copy currently, this also breaks (and is nonsense, when you think about it): |
I updated the title of this bug to reflect the problem that the move into |
if match is going to be copy by default, I can see the same problem trying to bind the inside of an @ in a match. |
preventing copies is really the job of the kind checker, but yeah we'll have to be sure and get this right. I'm sure we don't now, should open a bug on it. |
|
I suspect this bug exists with move bindings in match arms too. I think this bug should instead be titled "Patterns should never be able to move out of @-boxes". |
@nikomatsakis: is this still a problem? |
reproduced on 2013-03-22 |
non-critical for 0.6, de-milestoning |
Nominating for milestone 2, backward-compatible |
An update: The general approach for preventing moves in patterns has shifted a bit. In particular, we are currently detecting such moves in |
…ern has no moves. This check only works for `match`s, the checks (incorrectly) do not run for patterns in `let`s.
accepted for production-ready milestone |
Triage: reproduced 2013-07-25, editing code to compensate for language drift. |
@graydon I believe this bug was fixed. In particular:
Which test did you run? Presumably the test in the initial comment? There are still actions required:
|
Closing because this bug has long since been fixed. |
llvm.prefetch is not a math function fixes the comment in src/shims/foreign_items.rs
Dependency upgrade resulting from `cargo update`. Co-authored-by: tautschnig <[email protected]>
(edit: a similar problem appears for
let a@b = c
; see comment below.)The text was updated successfully, but these errors were encountered: