Skip to content

Commit 0a844a0

Browse files
bors[bot]japaric
andauthored
Merge #298
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 <[email protected]>
2 parents 6dc013b + d58b8db commit 0a844a0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Fixed
1515

16+
- `IndexSet` and `IndexMap`'s `default` method now compile time checks that their capacity is a power of two.
17+
1618
## [v0.7.13] - 2022-05-16
1719

1820
### Added

src/indexmap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,10 @@ where
952952
S: BuildHasher + Default,
953953
{
954954
fn default() -> Self {
955+
// Const assert
956+
crate::sealed::greater_than_1::<N>();
957+
crate::sealed::power_of_two::<N>();
958+
955959
IndexMap {
956960
build_hasher: <_>::default(),
957961
core: CoreMap::new(),

0 commit comments

Comments
 (0)