Skip to content

Commit 2d188cb

Browse files
committed
Monomorphize a bit of error handling in declare_class!
Mostly to make the assembly tests more stable
1 parent 6d351f2 commit 2d188cb

File tree

3 files changed

+340
-416
lines changed

3 files changed

+340
-416
lines changed

crates/objc2/src/__macro_helpers/declared_ivars.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,14 @@ pub(crate) fn register_with_ivars<T: DeclaredClass>(
281281
let cls = builder.register();
282282

283283
let ivars_offset = if T::HAS_IVARS {
284+
// Monomorphized error handling
285+
// Intentionally not #[track_caller], we expect this error to never occur
286+
fn get_ivar_failed() -> ! {
287+
unreachable!("failed retrieving instance variable on newly declared class")
288+
}
289+
284290
cls.instance_variable(&ivar_name)
285-
.expect("failed retrieving instance variable on newly declared class")
291+
.unwrap_or_else(|| get_ivar_failed())
286292
.offset()
287293
} else {
288294
// Fallback to an offset of zero.
@@ -293,8 +299,14 @@ pub(crate) fn register_with_ivars<T: DeclaredClass>(
293299
};
294300

295301
let drop_flag_offset = if T::HAS_DROP_FLAG {
302+
// Monomorphized error handling
303+
// Intentionally not #[track_caller], we expect this error to never occur
304+
fn get_drop_flag_failed() -> ! {
305+
unreachable!("failed retrieving drop flag instance variable on newly declared class")
306+
}
307+
296308
cls.instance_variable(&drop_flag_name)
297-
.expect("failed retrieving drop flag instance variable on newly declared class")
309+
.unwrap_or_else(|| get_drop_flag_failed())
298310
.offset()
299311
} else {
300312
// Fall back to an offset of zero.

0 commit comments

Comments
 (0)