@@ -1750,11 +1750,6 @@ impl<const N: usize> StaticVec<u8, N> {
17501750 #[ doc( hidden) ]
17511751 #[ inline]
17521752 pub ( crate ) const fn bytes_to_data ( values : & [ u8 ] ) -> MaybeUninit < [ u8 ; N ] > {
1753- // This works at compile time too, of course.
1754- assert ! (
1755- values. len( ) <= N ,
1756- "Attempted to create a `StaticString` with insufficient capacity from an `&str` literal!"
1757- ) ;
17581753 // What follows is an idea partially arrived at from reading the source of the `const-concat`
17591754 // crate. Note that it amounts to effectively a `const fn` compatible implementation of what
17601755 // `MaybeUninit::assume_uninit()` does, and is *only* used here due to there being no other way
@@ -1779,7 +1774,7 @@ impl<const N: usize> StaticVec<u8, N> {
17791774 // you, `const_loop`!
17801775 let mut i = 0 ;
17811776 while i < values. len ( ) {
1782- // We've statically asserted that `values.len() <= N` at the top of this overall function,
1777+ // We've statically asserted that `values.len() <= N` before entering this overall function,
17831778 // so there's no concern that we might go out of bounds here (although that would still just
17841779 // result in compilation not actually succeeding at all due to the `const` index error).
17851780 res[ i] = MaybeUninit :: new ( values[ i] ) ;
@@ -1796,6 +1791,15 @@ impl<const N: usize> StaticVec<u8, N> {
17961791 #[ doc( hidden) ]
17971792 #[ inline( always) ]
17981793 pub const fn __new_from_const_str ( values : & str ) -> Self {
1794+ // This works at compile time too, of course, thanks to the `const_panic` feature.
1795+ assert ! (
1796+ values. len( ) <= N ,
1797+ // At the moment, I don't think this message is actually printed in any context when the
1798+ // assertion gets triggered (currently it's just "could not evaluate static initializer") but
1799+ // I feel like it doesn't hurt to have here just in case the compiler-error behavior changes
1800+ // such that custom messages are actually shown.
1801+ "Attempted to create a `StaticString` with insufficient capacity from an `&str` literal!"
1802+ ) ;
17991803 Self :: new_from_str_data ( Self :: bytes_to_data ( values. as_bytes ( ) ) , values. len ( ) )
18001804 }
18011805}
0 commit comments