Closed
Description
A macro that uses an expr
non-terminal that's used in both arms of an if
statement, where the expression given to the macro expression involves borrowing *self
as mutable, triggers an incorrect borrowck warning where it claims *self
is being borrowed as mutable twice.
Code:
struct Foo {
i: int
}
macro_rules! foo(
($code:expr) => (
if true {
$code
} else {
$code
}
)
)
impl Foo {
pub fn foo(&mut self) {
foo!({ self.bar() })
}
pub fn bar(&mut self) {
self.i += 1;
}
}
fn main() {
let mut foo = Foo{i: 0};
foo.foo();
}
Errors:
Untitled.rs:17:15: 17:20 error: cannot borrow `*self` as mutable more than once at a time
Untitled.rs:17 foo!({ self.bar() })
^~~~~
Untitled.rs:5:0: 13:1 note: in expansion of foo!
Untitled.rs:17:8: 18:5 note: expansion site
Untitled.rs:17:15: 17:20 note: second borrow of `*self` as mutable occurs here
Untitled.rs:17 foo!({ self.bar() })
^~~~~
Untitled.rs:5:0: 13:1 note: in expansion of foo!
Untitled.rs:17:8: 18:5 note: expansion site
Untitled.rs:17:15: 17:20 error: cannot borrow `*self` as mutable more than once at a time
Untitled.rs:17 foo!({ self.bar() })
^~~~~
Untitled.rs:5:0: 13:1 note: in expansion of foo!
Untitled.rs:17:8: 18:5 note: expansion site
Untitled.rs:17:15: 17:20 note: second borrow of `*self` as mutable occurs here
Untitled.rs:17 foo!({ self.bar() })
^~~~~
Untitled.rs:5:0: 13:1 note: in expansion of foo!
Untitled.rs:17:8: 18:5 note: expansion site
error: aborting due to 2 previous errors