Closed
Description
Using rust 0.6 from homebrew. Trying to do two subsequent method calls with a mutable borrowed self -- by contrast, any number of calls to "peek" seem to work okay:
struct Numberizer <'self> {
numbers: &'self[int],
current: uint
}
impl <'self> Numberizer <'self> {
fn peek(&self) -> int {
self.numbers[self.current]
}
fn pop(&mut self) -> int {
let rv = self.peek();
self.current += 1;
rv
}
}
fn main() {
let numbers: ~[int] = ~[1, 42, 3, 4, 5];
let mut o = Numberizer {numbers: numbers, current: 0};
io::println(fmt!("%d", o.pop())); // note: prior loan as mutable granted here
io::println(fmt!("%d", o.pop())); // error: loan of mutable local variable as mutable conflicts with prior loan
}
(I may be doing it wrong but I figured making a github issue would at least make the fix searchable. :-)
$ rustc --version
rustc 0.6
host: x86_64-apple-darwin
Metadata
Metadata
Assignees
Labels
No labels