Skip to content

Commit

Permalink
Auto merge of #89237 - BoxyUwU:trackersMcCaller, r=eddyb
Browse files Browse the repository at this point in the history
make `#[track_caller]` actually do stuff in `Steal::borrow`

makes this ICE message useful:
``thread 'rustc' panicked at 'attempted to read from stolen value', /rustc/ac2d9fc509e36d1b32513744adf58c34bcc4f43c\compiler\rustc_data_structures\src\steal.rs:37:21``
  • Loading branch information
bors committed Sep 25, 2021
2 parents 60fe8b3 + f1e71a5 commit 218a96c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_data_structures/src/steal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ impl<T> Steal<T> {

#[track_caller]
pub fn borrow(&self) -> MappedReadGuard<'_, T> {
ReadGuard::map(self.value.borrow(), |opt| match *opt {
None => panic!("attempted to read from stolen value"),
Some(ref v) => v,
})
let borrow = self.value.borrow();
if let None = &*borrow {
panic!("attempted to read from stolen value: {}", std::any::type_name::<T>());
}
ReadGuard::map(borrow, |opt| opt.as_ref().unwrap())
}

#[track_caller]
Expand Down

0 comments on commit 218a96c

Please sign in to comment.