Skip to content

Regression in #[used] attribute on Windows msvc #127052

Closed

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.O-windowsOperating system: WindowsOperating system: WindowsO-windows-msvcToolchain: MSVC, Operating system: WindowsToolchain: MSVC, Operating system: Windowsregression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions