The capacity method declared at src/ctors.rs:38-40 is pub fn capacity(&mut self) -> usize and its body simply returns the const-generic N. It reads no field and mutates nothing, but its signature forces every external caller to hold a mutable borrow on the stack just to read the compile-time capacity, which blocks any concurrent shared borrow and breaks several otherwise-natural call sites.
The signature also contradicts the rest of the API: len, is_empty, and other state-readers on Stack in src/stack.rs are correctly declared &self (and several are even const fn). Stack::try_push and Stack::try_pop in src/stack.rs:80-84 and src/stack.rs:117-121 already paper over the bug internally by only calling self.capacity() from inside methods that already hold &mut self. There is no scenario in which the receiver needs to be mutable for this method. Clippy's wrong_self_convention family is set up to flag exactly this pattern.
The fix is to change the signature to pub const fn capacity() -> usize { N } (associated function returning N directly) and update the two callers in src/stack.rs accordingly, or, if a method-style call is preferred for source compatibility, to pub const fn capacity(&self) -> usize { N }. Either form is a one-line change in src/ctors.rs plus two trivial call-site updates in src/stack.rs.
The
capacitymethod declared atsrc/ctors.rs:38-40ispub fn capacity(&mut self) -> usizeand its body simply returns the const-genericN. It reads no field and mutates nothing, but its signature forces every external caller to hold a mutable borrow on the stack just to read the compile-time capacity, which blocks any concurrent shared borrow and breaks several otherwise-natural call sites.The signature also contradicts the rest of the API:
len,is_empty, and other state-readers onStackinsrc/stack.rsare correctly declared&self(and several are evenconst fn).Stack::try_pushandStack::try_popinsrc/stack.rs:80-84andsrc/stack.rs:117-121already paper over the bug internally by only callingself.capacity()from inside methods that already hold&mut self. There is no scenario in which the receiver needs to be mutable for this method. Clippy'swrong_self_conventionfamily is set up to flag exactly this pattern.The fix is to change the signature to
pub const fn capacity() -> usize { N }(associated function returningNdirectly) and update the two callers insrc/stack.rsaccordingly, or, if a method-style call is preferred for source compatibility, topub const fn capacity(&self) -> usize { N }. Either form is a one-line change insrc/ctors.rsplus two trivial call-site updates insrc/stack.rs.