Skip to content

On Windows a static address changes when copied into another static across a module boundary #127518

Closed as duplicate of#128775
@Alexendoo

Description

@Alexendoo

Technically not the address of the static itself, but it is a confusing interaction

I tried this code:

mod m {
    pub static IN_MOD: &str = &"s";
    pub static IN_MOD_2: &str = IN_MOD;
}

static OUTSIDE: &str = m::IN_MOD;

fn main() {
    println!("{:p}", m::IN_MOD);
    println!("{:p}", m::IN_MOD_2);
    println!("{:p}", OUTSIDE);
}

I expected to see this happen:

The same address printed 3 times as it is on Linux

Instead, this happened:

0x7ff6dba2a370
0x7ff6dba2a370
0x7ff6dba2a3c8

In --release mode the three addresses are the same

Meta

Stable behaves the same

rustc --version --verbose:

rustc 1.81.0-nightly (35b658fb1 2024-07-08)
binary: rustc
commit-hash: 35b658fb1071d752d092751d9f17a9fa7b154ec4
commit-date: 2024-07-08
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions