Regression in #[used] attribute on Windows msvc · Issue #127052 · rust-lang/rust (original) (raw)

Code

I tried this code:

#[used] static FOO: u32 = 0; fn main() {}

I expected to see this happen: Compiles successfully.

Instead, this happened: Fails with this error:

  = note: symbols.o : error LNK2001: unresolved external symbol _ZN3foo3FOO17h3b276d94f7182e74E
          D:\Temp\foo\target\debug\deps\foo.exe : fatal error LNK1120: 1 unresolved externals

Version it worked on

nightly-2024-06-26 and earlier.

Version with regression

nightly-2024-06-27 and later, starting with #126938.
See #126938 (comment) for a discussion of the issue.

rustc --version --verbose:

rustc 1.81.0-nightly (4bc39f028 2024-06-26)
binary: rustc
commit-hash: 4bc39f028d14c24b04dd17dc425432c6ec354536
commit-date: 2024-06-26
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

cc @RalfJung @ChrisDenton