Skip to content
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

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

Closed
Zoxc opened this issue Nov 19, 2017 · 1 comment · Fixed by #73600
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@Zoxc
Copy link
Contributor

Zoxc commented Nov 19, 2017

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
@Zoxc Zoxc added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Nov 19, 2017
@TimNN TimNN added the C-bug Category: This is a bug. label Nov 21, 2017
@estebank estebank added E-needs-mentor WG-diagnostics Working group: Diagnostics labels Dec 7, 2017
@estebank estebank changed the title Moving in macros can produce value moved here in previous iteration of loop with any loops Moving in macros can produce value moved here in previous iteration of loop without any loops Dec 13, 2017
@Ekleog
Copy link

Ekleog commented Mar 16, 2019

@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 23, 2020
…atic-morse

Fix spurious 'value moved here in previous iteration of loop' messages

Fixes rust-lang#46099

Previously, we would check the 'move' and 'use' spans to see if we
should emit this message. However, this can give false positives when
macros are involved, since two distinct expressions may end up with the
same span.

Instead, we check the actual MIR `Location`, which eliminates false
positives.
@bors bors closed this as completed in 953104e Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants