Thanks. To be clear, the error does not go away if the reference to the internal SizeClass returned is immutable, that is, this snippet produces the same error. Even if the first method that is declared &mut self returns an immutable reference to a location inside the object, further attempts at borrowing the object mutably will fail.
I understand the argument that an internal reference could be modified in a way that invalidates it in theory (for other examples such Vec! I’ve seen in this forum), but my question was about my example, not in theory. How can an embedded, fixed-sized array consisting of structs with one primitive type field be modified in a way that would invalidate it when performing further mutable borrows of the containing struct?
Regarding @Michael-F-Bryan’s proposed work-around, I’m struggling to understand how this would work for my case because in a memory allocator, implementing alloc() involves accesses to multiple SizeClasses. For instance, if you allocate n bytes, you may need to get access to the size classes for n/2 bytes and possibly n/4, etc. bytes. My example was simplified (in the actual implementation, the size class contains a linked list of blocks to which blocks need to be added or removed from as part of implementing alloc()).
In short, it’s not possible to implement ‘alloc’ in a method of SizeClass - it needs to be implemented in Allocator (which is also the logical place for it to be.)