11
11
//! `wgpu-core`'s `"strict_asserts"` feature enables that validation
12
12
//! in both debug and release builds.
13
13
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`] .
15
15
#[ cfg( feature = "strict_asserts" ) ]
16
16
#[ macro_export]
17
17
macro_rules! strict_assert {
@@ -20,7 +20,7 @@ macro_rules! strict_assert {
20
20
}
21
21
}
22
22
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`] .
24
24
#[ cfg( feature = "strict_asserts" ) ]
25
25
#[ macro_export]
26
26
macro_rules! strict_assert_eq {
@@ -29,7 +29,7 @@ macro_rules! strict_assert_eq {
29
29
}
30
30
}
31
31
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`] .
33
33
#[ cfg( feature = "strict_asserts" ) ]
34
34
#[ macro_export]
35
35
macro_rules! strict_assert_ne {
@@ -38,7 +38,7 @@ macro_rules! strict_assert_ne {
38
38
}
39
39
}
40
40
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`]
42
42
#[ cfg( not( feature = "strict_asserts" ) ) ]
43
43
#[ macro_export]
44
44
macro_rules! strict_assert {
@@ -47,7 +47,7 @@ macro_rules! strict_assert {
47
47
} ;
48
48
}
49
49
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`]
51
51
#[ cfg( not( feature = "strict_asserts" ) ) ]
52
52
#[ macro_export]
53
53
macro_rules! strict_assert_eq {
@@ -56,7 +56,7 @@ macro_rules! strict_assert_eq {
56
56
} ;
57
57
}
58
58
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`]
60
60
#[ cfg( not( feature = "strict_asserts" ) ) ]
61
61
#[ macro_export]
62
62
macro_rules! strict_assert_ne {
@@ -65,21 +65,27 @@ macro_rules! strict_assert_ne {
65
65
} ;
66
66
}
67
67
68
- /// Used to implement strict_assert for unwrap_unchecked
68
+ /// Unwrapping using strict_asserts
69
69
pub 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 ;
72
76
}
73
77
74
78
impl < T > StrictAssertUnwrapExt < T > for Option < T > {
75
- fn strict_unwrap_unchecked ( self ) -> T {
79
+ unsafe fn strict_unwrap_unchecked ( self ) -> T {
76
80
strict_assert ! ( self . is_some( ) , "Called strict_unwrap_unchecked on None" ) ;
81
+ // SAFETY: Checked by above assert, or by assertion by unsafe.
77
82
unsafe { self . unwrap_unchecked ( ) }
78
83
}
79
84
}
80
85
81
86
impl < 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.
83
89
strict_assert ! ( self . is_ok( ) , "Called strict_unwrap_unchecked on Err" ) ;
84
90
unsafe { self . unwrap_unchecked ( ) }
85
91
}
0 commit comments