rust-lang/wg-cargo-std-aware

Persistent unused attribute warnings when recompiling libcore after linker flags are changed

cr1901 opened this issue · 5 comments

All references to -Clink-arg are in a .cargo/config file. I can't duplicate this behavior using cargo rustc on the command-line.

I have an msp430 project I'm testing with -Zbuild-std=core. The .cargo/config file normally looks like this:

rustflags = [
    "-C", "link-arg=-Tlink.x",
    "-C", "link-arg=-nostartfiles",
    "-C", "link-arg=-mcpu=msp430",
    "-C", "link-arg=-lmul_none",
    "-C", "link-arg=-lgcc",
]

[build]
target = "msp430-none-elf"

Therefore, my command line invocation always looks like cargo build -Zbuild-std=core, relying on cargo to infer the target.

When I build a debug binary with or without -Clink-arg=-lc after a cargo clean, the build works fine. However, if I do a subsequent build where I either add -Clink-arg=-lc if it was missing, or remove -Clink-arg=-lc if it was present, I get a large number of warnings I don't understand, referring to unused attributes:

warning: unused attribute
    --> C:\Users\William\.rustup\toolchains\nightly-x86_64-pc-windows-gnu\lib\rustlib\src\rust\src\libcore\num\mod.rs:4176:13
     |
4176 |               #[allow_internal_unstable(const_fn_union)]
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
4872 | /     uint_impl! { usize, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
4873 | |     "[0x34, 0x12]", "[0x12, 0x34]",
4874 | |     usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
     | |______________________________________________________________________- in this macro invocation
     |
     = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

These warnings remain, no matter whether I include -Clink-arg=-lgcc or not, on subsequent builds until I do the next cargo clean. The warnings even occur when I switch between linking to memcpy and friends using libc to linking against rlibc instead (again, until the next cargo clean). This behavior does not happen during release builds.

Beside being noise in my console, these warnings may very well be harmless. But I would expect the warnings to not persist after every other recompilation of libcore no matter what linker flags I pass to cargo. This makes me think libcore builds using -Zbuild-std=core are not duplicable w/ the same exact flags between cargo invocations, depending on what linker args cargo has seen before.

I cannot duplicate this behavior in xargo. Possibly relevant: xargo always compiles libcore etc in release mode.

ehuss commented

Thanks for the report! It looks like this is a bug in rustc's incremental support. We should be turning incremental off anyways (#44), I'll take a look into that.

ehuss commented

Oh, and the incremental thing looks like a known issue:
rust-lang/rust#65023
rust-lang/rust#58633

Excellent, ty for your work! One question:

  • Lints are capped to "allow" for std crates, and warnings are not shown by default.

Not that I have immediate use for this, but is it possible to override this setting to see std warnings if I desire?

ehuss commented

-vv lowers the lint cap to warning for all crates.