Closed
Description
The TypeID of Box<Fn() -> ()>
seems to be inconsistent across crates in both nightly and stable, I found a similar closed issue from a couple years ago and wasn't sure whether I should comment on that or file a new bug. I can recreate it consistently as follows:
typeid_issue/lib.rs:
pub fn check() {
println!("{:?}", std::any::TypeId::of::<Box<Fn() -> ()>>());
}
typeid_issue/examples/example.rs:
extern crate typeid_issue;
fn main() {
println!("{:?}", std::any::TypeId::of::<Box<Fn() -> ()>>());
typeid_issue::check();
}
On my machine, cargo run --example example
with the above project outputs two different TypeId
s. The same thing doesn't happen for all types, e.g. Box<i32>
s seem to work fine, and Box<Fn() -> ()>
wrapped in a struct seems to work fine giving me a nice work around for now.