-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
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.
Metadata
Metadata
Assignees
Labels
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Manishearth commentedon May 18, 2016
I don't think typeid is supposed to be consistent across compilations
eddyb commentedon May 18, 2016
It looks like this is part of the same compilation, which would make it a bug.
Manishearth commentedon May 18, 2016
Oh, my bad.
MasonRemaley commentedon May 18, 2016
Yup, I should've made that a little clearer--I'm getting two different ids during the same run.
eddyb commentedon Jul 11, 2016
On IRC @willcrichton pointed out that
ProjectionPredicate
(found inExistentialBounds
, which gets hashed wholesale) would hash differently in different crates, and that's indeed what's happening here: it containsTy
(which hashes as an arena pointer),DefId
(which differs based on the crate you're seeing it from) andName
(which hashes as the index in the string interner).The immediate solution here is to manually include those in, with
Name
hashed as its string form.Manishearth commentedon Jul 11, 2016
Sounds simple enough to fix then, @willcrichton are you working on this or should I pick it up?
willcrichton commentedon Jul 12, 2016
@Manishearth I'll take a stab at it and post any troubles here.
Auto merge of #35267 - eddyb:ty-hash, r=nikomatsakis