Closed
Description
Code like
fn foobar(cx: &mut ExtCtxt) {
quote_expr!(cx, 1i);
quote_expr!(cx, 2i);
}
fails to compile because the first quote takes ownership of the &mut ExtCtxt
:
macro_crate_test.rs:41:5: 41:25 error: use of moved value: `cx`
macro_crate_test.rs:40:5: 40:25 note: `cx` moved here because it has type `&mut syntax::ext::base::ExtCtxt<'_>`, which is moved by default (use `ref` to override)
The solution is always (?) to re-borrow the ExtCtxt
like so:
fn foobar(cx: &mut ExtCtxt) {
quote_expr!(&mut *cx, 1i);
quote_expr!(&mut *cx, 2i);
}
The quote macros should do this automatically, for consistency with ordinary Rust functions and to reduce boilerplate.
Metadata
Metadata
Assignees
Labels
No labels