diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2024-09-24 18:59:58 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2024-09-24 19:09:40 +0200 |
| commit | 0791efaaace3927fb6cc716d127561b2028dfc71 (patch) | |
| tree | 016675a35bf0077f50876fc6157a01b4e28aa06d /clippy_lints/src/loops/missing_spin_loop.rs | |
| parent | 8ab744e2d195d3afc61ac9aa0dc9a5a36863437a (diff) | |
Use std_or_core to determine the correct prefix
Replace hand-crafted tests by the a call to the `std_or_core()` utility function.
Diffstat (limited to 'clippy_lints/src/loops/missing_spin_loop.rs')
| -rw-r--r-- | clippy_lints/src/loops/missing_spin_loop.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/clippy_lints/src/loops/missing_spin_loop.rs b/clippy_lints/src/loops/missing_spin_loop.rs index e405829b2f4..a9944d64ce2 100644 --- a/clippy_lints/src/loops/missing_spin_loop.rs +++ b/clippy_lints/src/loops/missing_spin_loop.rs @@ -1,6 +1,6 @@ use super::MISSING_SPIN_LOOP; use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_no_std_crate; +use clippy_utils::std_or_core; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, ExprKind}; use rustc_lint::LateContext; @@ -41,6 +41,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &' && [sym::load, sym::compare_exchange, sym::compare_exchange_weak].contains(&method.ident.name) && let ty::Adt(def, _args) = cx.typeck_results().expr_ty(callee).kind() && cx.tcx.is_diagnostic_item(sym::AtomicBool, def.did()) + && let Some(std_or_core) = std_or_core(cx) { span_lint_and_sugg( cx, @@ -48,12 +49,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &' body.span, "busy-waiting loop should at least have a spin loop hint", "try", - (if is_no_std_crate(cx) { - "{ core::hint::spin_loop() }" - } else { - "{ std::hint::spin_loop() }" - }) - .into(), + format!("{{ {std_or_core}::hint::spin_loop() }}"), Applicability::MachineApplicable, ); } |
