Skip to content

cargo-miri builds proc-macro crate's unit tests as an executable and tries to interpret it as JSON #1660

@ghost

Description

I tried this with today's nightly:

cargo new --lib cargo-miri-bug --vcs none
cd cargo-miri-bug
echo -e '[lib]\nproc-macro = true' >> Cargo.toml
cargo miri test

And it reported an error:

    Finished test [unoptimized + debuginfo] target(s) in 0.50s
     Running `/path/to/my/home/directory/.rustup/toolchains/nightly-2020-12-30-x86_64-unknown-linux-gnu/bin/cargo-miri /the/directory/cargo-miri-bug/target/debug/deps/cargo_miri_bug-90df6bde175539f3`
fatal error: file "/the/directory/cargo-miri-bug/target/debug/deps/cargo_miri_bug-90df6bde175539f3" contains outdated or invalid JSON; try `cargo clean`
error: test failed, to rerun pass '--lib'

But cargo_miri_bug-90df6bde175539f3 is not JSON at all:

$ file target/debug/deps/cargo_miri_bug-90df6bde175539f3
target/debug/deps/cargo_miri_bug-90df6bde175539f3: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=a50f714aa423145427213e658d992f246548e39d, for GNU/Linux 3.2.0, with debug_info, not stripped
$ LD_LIBRARY_PATH=~/.rustup/toolchains/nightly-2020-12-30-x86_64-unknown-linux-gnu/lib target/debug/deps/cargo_miri_bug-90df6bde175539f3

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

It's an executable. I can even run it manually.

Actually I think, for unit tests, cargo-miri should build the entire proc-macro crate and use Miri to interpret it like normal crates, not building an executable with machine code. (That is, cargo_miri_bug-90df6bde175539f3 should be a JSON file, but it's currently not.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargoArea: affects the cargo wrapper (cargo miri)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions