Skip to content

Commit

Permalink
Merge #1376
Browse files Browse the repository at this point in the history
1376: fix debug scopes r=matklad a=matklad



Co-authored-by: Aleksey Kladov <[email protected]>
  • Loading branch information
bors[bot] and matklad committed Jun 4, 2019
2 parents fcf30d8 + d2b2359 commit 8bd0e84
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/ra_prof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
/// Allows to check if the current code is withing some dynamic scope, can be
/// useful during debugging to figure out why a function is called.
pub struct Scope {
_hidden: (),
prev: bool,
}

impl Scope {
pub fn enter() -> Scope {
IN_SCOPE.with(|slot| *slot.borrow_mut() = true);
Scope { _hidden: () }
let prev = IN_SCOPE.with(|slot| std::mem::replace(&mut *slot.borrow_mut(), true));
Scope { prev }
}
pub fn is_active() -> bool {
IN_SCOPE.with(|slot| *slot.borrow())
Expand All @@ -251,7 +251,7 @@ impl Scope {

impl Drop for Scope {
fn drop(&mut self) {
IN_SCOPE.with(|slot| *slot.borrow_mut() = false);
IN_SCOPE.with(|slot| *slot.borrow_mut() = self.prev);
}
}

Expand Down

0 comments on commit 8bd0e84

Please sign in to comment.