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

Lint suppressions via RUSTFLAGS don't apply to proc-macro crates #4012

Closed
Veetaha opened this issue Nov 4, 2024 · 1 comment
Closed

Lint suppressions via RUSTFLAGS don't apply to proc-macro crates #4012

Veetaha opened this issue Nov 4, 2024 · 1 comment

Comments

@Veetaha
Copy link

Veetaha commented Nov 4, 2024

I tried this code:

A proc-macro crate:

[package]
edition = "2021"
name = "my-lovely-macro"
version = "0.1.0"

[lib]
proc-macro = true
#[proc_macro]
pub fn my_lovely_macro(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let unused = 1;

    stream
}

And a runtime crate:

[package]
edition = "2021"
name    = "sandbox"
version = "0.1.0"

[dependencies]
my-lovely-macro = { path = "../my-lovely-macro" }
fn main() {}

I invoked the following command:

RUSTFLAGS="--allow unused_variables" cargo +nightly miri run

The following output was generated:

   Compiling my-lovely-macro v0.1.0 (/home/veetaha/sandbox/rust/crates/my-lovely-macro)
warning: unused variable: `unused`
 --> crates/my-lovely-macro/src/lib.rs:3:9
  |
3 |     let unused = 1;
  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `my-lovely-macro` (lib) generated 1 warning
   Compiling sandbox v0.1.0 (/home/veetaha/sandbox/rust/crates/sandbox)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.25s
     Running `/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/sandbox`

With --verbose:

 cargo +nightly miri run --verbose
   Compiling my-lovely-macro v0.1.0 (/home/veetaha/sandbox/rust/crates/my-lovely-macro)
     Running `/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri /home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/miri --crate-name my_lovely_macro --edition=2021 crates/my-lovely-macro/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=133 --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=aae35d6b91939280 -C extra-filename=-aae35d6b91939280 --out-dir /home/veetaha/sandbox/rust/target/miri/debug/deps -C linker=clang -C incremental=/home/veetaha/sandbox/rust/target/miri/debug/incremental -L dependency=/home/veetaha/sandbox/rust/target/miri/debug/deps --extern proc_macro`
warning: unused variable: `unused`
 --> crates/my-lovely-macro/src/lib.rs:3:9
  |
3 |     let unused = 1;
  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `my-lovely-macro` (lib) generated 1 warning
   Compiling sandbox v0.1.0 (/home/veetaha/sandbox/rust/crates/sandbox)
     Running `/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri /home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/miri --crate-name sandbox --edition=2021 crates/sandbox/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=133 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=a65f98a81a567a5d -C extra-filename=-a65f98a81a567a5d --out-dir /home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -C linker=clang -C incremental=/home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/incremental -L dependency=/home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/veetaha/sandbox/rust/target/miri/debug/deps --extern my_lovely_macro=/home/veetaha/sandbox/rust/target/miri/debug/deps/libmy_lovely_macro-aae35d6b91939280.so --allow unused_variables`
     Running `/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri /home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/miri --crate-name sandbox --edition=2021 crates/sandbox/src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=133 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=5bd7ab0fcb5408a4 -C extra-filename=-5bd7ab0fcb5408a4 --out-dir /home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -C linker=clang -C incremental=/home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/incremental -L dependency=/home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/veetaha/sandbox/rust/target/miri/debug/deps --extern my_lovely_macro=/home/veetaha/sandbox/rust/target/miri/debug/deps/libmy_lovely_macro-aae35d6b91939280.so --extern sandbox=/home/veetaha/sandbox/rust/target/miri/x86_64-unknown-linux-gnu/debug/deps/libsandbox-a65f98a81a567a5d.rlib --allow unused_variables`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.23s
     Running `/home/veetaha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/sandbox`

Notice that the compilation of the proc macro didn't receive the --allow unused_variables parameter.

Version

$ cargo +nightly miri --version
miri 0.1.0 (b8c8287a22 2024-11-03)
@Veetaha Veetaha changed the title Lint suppressions via RUSTFLAGS doesn't apply to proc-macro cratees Lint suppressions via RUSTFLAGS don't apply to proc-macro crates Nov 4, 2024
@RalfJung
Copy link
Member

RalfJung commented Nov 5, 2024

Thanks for the report!

That's a cargo issue, not a Miri issue. Miri always invokes cargo with --target <tuple>, meaning cargo separately builds host crates and target crates. RUSTFLAGS only applies to target crates. So closing as a duplicate of rust-lang/cargo#4423.

@RalfJung RalfJung closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants