Skip to content

Moving in macros can produce value moved here in previous iteration of loop without any loops #46099

Closed
@Zoxc

Description

@Zoxc

Test case:

macro_rules! test {
    ($v:expr) => {{
        drop(&$v);
        $v
    }}
}

fn main() {
    let b = Box::new(true);
    test!({b});
}

Produces:

error[E0382]: use of moved value: `b`
  --> src/main.rs:10:12
   |
10 |     test!({b});
   |            ^ value moved here in previous iteration of loop
   |
   = note: move occurs because `b` has type `std::boxed::Box<bool>`, which does not implement the `Copy` trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions