diff --git a/src/dynamic.rs b/src/dynamic.rs index 5478efa2..abafc404 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1195,18 +1195,24 @@ impl Dynamic { match self.0 { Union::Shared(_, _) => match crate::stdlib::mem::take(self).0 { Union::Shared(cell, _) => { - let value = crate::fn_native::shared_take_or_clone(cell); + *self = crate::fn_native::shared_try_take(cell).map_or_else( + |cell| { + #[cfg(not(feature = "sync"))] + let value = cell.borrow(); + #[cfg(feature = "sync")] + let value = cell.read().unwrap(); - #[cfg(not(feature = "sync"))] - { - *self = value.into_inner(); - } - #[cfg(feature = "sync")] - { - *self = value.into_inner().unwrap(); - } + value.clone() + }, + |value| { + #[cfg(not(feature = "sync"))] + return value.into_inner(); + #[cfg(feature = "sync")] + return value.into_inner().unwrap(); + }, + ) } - _ => unreachable!(), + _ => unreachable!("self should be Shared"), }, _ => (), } diff --git a/src/engine.rs b/src/engine.rs index 113150f9..b4ac13c2 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -405,8 +405,8 @@ impl<'a> Target<'a> { Self::LockGuard((r, _)) => **r = new_val, Self::Value(_) => panic!("cannot update a value"), #[cfg(not(feature = "no_index"))] - Self::StringChar(string, index, _) if string.is::() => { - let mut s = string.write_lock::().unwrap(); + Self::StringChar(s, index, _) if s.is::() => { + let mut s = s.write_lock::().unwrap(); // Replace the character at the specified index position let new_ch = new_val.as_char().map_err(|err| { @@ -426,7 +426,10 @@ impl<'a> Target<'a> { } } #[cfg(not(feature = "no_index"))] - Self::StringChar(_, _, _) => unreachable!(), + Self::StringChar(s, _, _) => unreachable!( + "Target::StringChar should contain only a string, not {}", + s.type_name() + ), } Ok(()) diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 94fc32c6..6531ef39 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -147,7 +147,7 @@ impl From<&crate::module::FuncInfo> for FnMetadata { doc_comments: if info.func.is_script() { #[cfg(feature = "no_function")] { - unreachable!() + unreachable!("scripted functions should not exist under no_function") } #[cfg(not(feature = "no_function"))] {