rust-lang / rust-lang/rust

Use more useful panic message for with_session_globals when TLS variable not set

Open
#149,768 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Currently this panics with "cannot access a scoped thread local variable without calling set first", which doesn't explain why that is the case. In my experience this is generally caused by either someone forgetting to add extern crate rustc_driver; to their codegen backend (or back when we still supported them, their rustc plugin) or compiling against a different rustc_driver than the rustc it gets loaded into. It would be nice to indicate this in the panic message. Ideally we would also prevent loading the codegen backend entirely when either scenario is detected.

Contributor guide

Open the contributing guide

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 by locating the with_session_globals entry point and tracing where its thread-local state is initialized. Then inspect the codegen backend loading path to determine whether the panic message can identify a missing rustc_driver dependency or version mismatch, and whether loading should be prevented in those cases. Done means the failure explains the likely cause and the loading behavior is addressed if that scope is confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.