I can see why youâd take that position, but I disagree. Rc explicitly allows cycles, and when working with them you need to be careful not to create them. After all, leaking memory is allowed in safe Rust (see Box::leak). On the other hand, here youâve created a horror of horrors: an aliased Box; in this case, Box which contains itself (which produces exciting results when printed, or, better yet, dropped!).
Imagine the analogous C++ situation of std::unique_ptr and std::shared_ptr.
Depends on how much of that type is blessed⌠and Box is (for unfortunate, hilarious reasons) among the holiest of holies of such types. As listed in the nomiconâs (exhaustive) list of UB types,
I think it is completely fair to consider that violating the invariants of a type foreign to your crate, which its unsafe interface does not permit (with or without strings attached), is UB. Especially for lang items like Box. Note that you did not use any of Box's unsafe interfaces, but instead performed great evils with std::{mem, ptr}.
Like, I get the point youâre trying to make, and I agree that the compiler trying to prove that Haskal is uninhabited is going to result in⌠hilarious, unforeseeable problems (unless a repr hint is allowed to prevent this).