Skip to content

Automatically re-borrow the ExtCtxt in quotes #16992

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

Closed
kmcallister opened this issue Sep 4, 2014 · 0 comments · Fixed by #17040
Closed

Automatically re-borrow the ExtCtxt in quotes #16992

kmcallister opened this issue Sep 4, 2014 · 0 comments · Fixed by #17040

Comments

@kmcallister
Copy link
Contributor

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.

kmcallister added a commit to kmcallister/rust that referenced this issue Sep 8, 2014
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

Successfully merging a pull request may close this issue.

1 participant