Skip to content

Do not promote extern statics - #2302

Open
sjwang05 wants to merge 1 commit into
rust-lang:masterfrom
sjwang05:document-extern-static-promotion
Open

Do not promote extern statics#2302
sjwang05 wants to merge 1 commit into
rust-lang:masterfrom
sjwang05:document-extern-static-promotion

Conversation

@sjwang05

Copy link
Copy Markdown

Reference update for rust-lang/rust#157641: a borrow of an extern static cannot be promoted, even when the reference is never read from.

Reference update for rust-lang/rust#157641: a borrow of an extern
static is never eligible for constant promotion, even when the
reference itself is never read from.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jun 30, 2026
@ehuss ehuss added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Jul 14, 2026
@traviscross traviscross removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jul 28, 2026
Comment thread src/destructors.md
Comment on lines +381 to +391
r[destructors.scope.const-promotion.extern-static]
A borrow of an [`extern` static] cannot be promoted, even if the resulting reference is never read from.

```rust,compile_fail
unsafe extern "C" {
static X: i32;
}
static mut FOO: *const &i32 = [unsafe { &X }].as_ptr();
```

@traviscross traviscross Jul 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error produced has an error code, we'll want to add that to the infostring line.

Probably we also want to add some comments to this example to help make clear what's going on. And maybe it's worth adding an admonition that mentions the theory behind why this is rejected (see, e.g., what I wrote in rust-lang/rust#157641 (comment)).

View changes since the review

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

Labels

S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants