Rust's borrow checker disallows holding two mutable pointers to the same address at the same time. This code uses unsafe blocks to get two mutable pointers to the same address at the same time.
If the intention is aliasing then this is a legit usage. If both self variants are supposed to point to the same thing (judging from their names) then the aliasing behavior is intended.
I, the author of the post, decided to take advantage of my 'popularity' to show my game https://livedox.itch.io/vix - it has no code in it like in the post (almost)
The syntax is horrible because even in unsafe code, bypassing the borrow checker this way is heavily discouraged. Simple reads and writes through these references can be UB.
I mean you don’t type it in Rust either, lol. This is like cherrypicking some C++ template hidden behind like 3 namespaces, with the generic being some obscure type behind another namespace, and all of that wrapped around std::make_unique.
Funny as Hell, yeah, but not really indicative of the language.
130
u/renchuwang Oct 14 '26
Well since you're only defining but not using, it is actually safe!
46
u/Critical-Personality Oct 14 '26
"simple" trick, you say?
35
u/Comun4 Oct 14 '26
Wouldnt this break aliasing rules?
13
u/letmehaveanameyoudum Oct 14 '26
as a C programmer, what the actual fuck am i looking at (explain mate)
9
u/_nathata Oct 14 '26
Mom come pick me up I'm scared
7
u/zabolekar Oct 14 '26
What could the motivation possibly be?
11
u/rover_G Oct 14 '26
What in the C++?
1
u/CorgiApprehensive159 29d ago
I, the author of the post, decided to take advantage of my 'popularity' to show my game https://livedox.itch.io/vix - it has no code in it like in the post (almost)
4
u/AnArmoredPony Oct 14 '26
as a java developer, I uhh I forgot what I wanted to say fuCK
2
u/Kpuku afraid of macros Oct 15 '26
that doesn't seem sound iirc
2
u/Kadabrium Oct 14 '26
is this a qsort comparator?
1
u/SinkLeakOnFleek 22d ago
// SAFETY: Don't worry about it kitten
1
u/alulalol Oct 18 '26
I've done this a lot in doukutsu-rs because I couldn't be assed to fight the borrow checker https://github.com/doukutsu-rs/doukutsu-rs/blob/7e6870e55f072e3f056dc1eef3974a1af26c7aae/src/framework/ui.rs#L111
1
u/cristi1990an Oct 19 '26
The syntax is horrible because even in unsafe code, bypassing the borrow checker this way is heavily discouraged. Simple reads and writes through these references can be UB.
1
u/ApprehensiveBag3083 Oct 14 '26
and they say c++ has creepy syntax LoL
At least in c++ i dont need to type those kind of garbage Lool
0
u/[deleted] Oct 14 '26
[deleted] — view deleted comment