Are these sound?

So we made anycast recently. We rely on it to turn things into dyn Any and to provide Eq for a dyn Trait type. Does this actually work as intended? There's no way to fake the dyn Any, is there?

The crate has no unsafe blocks, so it is sound.

1 Like

If there's no unsafe, it's sound.

This might be sketchier (on the logical side if not the soundness side), but it doesn't seem to be part of the crate. Unless you just mean the part in test where you check for pointer equality after downcasting in that test block, in which case you have all the usual problems of considering two pointers equal (ZSTs, struct and slice prefixes...).

Not sure what you mean here. Some other code could unsoundly create a fake &dyn Any reference no problem, of course.

1 Like

we mean there's no way to impl Anycast for a custom type, is there?

(the dyn Trait with Eq is because Trait: Eq so it should be fine. actually there are two traits and one of them is private. but anyway.)

No, due to your blanket impl (outside specialization) and sealed supertrait (even with specialization).

I'm not sure what you're actually concerned about, but a specific type could have an inherent method called any_ref, say, that you accidentally call somewhere. But if you're working with generics so all you know are trait bounds, you wouldn't see (wouldn't be able to call) such an inherent method.

2 Likes

Very minor point: Any is unsound an the sense of hash collision being a real thing

( Note that I'm not 100%) Sure

1 Like

Yes, that is a known issue. It also has known solutions, not that anyone cares enough to implement them in rustc.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.