`debug_refcell` points into std source for `LocalKey::with_borrow`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::cell::RefCell;
thread_local! {
static FOO: RefCell<()> = RefCell::new(());
}
fn main() {
FOO.with_borrow(|_x| FOO.with_borrow_mut(|_y| {}))
}
Run with cargo +nightly run -Zbuild-std -Zbuild-std-features="debug_refcell"
I expect to get an error telling me where the first and second borrow occur in my code.
What actually happens is that I get two locations in the standard library:
thread 'main' (141310) panicked at /home/lucasholten/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:752:38:
RefCell already borrowed; a previous borrow was at /home/lucasholten/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:719:34
It seems to me that LocalKey::with_borrow and LocalKey::with_borrow_mut should have #[track_caller] applied, at least when the debug_refcell feature is used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with cargo +nightly run -Zbuild-std -Zbuild-std-features="debug_refcell", then inspect library/std/src/thread/local.rs around lines 719 and 752. The issue is done when borrow diagnostics for LocalKey::with_borrow and with_borrow_mut point to the user call sites rather than only standard-library locations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100