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

Can duplicate unique pointers using auto-move-by-type #4114

Closed
rntz opened this issue Dec 5, 2012 · 1 comment
Closed

Can duplicate unique pointers using auto-move-by-type #4114

rntz opened this issue Dec 5, 2012 · 1 comment

Comments

@rntz
Copy link
Contributor

rntz commented Dec 5, 2012

Currently, the incoming branch rustc accepts the following program:

fn dup(x: ~int) -> (~int,~int) { *~(x,x) }
fn main() { dup(~2); }

Since dup duplicates a unique pointer, it shouldn't accept it. Indeed, it correctly rejects the following program, complaining that it uses a moved variable:

fn dup(x: ~int) -> (~int,~int) { *~(move x,move x) }
fn main() { dup(~2); }

This makes me think that the problem is somewhere in the code @pcwalton added in #4109, @33c1e47.

Note that the following is also accepted incorrectly:

fn dup(x: ~int) -> ~(~int,~int) { ~(x,x) }

However, the following is correctly rejected:

fn dup(x: ~int) -> (~int,~int) { (x,x) }
@pcwalton
Copy link
Contributor

pcwalton commented Dec 6, 2012

First problem was due to not updating the borrow check for moves-based-on-type; that was fixed earlier today. The second problem was due to not handing @ and ~ constructors correctly in mode computation; that was fixed just now.

RalfJung added a commit to RalfJung/rust that referenced this issue Jan 19, 2025
FD handling: avoid unnecessary dynamic downcasts
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

No branches or pull requests

2 participants