@@ -249,27 +249,30 @@ impl AnyRef {
249249 /// This function assumes that `raw` is an `anyref` value which is currently
250250 /// rooted within the [`Store`].
251251 ///
252- /// # Unsafety
252+ /// # Correctness
253253 ///
254- /// This function is particularly `unsafe` because `raw` not only must be a
255- /// valid `anyref` value produced prior by [`AnyRef::to_raw`] but it must
256- /// also be correctly rooted within the store. When arguments are provided
257- /// to a callback with [`Func::new_unchecked`], for example, or returned via
258- /// [`Func::call_unchecked`], if a GC is performed within the store then
259- /// floating `anyref` values are not rooted and will be GC'd, meaning that
260- /// this function will no longer be safe to call with the values cleaned up.
261- /// This function must be invoked *before* possible GC operations can happen
262- /// (such as calling Wasm).
254+ /// This function is tricky to get right because `raw` not only must be a
255+ /// valid `anyref` value produced prior by [`AnyRef::to_raw`] but it
256+ /// must also be correctly rooted within the store. When arguments are
257+ /// provided to a callback with [`Func::new_unchecked`], for example, or
258+ /// returned via [`Func::call_unchecked`], if a GC is performed within the
259+ /// store then floating `anyref` values are not rooted and will be GC'd,
260+ /// meaning that this function will no longer be correct to call with the
261+ /// values cleaned up. This function must be invoked *before* possible GC
262+ /// operations can happen (such as calling Wasm).
263263 ///
264- /// When in doubt try to not use this. Instead use the safe Rust APIs of
265- /// [`TypedFunc`] and friends.
264+ ///
265+ /// When in doubt try to not use this. Instead use the Rust APIs of
266+ /// [`TypedFunc`] and friends. Note though that this function is not
267+ /// `unsafe` as any value can be passed in. Incorrect values can result in
268+ /// runtime panics, however, so care must still be taken with this method.
266269 ///
267270 /// [`Func::call_unchecked`]: crate::Func::call_unchecked
268271 /// [`Func::new_unchecked`]: crate::Func::new_unchecked
269272 /// [`Store`]: crate::Store
270273 /// [`TypedFunc`]: crate::TypedFunc
271274 /// [`ValRaw`]: crate::ValRaw
272- pub unsafe fn from_raw ( mut store : impl AsContextMut , raw : u32 ) -> Option < Rooted < Self > > {
275+ pub fn from_raw ( mut store : impl AsContextMut , raw : u32 ) -> Option < Rooted < Self > > {
273276 let mut store = AutoAssertNoGc :: new ( store. as_context_mut ( ) . 0 ) ;
274277 Self :: _from_raw ( & mut store, raw)
275278 }
@@ -320,19 +323,19 @@ impl AnyRef {
320323 ///
321324 /// Returns an error if this `anyref` has been unrooted.
322325 ///
323- /// # Unsafety
326+ /// # Correctness
324327 ///
325- /// Produces a raw value which is only safe to pass into a store if a GC
328+ /// Produces a raw value which is only valid to pass into a store if a GC
326329 /// doesn't happen between when the value is produce and when it's passed
327330 /// into the store.
328331 ///
329332 /// [`ValRaw`]: crate::ValRaw
330- pub unsafe fn to_raw ( & self , mut store : impl AsContextMut ) -> Result < u32 > {
333+ pub fn to_raw ( & self , mut store : impl AsContextMut ) -> Result < u32 > {
331334 let mut store = AutoAssertNoGc :: new ( store. as_context_mut ( ) . 0 ) ;
332335 self . _to_raw ( & mut store)
333336 }
334337
335- pub ( crate ) unsafe fn _to_raw ( & self , store : & mut AutoAssertNoGc < ' _ > ) -> Result < u32 > {
338+ pub ( crate ) fn _to_raw ( & self , store : & mut AutoAssertNoGc < ' _ > ) -> Result < u32 > {
336339 let gc_ref = self . inner . try_clone_gc_ref ( store) ?;
337340 let raw = if gc_ref. is_i31 ( ) {
338341 gc_ref. as_raw_non_zero_u32 ( )
0 commit comments