Skip to content

nightly-only regression: borrows of #[thread_local]s can escape from functions #165290

Description

@dianne

reported by @veluca93 in #165119 (comment):

FYI, this change seems to introduce a soundness regression: the following code compiles, but did not before this PR, and segfaults without any unsafe.

#![feature(thread_local)]

#[thread_local]
static TLS: [u8; 64 << 20] = [0; 64 << 20];

fn leak_tls() -> &'static [u8; 64 << 20] {
    &TLS
}

fn main() {
   let dangling = std::thread::spawn(leak_tls).join().unwrap();
   std::hint::black_box(dangling[0]);
}

oops! PR soon.

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added
    A-borrow-checker
    T-compiler
    I-unsound
    C-bug
    F-thread_local
    on Nov 1, 2026
  3. added
    needs-triage
    on Nov 1, 2026
  4. added
    A-thread-locals
    and removed
    needs-triage
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-borrow-checkerA-thread-localsC-bugF-thread_localI-unsoundT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions