Skip to content

TypeID of Box<Fn() -> ()> inconsistent across crates #33703

Closed
@MasonRemaley

Description

@MasonRemaley

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 TypeIds. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions