You should read  to understand how Rust achieves this.
A data race has Undefined Behavior, and is therefore impossible to perform in Safe Rust.
However Rust does not prevent general race conditions.
This is pretty fundamentally impossible, and probably honestly undesirable. Your hardware
is racy, your OS is racy, the other programs on your computer are racy, and the world this
all runs in is racy. Any system that could genuinely claim to prevent all race conditions
would be pretty awful to use, if not just incorrect.
Maybe you should read a bit more on its docs . I quote: