Skip to content

Commit f6e86b9

Browse files
authored
Actually run RecursionGuard in release mode (#827)
debug_assert! is disabled in release mode, so side effects that we want to preserve should happen outside of it.
1 parent 0fa07a8 commit f6e86b9

File tree

1 file changed

+6
-2
lines changed
  • crates/apollo-compiler/src/validation

1 file changed

+6
-2
lines changed

crates/apollo-compiler/src/validation/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,13 @@ impl RecursionStack {
573573
/// if the name was used somewhere up the call stack. When a guard is dropped, its name is removed
574574
/// from the list.
575575
struct RecursionGuard<'a>(&'a mut RecursionStack);
576+
576577
impl RecursionGuard<'_> {
577578
/// Mark that we saw a name. If there are too many names, return an error.
578579
fn push(&mut self, name: &Name) -> Result<RecursionGuard<'_>, RecursionLimitError> {
580+
let new = self.0.seen.insert(name.clone());
579581
debug_assert!(
580-
self.0.seen.insert(name.clone()),
582+
new,
581583
"cannot push the same name twice to RecursionGuard, check contains() first"
582584
);
583585
self.0.high = self.0.high.max(self.0.seen.len());
@@ -587,10 +589,12 @@ impl RecursionGuard<'_> {
587589
Ok(RecursionGuard(self.0))
588590
}
589591
}
592+
590593
/// Check if we saw a name somewhere up the call stack.
591594
fn contains(&self, name: &Name) -> bool {
592-
self.0.seen.iter().any(|seen| seen == name)
595+
self.0.seen.contains(name)
593596
}
597+
594598
/// Return the name where we started.
595599
fn first(&self) -> Option<&Name> {
596600
self.0.seen.first()

0 commit comments

Comments
 (0)