Skip to content

Commit

Permalink
Display object's kind if unchecked cast fails
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 30, 2024
1 parent aed85a9 commit 66998bc
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions crates/types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Object {
/// with any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_boolean_unchecked(&self) -> bool {
debug_assert!(self.ty == ObjectKind::Boolean);
debug_assert!(self.ty == ObjectKind::Boolean, "{:?}", self.ty);
self.data.boolean
}

Expand All @@ -177,7 +177,7 @@ impl Object {
/// with any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_boolean_unchecked_mut(&mut self) -> &mut bool {
debug_assert!(self.ty == ObjectKind::Boolean);
debug_assert!(self.ty == ObjectKind::Boolean, "{:?}", self.ty);
&mut self.data.boolean
}

Expand All @@ -193,7 +193,7 @@ impl Object {
/// with any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_integer_unchecked(&self) -> Integer {
debug_assert!(self.ty == ObjectKind::Integer);
debug_assert!(self.ty == ObjectKind::Integer, "{:?}", self.ty);
self.data.integer
}

Expand All @@ -210,7 +210,7 @@ impl Object {
/// with any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_integer_unchecked_mut(&mut self) -> &mut Integer {
debug_assert!(self.ty == ObjectKind::Integer);
debug_assert!(self.ty == ObjectKind::Integer, "{:?}", self.ty);
&mut self.data.integer
}

Expand All @@ -226,7 +226,7 @@ impl Object {
/// undefined behavior.
#[inline(always)]
pub unsafe fn as_float_unchecked(&self) -> Float {
debug_assert!(self.ty == ObjectKind::Float);
debug_assert!(self.ty == ObjectKind::Float, "{:?}", self.ty);
self.data.float
}

Expand All @@ -243,7 +243,7 @@ impl Object {
/// undefined behavior.
#[inline(always)]
pub unsafe fn as_float_unchecked_mut(&mut self) -> &mut Float {
debug_assert!(self.ty == ObjectKind::Float);
debug_assert!(self.ty == ObjectKind::Float, "{:?}", self.ty);
&mut self.data.float
}

Expand All @@ -259,7 +259,7 @@ impl Object {
/// any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_luaref_unchecked(&self) -> LuaRef {
debug_assert!(self.ty == ObjectKind::LuaRef);
debug_assert!(self.ty == ObjectKind::LuaRef, "{:?}", self.ty);
self.data.luaref
}

Expand All @@ -276,7 +276,7 @@ impl Object {
/// any other kind may result in undefined behavior.
#[inline(always)]
pub unsafe fn as_luaref_unchecked_mut(&mut self) -> &mut LuaRef {
debug_assert!(self.ty == ObjectKind::LuaRef);
debug_assert!(self.ty == ObjectKind::LuaRef, "{:?}", self.ty);
&mut self.data.luaref
}

Expand All @@ -291,7 +291,7 @@ impl Object {
/// [`String`][ObjectKind::String]. Calling this method on an `Object` with
/// any other kind may result in undefined behavior.
pub unsafe fn as_string_unchecked(&self) -> &crate::String {
debug_assert!(self.ty == ObjectKind::String);
debug_assert!(self.ty == ObjectKind::String, "{:?}", self.ty);
&self.data.string
}

Expand All @@ -307,7 +307,7 @@ impl Object {
/// [`String`][ObjectKind::String]. Calling this method on an `Object` with
/// any other kind may result in undefined behavior.
pub unsafe fn as_string_unchecked_mut(&mut self) -> &mut crate::String {
debug_assert!(self.ty == ObjectKind::String);
debug_assert!(self.ty == ObjectKind::String, "{:?}", self.ty);
&mut self.data.string
}

Expand All @@ -322,7 +322,7 @@ impl Object {
/// [`String`][ObjectKind::String]. Calling this method on an `Object` with
/// any other kind may result in undefined behavior.
pub unsafe fn into_string_unchecked(self) -> crate::String {
debug_assert!(self.ty == ObjectKind::String);
debug_assert!(self.ty == ObjectKind::String, "{:?}", self.ty);
#[allow(clippy::unnecessary_struct_initialization)]
let string = crate::String { ..*self.data.string };
core::mem::forget(self);
Expand All @@ -340,7 +340,7 @@ impl Object {
/// Calling this method on an `Object` with any other kind may result in
/// undefined behavior.
pub unsafe fn as_array_unchecked(&self) -> &Array {
debug_assert!(self.ty == ObjectKind::Array);
debug_assert!(self.ty == ObjectKind::Array, "{:?}", self.ty);
&self.data.array
}

Expand All @@ -356,7 +356,7 @@ impl Object {
/// Calling this method on an `Object` with any other kind may result in
/// undefined behavior.
pub unsafe fn as_array_unchecked_mut(&mut self) -> &mut Array {
debug_assert!(self.ty == ObjectKind::Array);
debug_assert!(self.ty == ObjectKind::Array, "{:?}", self.ty);
&mut self.data.array
}

Expand All @@ -371,7 +371,7 @@ impl Object {
/// Calling this method on an `Object` with any other kind may result in
/// undefined behavior.
pub unsafe fn into_array_unchecked(self) -> Array {
debug_assert!(self.ty == ObjectKind::Array);
debug_assert!(self.ty == ObjectKind::Array, "{:?}", self.ty);
#[allow(clippy::unnecessary_struct_initialization)]
let array = Array(crate::kvec::KVec { ..self.data.array.0 });
core::mem::forget(self);
Expand All @@ -389,7 +389,7 @@ impl Object {
/// [`Dictionary`][ObjectKind::Dictionary]. Calling this method on an
/// `Object` with any other kind may result in undefined behavior.
pub unsafe fn as_dictionary_unchecked(&self) -> &Dictionary {
debug_assert!(self.ty == ObjectKind::Dictionary);
debug_assert!(self.ty == ObjectKind::Dictionary, "{:?}", self.ty);
&self.data.dictionary
}

Expand All @@ -405,7 +405,7 @@ impl Object {
/// [`Dictionary`][ObjectKind::Dictionary]. Calling this method on an
/// `Object` with any other kind may result in undefined behavior.
pub unsafe fn as_dictionary_unchecked_mut(&mut self) -> &mut Dictionary {
debug_assert!(self.ty == ObjectKind::Dictionary);
debug_assert!(self.ty == ObjectKind::Dictionary, "{:?}", self.ty);
&mut self.data.dictionary
}

Expand All @@ -420,7 +420,7 @@ impl Object {
/// [`Dictionary`][ObjectKind::Dictionary]. Calling this method on an
/// `Object` with any other kind may result in undefined behavior.
pub unsafe fn into_dictionary_unchecked(self) -> Dictionary {
debug_assert!(self.ty == ObjectKind::Dictionary);
debug_assert!(self.ty == ObjectKind::Dictionary, "{:?}", self.ty);
#[allow(clippy::unnecessary_struct_initialization)]
let dict = Dictionary(crate::kvec::KVec { ..self.data.dictionary.0 });
core::mem::forget(self);
Expand Down

0 comments on commit 66998bc

Please sign in to comment.