rust-lang / rust-lang/rfcs

"scoped_thread_local!(...)" can be improved

Open
#1,112 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Currently it's impossible to store structs with lifetime bounds in a scoped thread local, largely because rust doesn't support HKT. However, with macros and associated types, the type system is just powerful enough to express the required semantics.

Using the example implementation below, one can write code like the following:

scoped_thread_local!(static EXAMPLE: for<'scope> &'scope MutexGuard<'scope, u32>);

The presence of 'scope allows a much wider range of types to be stored safely in a scoped thread local. Without this change the only way to get the same behaviour is via the use of unsafe code.

Example implementation:
https://github.com/Diggsey/rust/tree/scoped_thread_local_hkt

(While it requires no changes to the compiler, changes to the compiler could make it significantly less hacky...)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the scoped_thread_local!(...) macro entry point and review the linked scoped_thread_local_hkt example implementation. Check how its associated types and 'scope lifetime express storage of lifetime-bound structs, then assess whether the approach can be adopted without compiler changes. Done means scoped thread locals safely support the illustrated MutexGuard type.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.