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

Matching a partially moved value results in weird runtime behavior. #17385

Closed
dpc opened this issue Sep 19, 2014 · 4 comments · Fixed by #17413
Closed

Matching a partially moved value results in weird runtime behavior. #17385

dpc opened this issue Sep 19, 2014 · 4 comments · Fixed by #17413

Comments

@dpc
Copy link
Contributor

dpc commented Sep 19, 2014

Sorry for not providing smaller case but I hope this is better than nothing:

https://github.com/dpc/rustyhex/blob/broken/src/ui/piston.rs#L744

self.input_controller.push_input(i);
// vs self.input_controller.push_input(i.clone());

Both versions works (compile and start), but runtime behavior changes. The code that follows the above part:

match i {
    Press(Keyboard(_)) => {
           self.game_update(game)
     },

will match Press(Keyboard(_)) no matter what i really is, if the value is partially moved (so mouse events are updating my game). If I use the version with i.clone(), the code works as intended and game is updated only on keyboard presses.

@dpc
Copy link
Contributor Author

dpc commented Sep 19, 2014

$ rustc --version
rustc 0.12.0-pre (b88d1030e 2014-09-17 18:26:14 +0000)

@ghost
Copy link

ghost commented Sep 20, 2014

Minimal:

struct X(int);

impl Drop for X {
    fn drop(&mut self) { }
}

fn main() {
    let foo = X(1i);
    drop(foo);
    match foo {
        X(1i) => (),
        _ => unreachable!()
    }
}

This shouldn't compile at all.

@alexcrichton
Copy link
Member

Nominating.

@ghost
Copy link

ghost commented Sep 20, 2014

Looks like a regression. 0.10 rejects this code.

bors added a commit that referenced this issue Sep 23, 2014
This is to make sure it hadn't been moved if there are no bindings
in any of the arms.

Fixes #17385.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants