diff --git a/src/closure.rs b/src/closure.rs index 957f68fe976..885b5975367 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -4,6 +4,7 @@ //! closures" from Rust to JS. Some more details can be found on the `Closure` //! type itself. +use std::fmt; #[cfg(feature = "nightly")] use std::marker::Unsize; use std::mem::{self, ManuallyDrop}; @@ -489,6 +490,15 @@ fn _check() { _assert::<&Closure String>>(); } +impl fmt::Debug for Closure +where + T: ?Sized, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Closure {{ ... }}") + } +} + impl Drop for Closure where T: ?Sized, diff --git a/tests/wasm/closures.rs b/tests/wasm/closures.rs index ed1e29def1e..4ce047f0d08 100755 --- a/tests/wasm/closures.rs +++ b/tests/wasm/closures.rs @@ -107,6 +107,12 @@ fn cannot_reuse() { assert!(cannot_reuse_call_again().is_err()); } +#[wasm_bindgen_test] +fn debug() { + let closure = Closure::wrap(Box::new(|| {}) as Box); + assert_eq!(&format!("{:?}", closure), "Closure { ... }"); +} + #[wasm_bindgen_test] fn long_lived() { let hit = Rc::new(Cell::new(false));