1 use super::MISSING_SPIN_LOOP;
2 use clippy_utils::diagnostics::span_lint_and_sugg;
3 use clippy_utils::is_no_std_crate;
4 use rustc_errors::Applicability;
5 use rustc_hir::{Block, Expr, ExprKind};
6 use rustc_lint::LateContext;
10 fn unpack_cond<'tcx>(cond: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
20 | ExprKind::Unary(_, e) => unpack_cond(e),
21 ExprKind::Binary(_, l, r) => {
22 let l = unpack_cond(l);
23 if let ExprKind::MethodCall(..) = l.kind {
33 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>) {
35 if let ExprKind::Block(Block { stmts: [], expr: None, ..}, _) = body.kind;
36 if let ExprKind::MethodCall(method, callee, ..) = unpack_cond(cond).kind;
37 if [sym::load, sym::compare_exchange, sym::compare_exchange_weak].contains(&method.ident.name);
38 if let ty::Adt(def, _substs) = cx.typeck_results().expr_ty(callee).kind();
39 if cx.tcx.is_diagnostic_item(sym::AtomicBool, def.did());
45 "busy-waiting loop should at least have a spin loop hint",
47 (if is_no_std_crate(cx) {
48 "{ core::hint::spin_loop() }"
50 "{ std::hint::spin_loop() }"
52 Applicability::MachineApplicable