It 100% causes undefined behavior every time. They are the same thing. UB == instant undefined behavior. I don't know how to state it any clearer.
"Does what you hoped with the current compilation" is a subset of undefined behavior, because undefined behavior can do anything if compilation succeeds.
What you probably actually mean is "causes a miscompilation from my POV (i.e. doesn't do what you hoped with the current compilation)". That is not the same thing as undefined behavior. You 100% have undefined behavior. UB and undefined behavior are the same thing. Stop calling the "doesn't do what you hoped" thing "undefined behavior". You need a different terminology if you're going to be able to communicate effectively.
You think you do, as thousands before have as well. Time may prove you wrong.
There are no guarantees about what will "never really happen". That's the point. There's a long history of more UB things being exhibited as compilers become more agressive over time.
People who thought they knew better are the cause of untold numbers of bugs and fallout, with more every day. Changing that paradigm is one of the major motivations and benefits of Rust.
Alright, now let's say you don't give a hoot about any of that, and you're just looking for an opinion of what you can "get away with" with the current compiler (on your platform with your flags yadda yadda).
For any personal project or exploration,that's fine, knock yourself out! [2] But you'll have to be very upfront with your stance on forums like this, and probably won't find much help.
I think this is the best I've said it:
I get it, but I think you're going to keep getting friction, for at least two distinct reasons:
One is cultural -- preferring "definitely sound" to "happens to work today" is pretty entwined with the general safety guarantees of Rust, which are highly valued. Seems likely that you'll need to get past this part of the conversation every time. (This also leads to people not wanting "quick-and-dirty like C" to be common in Rust, as that would weaken it's "safer and more reliable" associations.)
Conflation of terminology: you led with "Is it safe", and in a Rust context, this is almost always going to be taken as "is it sound". Similarly, UB is usually not considered a what-it-compiled-to term, like was already hashed-over above.
The latter could be mitigated by being more explicit or using different terminology. But you'll also probably never get a very satisfying answer, due to the former cultural considerations -- people are a lot less interested in "getting away with" unsoundness compared to C, and thus don't know or necessarily even care when you can do it, because "you shouldn't".
Now, if you want to expand this attitude to some publicly used crate, you'll likely experience backlash and rejection. You're swimming strongly against the cultural tide.
Incidentally this is also all true in C, there's just a large ignorance/sea of denial about C switching to an abstract machine model long ago, widespread use of compiler extensions to redefine what's UB thus creating different C dialects, a cultural acceptance/conflation between "it compiled ok" and UB, etc. ↩︎
IMO, some will still deride you. ↩︎