298: compile-time check power of two invariant in Index{Set,Map}'s default method r=korken89 a=japaric

closes #295

I tested this manually with both `FnvIndexSet` and `FnvIndexMap`. I tried to add a compile fail test but discovered (the hard way) that all the const assert trickery in `sealed` is checked when the code is built with `cargo build` but *not* when the code is built with `cargo check`. As `trybuild` uses `cargo check` under the hood it's not possible to compile fail test any of those const asserts.

r? `@korken89` 

Co-authored-by: Jorge Aparicio <jorge.aparicio@ferrous-systems.com>
This commit is contained in:
bors[bot] 2022-06-15 11:28:46 +00:00 committed by GitHub
commit 0a844a0204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- `IndexSet` and `IndexMap`'s `default` method now compile time checks that their capacity is a power of two.
## [v0.7.13] - 2022-05-16
### Added

View File

@ -952,6 +952,10 @@ where
S: BuildHasher + Default,
{
fn default() -> Self {
// Const assert
crate::sealed::greater_than_1::<N>();
crate::sealed::power_of_two::<N>();
IndexMap {
build_hasher: <_>::default(),
core: CoreMap::new(),