Skip to content

Automatically re-borrow the ExtCtxt in quotes #16992

Closed
@kmcallister

Description

@kmcallister

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions