Closed
Description
This program should be legal
struct Foo {
v: ~[uint]
}
fn make_foo() -> Foo {
Foo { v: ~[1, 2, 3] }
}
fn main() {
let v = make_foo().v;
for v.each |i| { io::println(fmt!("%u", *i)); }
}
But it yields:
/Users/nmatsakis/tmp/bar.rs:10:12: 10:24 error: moving out of immutable field
/Users/nmatsakis/tmp/bar.rs:10 let v = make_foo().v;
^~~~~~~~~~~~
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
nikomatsakis commentedon Jan 8, 2013
Presumably the problem here is how borrow checker treats moves out of fields contained in rvalues. But that code needs to be somewhat re-worked in general.
nikomatsakis commentedon Jan 8, 2013
Oh, actually, this is not specific to rvalues really. It's just a generally unnecessary limitation of borrowck.
bblum commentedon Jan 11, 2013
I'm confused why this isn't specific to rvalues. Isn't
let f = make_foo(); let v = foo.v;
illegal?This seems to me like a legal special case because it could be syntax sugar for
let Foo { v: v } = make_foo()
.nikomatsakis commentedon Feb 15, 2013
I am editing the title of this issue and expanding it. We should allow moves out of arbitrary owned content. Most of the system is setup for this already, I think the only problem is that borrow check flags such moves as illegal. (But there might be trans work needed to) Examples of things that ought to work but do not:
In some cases these can be expressed today using match statements. I see no reason for match statements to be more expressive than other kinds of expressions; moreover, they do not allow
e[f]
.Currently, the moves code and liveness analysis will allow such moves. They would cause the local variables
b
ande
above to be considered "partially moved" and thus unusable. But then the borrow checker would flag an error for moving out of something that's not a local variable.nikomatsakis commentedon Feb 15, 2013
@bblum your example is illegal today but I don't see any good reason for that restriction.
graydon commentedon Apr 30, 2013
assigning bug; change assignment if you disagree
nikomatsakis commentedon May 6, 2013
Some FIXMEs related to bits of code that will have to be adjusted.
7 remaining items