]> git.lizzy.rs Git - rust.git/blob - tests/ui/missing_spin_loop.fixed
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / missing_spin_loop.fixed
1 // run-rustfix
2 #![warn(clippy::missing_spin_loop)]
3 #![allow(clippy::bool_comparison)]
4 #![allow(unused_braces)]
5
6 use core::sync::atomic::{AtomicBool, Ordering};
7
8 fn main() {
9     let b = AtomicBool::new(true);
10     // Those should lint
11     while b.load(Ordering::Acquire) { std::hint::spin_loop() }
12
13     while !b.load(Ordering::SeqCst) { std::hint::spin_loop() }
14
15     while b.load(Ordering::Acquire) == false { std::hint::spin_loop() }
16
17     while { true == b.load(Ordering::Acquire) } { std::hint::spin_loop() }
18
19     while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) { std::hint::spin_loop() }
20
21     while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) { std::hint::spin_loop() }
22
23     // This is OK, as the body is not empty
24     while b.load(Ordering::Acquire) {
25         std::hint::spin_loop()
26     }
27     // TODO: also match on loop+match or while let
28 }