News for hackers. Stuff that matters.
Re:I_suck_and_my_tests_are_order_dependent by tialaramex on Thursday February 16, 2023 @08:23PM (#34829425)
There is no such "compiler flag" in Rust, that's only a C# thing.

But also more relevantly here, stuff you'd be calling in those Rust blocks tends to have longer names and often calls out the fact it's specifically not checked, e.g.

  a = b.unchecked_add(c); // Like a C or C++ arithmetic operation if you overflow it's UB. This might be faster. It might not. But if you must have this anyway, that's how

  n = NonZeroU32::new_unchecked(0); // Unlike new() which returns None because duh, zero isn't non-zero, this results in UB.
Not all of them though, for example:

  v = Vec::from_raw_parts(ptr, len, cap); // Make a Vec, the pointer ptr had better actually be pointing at contiguous memory for exactly cap item-sized slots, the first len of which are in fact legitimately values of the appropriate type, if any of this is wrong that's immediately UB.
Re:I_suck_and_my_tests_are_order_dependent by CamJN on Thursday February 16, 2023 @11:03PM (#34830601)
While sadly it does not require a flag to enable, at least you can turn it off with: `#![forbid(unsafe_code)]`.