Skip to content

Commit

Permalink
proc_macro: check non-interned handles for "leaks" between/after invo…
Browse files Browse the repository at this point in the history
…cations.
  • Loading branch information
eddyb committed Aug 22, 2019
1 parent 201e52e commit 1754dcd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/libproc_macro/bridge/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ impl<T> OwnedStore<T> {
}
}

impl<T> Drop for OwnedStore<T> {
fn drop(&mut self) {
assert!(self.data.is_empty(), "{} `proc_macro` handles were leaked", self.data.len());
}
}

impl<T> OwnedStore<T> {
pub(super) fn alloc(&mut self, x: T) -> Handle {
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
Expand Down Expand Up @@ -63,6 +69,13 @@ pub(super) struct InternedStore<T: 'static> {
interner: HashMap<T, Handle>,
}

impl<T> Drop for InternedStore<T> {
fn drop(&mut self) {
// HACK(eddyb) turn off the leak-checking for interned handles.
self.owned.data.clear();
}
}

impl<T: Copy + Eq + Hash> InternedStore<T> {
pub(super) fn new(counter: &'static AtomicUsize) -> Self {
InternedStore {
Expand Down

0 comments on commit 1754dcd

Please sign in to comment.