You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi.
The crate looks promising, however I bumped with a pretty cryptic error. MRE:
use thin_trait_object::*;#[derive(Debug,Clone)]structBar(String);#[thin_trait_object]traitFoo{fnfooify(&self,bar:&Bar);}implFooforString{fnfooify(&self,bar:&Bar){println!("Fooified a string: {} {:?}",self,bar);}}fnmain(){let bar = Bar("suffix".to_string());BoxedFoo::new("Hello World!".to_string()).fooify(&bar);}
The error:
➜ thin_trait_object git:(main) ✗ cargo run --example basic
Compiling thin_trait_object v1.1.1 (/Users/nick/rust/scai/utils/cxx-all/thin_trait_object)
error: implementation of `Hash` is not general enough
--> examples/basic.rs:6:1
|
6 | #[thin_trait_object]
| ^^^^^^^^^^^^^^^^^^^^ implementation of `Hash` is not general enough
|
= note: `Hash` would have to be implemented for the type `for<'r> unsafe fn(*mut c_void, &'r Bar)`
= note: ...but `Hash` is actually implemented for the type `unsafe fn(*mut c_void, &'0 Bar)`, for some specific lifetime `'0`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: implementation of `Debug` is not general enough
--> examples/basic.rs:6:1
|
6 | #[thin_trait_object]
| ^^^^^^^^^^^^^^^^^^^^ implementation of `Debug` is not general enough
|
= note: `Debug` would have to be implemented for the type `for<'r> unsafe fn(*mut c_void, &'r Bar)`
= note: ...but `Debug` is actually implemented for the type `unsafe fn(*mut c_void, &'0 Bar)`, for some specific lifetime `'0`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
This is indeed so cryptic that I suspect it may be a compiler bug. What's happening here is that it's trying to compile FooVtable's definition which looks like this:
where the unsafe fn(*mut ::core::ffi::c_void, &Bar) desugars into for<'r> unsafe fn(*mut ::core::ffi::c_void, &'r Bar). The #[derive(Debug, Hash)] derives then try to use the implementation of Debug on that type, for<'r> unsafe fn(*mut ::core::ffi::c_void, &'r Bar), which is the type of the field, but that fails for... some reason. It really shouldn't: Debug should be implemented for all fn types and the implicit HRTB, for<'r>, has nothing to do with the function pointer's ability to be printed.
I'm currently writing a band-aid fix to this (implementing Debug and Hash manually by casting the function pointer to a *mut ::core::ffi::c_void), and will explore the compiler bug further if I can.
This indeed turned out to be a known compiler bug. I've just released a fix in 1.1.2 which is functionally identical to how the derives would behave once the compiler bug is fixed.
Hi.
The crate looks promising, however I bumped with a pretty cryptic error. MRE:
The error:
I also put the MRE into the fork https://github.com/nlinker/thin_trait_object/blob/main/examples/basic.rs
The text was updated successfully, but these errors were encountered: