5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- #[ cfg( debug_assertions ) ]
8
+ #[ cfg( checks_at_least = "paranoid" ) ]
9
9
use std:: cell:: Cell ;
10
10
use std:: cell:: RefCell ;
11
11
use std:: collections:: hash_map:: Entry ;
@@ -27,7 +27,7 @@ thread_local! {
27
27
}
28
28
29
29
/// Represents the initialization state of a `Base<T>` object.
30
- #[ cfg( debug_assertions ) ]
30
+ #[ cfg( checks_at_least = "paranoid" ) ]
31
31
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
32
32
enum InitState {
33
33
/// Object is being constructed (inside `I*::init()` or `Gd::from_init_fn()`).
@@ -38,14 +38,14 @@ enum InitState {
38
38
Script ,
39
39
}
40
40
41
- #[ cfg( debug_assertions ) ]
41
+ #[ cfg( checks_at_least = "paranoid" ) ]
42
42
macro_rules! base_from_obj {
43
43
( $obj: expr, $state: expr) => {
44
44
Base :: from_obj( $obj, $state)
45
45
} ;
46
46
}
47
47
48
- #[ cfg( not( debug_assertions ) ) ]
48
+ #[ cfg( not( checks_at_least = "paranoid" ) ) ]
49
49
macro_rules! base_from_obj {
50
50
( $obj: expr, $state: expr) => {
51
51
Base :: from_obj( $obj)
@@ -82,7 +82,7 @@ pub struct Base<T: GodotClass> {
82
82
/// Tracks the initialization state of this `Base<T>` in Debug mode.
83
83
///
84
84
/// Rc allows to "copy-construct" the base from an existing one, while still affecting the user-instance through the original `Base<T>`.
85
- #[ cfg( debug_assertions ) ]
85
+ #[ cfg( checks_at_least = "paranoid" ) ]
86
86
init_state : Rc < Cell < InitState > > ,
87
87
}
88
88
@@ -101,7 +101,7 @@ impl<T: GodotClass> Base<T> {
101
101
102
102
Self {
103
103
obj : ManuallyDrop :: new ( obj) ,
104
- #[ cfg( debug_assertions ) ]
104
+ #[ cfg( checks_at_least = "paranoid" ) ]
105
105
init_state : Rc :: clone ( & base. init_state ) ,
106
106
}
107
107
}
@@ -141,15 +141,15 @@ impl<T: GodotClass> Base<T> {
141
141
base_from_obj ! ( obj, InitState :: ObjectConstructing )
142
142
}
143
143
144
- #[ cfg( debug_assertions ) ]
144
+ #[ cfg( checks_at_least = "paranoid" ) ]
145
145
fn from_obj ( obj : Gd < T > , init_state : InitState ) -> Self {
146
146
Self {
147
147
obj : ManuallyDrop :: new ( obj) ,
148
148
init_state : Rc :: new ( Cell :: new ( init_state) ) ,
149
149
}
150
150
}
151
151
152
- #[ cfg( not( debug_assertions ) ) ]
152
+ #[ cfg( not( checks_at_least = "paranoid" ) ) ]
153
153
fn from_obj ( obj : Gd < T > ) -> Self {
154
154
Self {
155
155
obj : ManuallyDrop :: new ( obj) ,
@@ -187,7 +187,7 @@ impl<T: GodotClass> Base<T> {
187
187
/// If called outside an initialization function, or for ref-counted objects on a non-main thread.
188
188
#[ cfg( since_api = "4.2" ) ]
189
189
pub fn to_init_gd ( & self ) -> Gd < T > {
190
- #[ cfg( debug_assertions ) ] // debug_assert! still checks existence of symbols.
190
+ #[ cfg( checks_at_least = "paranoid" ) ] // debug_assert! still checks existence of symbols.
191
191
assert ! (
192
192
self . is_initializing( ) ,
193
193
"Base::to_init_gd() can only be called during object initialization, inside I*::init() or Gd::from_init_fn()"
@@ -253,7 +253,7 @@ impl<T: GodotClass> Base<T> {
253
253
254
254
/// Finalizes the initialization of this `Base<T>` and returns whether
255
255
pub ( crate ) fn mark_initialized ( & mut self ) {
256
- #[ cfg( debug_assertions ) ]
256
+ #[ cfg( checks_at_least = "paranoid" ) ]
257
257
{
258
258
assert_eq ! (
259
259
self . init_state. get( ) ,
@@ -270,7 +270,7 @@ impl<T: GodotClass> Base<T> {
270
270
/// Returns a [`Gd`] referencing the base object, assuming the derived object is fully constructed.
271
271
#[ doc( hidden) ]
272
272
pub fn __fully_constructed_gd ( & self ) -> Gd < T > {
273
- #[ cfg( debug_assertions ) ] // debug_assert! still checks existence of symbols.
273
+ #[ cfg( checks_at_least = "paranoid" ) ] // debug_assert! still checks existence of symbols.
274
274
assert ! (
275
275
!self . is_initializing( ) ,
276
276
"WithBaseField::to_gd(), base(), base_mut() can only be called on fully-constructed objects, after I*::init() or Gd::from_init_fn()"
@@ -301,7 +301,7 @@ impl<T: GodotClass> Base<T> {
301
301
302
302
/// Returns a [`Gd`] referencing the base object, for use in script contexts only.
303
303
pub ( crate ) fn to_script_gd ( & self ) -> Gd < T > {
304
- #[ cfg( debug_assertions ) ]
304
+ #[ cfg( checks_at_least = "paranoid" ) ]
305
305
assert_eq ! (
306
306
self . init_state. get( ) ,
307
307
InitState :: Script ,
@@ -312,15 +312,15 @@ impl<T: GodotClass> Base<T> {
312
312
}
313
313
314
314
/// Returns `true` if this `Base<T>` is currently in the initializing state.
315
- #[ cfg( debug_assertions ) ]
315
+ #[ cfg( checks_at_least = "paranoid" ) ]
316
316
fn is_initializing ( & self ) -> bool {
317
317
self . init_state . get ( ) == InitState :: ObjectConstructing
318
318
}
319
319
320
320
/// Returns a [`Gd`] referencing the base object, assuming the derived object is fully constructed.
321
321
#[ doc( hidden) ]
322
322
pub fn __constructed_gd ( & self ) -> Gd < T > {
323
- #[ cfg( debug_assertions ) ] // debug_assert! still checks existence of symbols.
323
+ #[ cfg( checks_at_least = "paranoid" ) ] // debug_assert! still checks existence of symbols.
324
324
assert ! (
325
325
!self . is_initializing( ) ,
326
326
"WithBaseField::to_gd(), base(), base_mut() can only be called on fully-constructed objects, after I*::init() or Gd::from_init_fn()"
0 commit comments