fix(semantic): fix const assertions in UnresolvedReferencesStack (#8653)

The `_SIZE_CHECK` assertion was ignored, because `const`s are only evaluated if they're referenced in a function which is called. Fix that by referencing the const in `UnresolvedReferencesStack::new`.

Also add more assertions to cover all the invariants.
This commit is contained in:
overlookmotel 2025-01-22 13:13:15 +00:00
parent de76eb1b90
commit d1c5dc4d12

View file

@ -34,11 +34,17 @@ impl<'a> UnresolvedReferencesStack<'a> {
/// SAFETY: Must be >= 2 to ensure soundness of `current_and_parent_mut`.
const INITIAL_SIZE: usize = 16;
/// Assert invariant
#[allow(clippy::assertions_on_constants)]
const _SIZE_CHECK: () = assert!(Self::INITIAL_SIZE > Self::INITIAL_DEPTH);
/// Assert invariants
const ASSERT_INVARIANTS: () = {
assert!(Self::INITIAL_DEPTH >= 1);
assert!(Self::INITIAL_SIZE >= 2);
assert!(Self::INITIAL_SIZE > Self::INITIAL_DEPTH);
};
pub(crate) fn new() -> Self {
// Invoke `ASSERT_INVARIANTS` assertions. Without this line, the assertions are ignored.
const { Self::ASSERT_INVARIANTS };
let mut stack = vec![];
stack.resize_with(Self::INITIAL_SIZE, TempUnresolvedReferences::default);
Self { stack, current_scope_depth: Self::INITIAL_DEPTH }