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

inscrutable eval_order_dependence warning (futures related?) #6925

Closed
Fishrock123 opened this issue Mar 17, 2021 · 1 comment · Fixed by #7174
Closed

inscrutable eval_order_dependence warning (futures related?) #6925

Fishrock123 opened this issue Mar 17, 2021 · 1 comment · Fixed by #7174
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Fishrock123
Copy link
Contributor

Fishrock123 commented Mar 17, 2021

Lint name: eval_order_dependence

I tried this code:

#[macro_export]
macro_rules! fixture_body {
    ($($e:expr),* $(,)?) => {
        tide::Body::from_file(
            concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*)
        )
        .await
        .expect(
            concat!("Fixture \"", env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*, "\" not found from file \"", file!(), "\"")
        )
    }
}

// ...
let things = vec![
    fixture_body!("file_1.json"),
    fixture_body!("file_2.json"),
    fixture_body!("file_3.json"),
];
// And many other invocations which also cause the warning, mostly not in this array form

I expected to see this happen:

The clippy lint explanation says:

Checks for a read and a write to the same variable where whether the read occurs before or after the write depends on the evaluation order of sub-expressions.

In the fixture_body! macro, there is no variable declaration, which makes this rule very confusing.

The output is wrong regardless, I am not reading and writing to the same variable at all.

Instead, this happened:

warning: unsequenced read of a variable
  --> tests/integration/test_utils.rs:30:9
   |
28 |  / macro_rules! fixture_body {
29 |  |     ($($e:expr),* $(,)?) => {
30 |  |         tide::Body::from_file(
   |  |_________^
31 | ||             concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*)
32 | ||         )
33 | ||         .await
   | ||______________^
...   |
37 |  |     }
38 |  | }
   |  |_- in this expansion of `fixture_body!` (#1)
   | 
  ::: tests/integration/things.rs:16:13
   |
16 |                fixture_body!("file_1.json"),
   |                --------------------------------------- in this macro invocation (#1)
   |
   = note: `#[warn(clippy::eval_order_dependence)]` on by default
note: whether read occurs before this write depends on evaluation order
  --> tests/integration/test_utils.rs:30:9
   |
28 |  / macro_rules! fixture_body {
29 |  |     ($($e:expr),* $(,)?) => {
30 |  |         tide::Body::from_file(
   |  |_________^
31 | ||             concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*)
32 | ||         )
33 | ||         .await
   | ||______________^
...   |
37 |  |     }
38 |  | }
   |  |_- in this expansion of `fixture_body!` (#1)
   | 
  ::: tests/integration/things.rs:15:13
   |
15 |                fixture_body!("file_1.json"),
   |                ---------------------------------------- in this macro invocation (#1)
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence

Meta

  • cargo clippy -V: clippy 0.0.212 (cb75ad5 2021-02-10)
  • rustc -Vv:
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0

Note: the above error message was taken with -Z macro-backtrace on nightly:

rustc 1.52.0-nightly (f5d8117c3 2021-03-16)
binary: rustc
commit-hash: f5d8117c338a788bd24abec733fd143dfceb25a0
commit-date: 2021-03-16
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

My best guess here is it has something odd to do with the .await and futures. It seems just plain wrong.

Curiously, this similar macro does not seem to cause this issue:

#[macro_export]
macro_rules! fixture {
    ($($e:expr),* $(,)?) => {
        async_std::fs::read_to_string(
            concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*)
        )
        .await
        .expect(
            concat!("Fixture \"", env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", $($e),*, "\" not found from file \"", file!(), "\"")
        )
    }
}
@Fishrock123 Fishrock123 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 17, 2021
@bors bors closed this as completed in 93fe356 May 5, 2021
@Fishrock123
Copy link
Contributor Author

Ooh this is being fixed? Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant