This post is removed by the author. The idea is incorrect. Thanks for your attention!
Making code that used to compile not compile is a breaking change.
It’s entirely possible to write a type that has interior mutability and upholds the invariants necessary for HashMap and BTreeMap to work.
This also breaks all code that is parameterized over a type used as a key in a hashmap or hashset.
Em, you are right. Thanks for all your reply. I would like to withdraw this post.
As an aside, please don’t do that! It’s pretty frustrating to come by and only see the remnants of a discussion. Nobodys judging you for starting a thread that did not turn into a revolution, so just leave it be, others might be interested nonetheless.
Also, if you withdraw it then no one with the same idaya in the future can google to find the past discussion.
Sorry for the inconvenience. My basic idea of this post is to introduce a auto trait
NonInteriorMut to indicate whether a type has interior mutability or not. And add this trait as a constraint to the key type of associative containers (
BTreeMap etc), to prevent keys being modified when they are in the container.