1111//! `wgpu-core`'s `"strict_asserts"` feature enables that validation
1212//! in both debug and release builds.
1313
14- /// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated.
14+ /// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`] .
1515#[ cfg( feature = "strict_asserts" ) ]
1616#[ macro_export]
1717macro_rules! strict_assert {
@@ -20,7 +20,7 @@ macro_rules! strict_assert {
2020 }
2121}
2222
23- /// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
23+ /// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`] .
2424#[ cfg( feature = "strict_asserts" ) ]
2525#[ macro_export]
2626macro_rules! strict_assert_eq {
@@ -29,7 +29,7 @@ macro_rules! strict_assert_eq {
2929 }
3030}
3131
32- /// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
32+ /// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`] .
3333#[ cfg( feature = "strict_asserts" ) ]
3434#[ macro_export]
3535macro_rules! strict_assert_ne {
@@ -38,7 +38,7 @@ macro_rules! strict_assert_ne {
3838 }
3939}
4040
41- /// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated.
41+ /// This is equivalent to [`std::assert`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert`]
4242#[ cfg( not( feature = "strict_asserts" ) ) ]
4343#[ macro_export]
4444macro_rules! strict_assert {
@@ -47,7 +47,7 @@ macro_rules! strict_assert {
4747 } ;
4848}
4949
50- /// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated.
50+ /// This is equivalent to [`std::assert_eq`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_eq`]
5151#[ cfg( not( feature = "strict_asserts" ) ) ]
5252#[ macro_export]
5353macro_rules! strict_assert_eq {
@@ -56,7 +56,7 @@ macro_rules! strict_assert_eq {
5656 } ;
5757}
5858
59- /// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated.
59+ /// This is equivalent to [`std::assert_ne`] if the `strict_asserts` feature is activated, otherwise equal to [`std::debug_assert_ne`]
6060#[ cfg( not( feature = "strict_asserts" ) ) ]
6161#[ macro_export]
6262macro_rules! strict_assert_ne {
@@ -65,21 +65,27 @@ macro_rules! strict_assert_ne {
6565 } ;
6666}
6767
68- /// Used to implement strict_assert for unwrap_unchecked
68+ /// Unwrapping using strict_asserts
6969pub trait StrictAssertUnwrapExt < T > {
70- /// Implementation of strict_assert for unwrap_unchecked
71- fn strict_unwrap_unchecked ( self ) -> T ;
70+ /// Unchecked unwrap, with a [`strict_assert`] backed assertion of validitly.
71+ ///
72+ /// SAFETY:
73+ ///
74+ /// It _must_ be valid to call unwrap_unchecked on this value.
75+ unsafe fn strict_unwrap_unchecked ( self ) -> T ;
7276}
7377
7478impl < T > StrictAssertUnwrapExt < T > for Option < T > {
75- fn strict_unwrap_unchecked ( self ) -> T {
79+ unsafe fn strict_unwrap_unchecked ( self ) -> T {
7680 strict_assert ! ( self . is_some( ) , "Called strict_unwrap_unchecked on None" ) ;
81+ // SAFETY: Checked by above assert, or by assertion by unsafe.
7782 unsafe { self . unwrap_unchecked ( ) }
7883 }
7984}
8085
8186impl < T , E > StrictAssertUnwrapExt < T > for Result < T , E > {
82- fn strict_unwrap_unchecked ( self ) -> T {
87+ unsafe fn strict_unwrap_unchecked ( self ) -> T {
88+ // SAFETY: Checked by above assert, or by assertion by unsafe.
8389 strict_assert ! ( self . is_ok( ) , "Called strict_unwrap_unchecked on Err" ) ;
8490 unsafe { self . unwrap_unchecked ( ) }
8591 }
0 commit comments