From 5d8c4be0b97e28f4a4d7feaaa3770be3f80bf30b Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 2 Dec 2020 15:16:12 -0800 Subject: [PATCH 1/8] Uplift the `invalid_atomic_ordering` lint from clippy to rustc --- Cargo.lock | 1 + compiler/rustc_lint/Cargo.toml | 1 + compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint/src/types.rs | 219 +++++++++++++++++- compiler/rustc_span/src/symbol.rs | 28 +++ library/core/src/sync/atomic.rs | 18 ++ .../lint/lint-invalid-atomic-ordering-bool.rs | 27 +++ .../lint-invalid-atomic-ordering-bool.stderr | 35 +++ ...t-invalid-atomic-ordering-exchange-weak.rs | 61 +++++ ...valid-atomic-ordering-exchange-weak.stderr | 131 +++++++++++ .../lint-invalid-atomic-ordering-exchange.rs | 59 +++++ ...nt-invalid-atomic-ordering-exchange.stderr | 131 +++++++++++ .../lint-invalid-atomic-ordering-fence.rs | 20 ++ .../lint-invalid-atomic-ordering-fence.stderr | 19 ++ ...nt-invalid-atomic-ordering-fetch-update.rs | 59 +++++ ...nvalid-atomic-ordering-fetch-update.stderr | 131 +++++++++++ .../lint/lint-invalid-atomic-ordering-int.rs | 128 ++++++++++ .../lint-invalid-atomic-ordering-int.stderr | 163 +++++++++++++ .../lint/lint-invalid-atomic-ordering-ptr.rs | 29 +++ .../lint-invalid-atomic-ordering-ptr.stderr | 35 +++ .../lint/lint-invalid-atomic-ordering-uint.rs | 128 ++++++++++ .../lint-invalid-atomic-ordering-uint.stderr | 163 +++++++++++++ src/tools/clippy/clippy_lints/src/lib.rs | 4 + 23 files changed, 1589 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-bool.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-fence.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-int.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-uint.rs create mode 100644 src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr diff --git a/Cargo.lock b/Cargo.lock index 5c096e9f80c30..8cdd5d71a4f94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3831,6 +3831,7 @@ dependencies = [ name = "rustc_lint" version = "0.0.0" dependencies = [ + "if_chain", "rustc_ast", "rustc_ast_pretty", "rustc_attr", diff --git a/compiler/rustc_lint/Cargo.toml b/compiler/rustc_lint/Cargo.toml index c56eb09b63471..1d1c5426f43e0 100644 --- a/compiler/rustc_lint/Cargo.toml +++ b/compiler/rustc_lint/Cargo.toml @@ -5,6 +5,7 @@ version = "0.0.0" edition = "2018" [dependencies] +if_chain = "1.0" tracing = "0.1" unicode-security = "0.0.5" rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 80ef855c3859e..7b9596232f20d 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -169,6 +169,7 @@ macro_rules! late_lint_passes { DropTraitConstraints: DropTraitConstraints, TemporaryCStringAsPtr: TemporaryCStringAsPtr, PanicFmt: PanicFmt, + InvalidAtomicOrdering: InvalidAtomicOrdering, ] ); }; diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 9ad9d53cd0db3..06c135a222723 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -4,18 +4,20 @@ use rustc_attr as attr; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; -use rustc_hir::{is_range_literal, ExprKind, Node}; +use rustc_hir::def_id::DefId; +use rustc_hir::{is_range_literal, Expr, ExprKind, Node}; use rustc_index::vec::Idx; use rustc_middle::ty::layout::{IntegerExt, SizeSkeleton}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_target::abi::Abi; use rustc_target::abi::{Integer, LayoutOf, TagEncoding, VariantIdx, Variants}; use rustc_target::spec::abi::Abi as SpecAbi; +use if_chain::if_chain; use std::cmp; use std::ops::ControlFlow; use tracing::debug; @@ -1358,3 +1360,216 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { } } } + +declare_lint! { + /// The `invalid_atomic_ordering` lint detects using passing an `Ordering` + /// to an atomic operation that does not support that ordering. + /// + /// ### Example + /// + /// ```rust + /// # use core::sync::atomic::{AtomicU8, Ordering}; + /// let atom = AtomicU8::new(0); + /// let value = atom.load(Ordering::Release); + /// # let _ = value; + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Some atomic operations are only supported for a subset of the + /// `atomic::Ordering` variants. Passing an unsupported variant will cause + /// an unconditional panic at runtime, which is detected by this lint. + /// + /// This lint will trigger in the following cases: (where `AtomicType` is an + /// atomic type from `core::sync::atomic`, such as `AtomicBool`, + /// `AtomicPtr`, `AtomicUsize`, or any of the other integer atomics). + /// + /// - Passing `Ordering::Acquire` or `Ordering::AcqRel` to + /// `AtomicType::store`. + /// + /// - Passing `Ordering::Release` or `Ordering::AcqRel` to + /// `AtomicType::load`. + /// + /// - Passing `Ordering::Relaxed` to `core::sync::atomic::fence` or + /// `core::sync::atomic::compiler_fence`. + /// + /// - Passing `Ordering::Release` or `Ordering::AcqRel` as the failure + /// ordering for any of `AtomicType::compare_exchange`, + /// `AtomicType::compare_exchange_weak`, or `AtomicType::fetch_update`. + /// + /// - Passing in a pair of orderings to `AtomicType::compare_exchange`, + /// `AtomicType::compare_exchange_weak`, or `AtomicType::fetch_update` + /// where the failure ordering is stronger than the success ordering. + INVALID_ATOMIC_ORDERING, + Deny, + "usage of invalid atomic ordering in atomic operations and memory fences" +} + +declare_lint_pass!(InvalidAtomicOrdering => [INVALID_ATOMIC_ORDERING]); + +impl InvalidAtomicOrdering { + fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { + const ATOMIC_TYPES: &[Symbol] = &[ + sym::atomic_bool_type, + sym::atomic_ptr_type, + sym::atomic_usize_type, + sym::atomic_u8_type, + sym::atomic_u16_type, + sym::atomic_u32_type, + sym::atomic_u64_type, + sym::atomic_u128_type, + sym::atomic_isize_type, + sym::atomic_i8_type, + sym::atomic_i16_type, + sym::atomic_i32_type, + sym::atomic_i64_type, + sym::atomic_i128_type, + ]; + if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind() { + ATOMIC_TYPES.iter().any(|sym| cx.tcx.is_diagnostic_item(*sym, did)) + } else { + false + } + } + + fn matches_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[Symbol]) -> bool { + orderings.iter().any(|ordering| { + cx.match_def_path(did, &[sym::core, sym::sync, sym::atomic, sym::Ordering, *ordering]) + }) + } + + fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option { + if let ExprKind::Path(ref ord_qpath) = ord_arg.kind { + cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id() + } else { + None + } + } + + fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) { + if_chain! { + if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; + let method = method_path.ident.name; + if Self::type_is_atomic(cx, &args[0]); + if method == sym::load || method == sym::store; + let ordering_arg = if method == sym::load { &args[1] } else { &args[2] }; + if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; + if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); + then { + if method == sym::load && + Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Release, sym::AcqRel]) { + cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| { + diag.build("atomic loads cannot have `Release` or `AcqRel` ordering") + .help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`") + .emit(); + }); + } else if method == sym::store && + Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Acquire, sym::AcqRel]) { + cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| { + diag.build("atomic stores cannot have `Acquire` or `AcqRel` ordering") + .help("consider using ordering modes `Release`, `SeqCst` or `Relaxed`") + .emit(); + }); + } + } + } + } + + fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) { + if_chain! { + if let ExprKind::Call(ref func, ref args) = expr.kind; + if let ExprKind::Path(ref func_qpath) = func.kind; + if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); + if cx.tcx.is_diagnostic_item(sym::fence, def_id) || + cx.tcx.is_diagnostic_item(sym::compiler_fence, def_id); + if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; + if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); + if Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Relaxed]); + then { + cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| { + diag.build("memory fences cannot have `Relaxed` ordering") + .help("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`") + .emit(); + }); + } + } + } + + fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) { + if_chain! { + if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; + let method = method_path.ident.name; + if Self::type_is_atomic(cx, &args[0]); + if method == sym::compare_exchange || method == sym::compare_exchange_weak || method == sym::fetch_update; + let (success_order_arg, failure_order_arg) = if method == sym::fetch_update { + (&args[1], &args[2]) + } else { + (&args[3], &args[4]) + }; + if let Some(fail_ordering_def_id) = Self::opt_ordering_defid(cx, failure_order_arg); + then { + // Helper type holding on to some checking and error reporting data. Has + // - (success ordering, + // - list of failure orderings forbidden by the success order, + // - suggestion message) + type OrdLintInfo = (Symbol, &'static [Symbol], &'static str); + let relaxed: OrdLintInfo = (sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`"); + let acquire: OrdLintInfo = (sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`"); + let seq_cst: OrdLintInfo = (sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); + let release = (sym::Release, relaxed.1, relaxed.2); + let acqrel = (sym::AcqRel, acquire.1, acquire.2); + let search = [relaxed, acquire, seq_cst, release, acqrel]; + + let success_lint_info = Self::opt_ordering_defid(cx, success_order_arg) + .and_then(|success_ord_def_id| -> Option { + search + .iter() + .find(|(ordering, ..)| { + cx.match_def_path( + success_ord_def_id, + &[sym::core, sym::sync, sym::atomic, sym::Ordering, *ordering], + ) + }) + .copied() + }); + if Self::matches_ordering_def_path(cx, fail_ordering_def_id, &[sym::Release, sym::AcqRel]) { + // If we don't know the success order is, use what we'd suggest + // if it were maximally permissive. + let suggested = success_lint_info.unwrap_or(seq_cst).2; + cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| { + let msg = format!( + "{}'s failure ordering may not be `Release` or `AcqRel`", + method, + ); + diag.build(&msg) + .help(&format!("consider using {} instead", suggested)) + .emit(); + }); + } else if let Some((success_ord, bad_ords_given_success, suggested)) = success_lint_info { + if Self::matches_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) { + cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| { + let msg = format!( + "{}'s failure ordering may not be stronger than the success ordering of `{}`", + method, + success_ord, + ); + diag.build(&msg) + .help(&format!("consider using {} instead", suggested)) + .emit(); + }); + } + } + } + } + } +} + +impl<'tcx> LateLintPass<'tcx> for InvalidAtomicOrdering { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { + Self::check_atomic_load_store(cx, expr); + Self::check_memory_fence(cx, expr); + Self::check_atomic_compare_exchange(cx, expr); + } +} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e75ddb36ff876..0d1f7e69d33c5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -121,6 +121,8 @@ symbols! { // There is currently no checking that all symbols are used; that would be // nice to have. Symbols { + AcqRel, + Acquire, Alignment, Arc, Argument, @@ -185,12 +187,15 @@ symbols! { RangeToInclusive, Rc, Ready, + Relaxed, + Release, Result, Return, Right, RustcDecodable, RustcEncodable, Send, + SeqCst, Some, StructuralEq, StructuralPartialEq, @@ -279,6 +284,21 @@ symbols! { assume_init, async_await, async_closure, + atomic, + atomic_bool_type, + atomic_i128_type, + atomic_i16_type, + atomic_i32_type, + atomic_i64_type, + atomic_i8_type, + atomic_isize_type, + atomic_ptr_type, + atomic_u128_type, + atomic_u16_type, + atomic_u32_type, + atomic_u64_type, + atomic_u8_type, + atomic_usize_type, atomics, att_syntax, attr, @@ -350,8 +370,12 @@ symbols! { coerce_unsized, cold, column, + compare_and_swap, + compare_exchange, + compare_exchange_weak, compile_error, compiler_builtins, + compiler_fence, concat, concat_idents, conservative_impl_trait, @@ -514,6 +538,8 @@ symbols! { fadd_fast, fdiv_fast, feature, + fence, + fetch_update, ffi, ffi_const, ffi_pure, @@ -651,6 +677,7 @@ symbols! { lint_reasons, literal, llvm_asm, + load, local_inner_macros, log10f32, log10f64, @@ -1074,6 +1101,7 @@ symbols! { stmt, stmt_expr_attributes, stop_after_dataflow, + store, str, str_alloc, string_type, diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 9d2045990570b..b37e8bcdc75d1 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -143,6 +143,7 @@ pub fn spin_loop_hint() { /// loads and stores of `u8`. #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_diagnostic_item = "atomic_bool_type"] #[repr(C, align(1))] pub struct AtomicBool { v: UnsafeCell, @@ -174,6 +175,7 @@ unsafe impl Sync for AtomicBool {} #[cfg_attr(target_pointer_width = "16", repr(C, align(2)))] #[cfg_attr(target_pointer_width = "32", repr(C, align(4)))] #[cfg_attr(target_pointer_width = "64", repr(C, align(8)))] +#[rustc_diagnostic_item = "atomic_ptr_type"] pub struct AtomicPtr { p: UnsafeCell<*mut T>, } @@ -1295,6 +1297,7 @@ macro_rules! atomic_int { $stable_nand:meta, $const_stable:meta, $stable_init_const:meta, + $diag_item_name:expr, $s_int_type:literal, $int_ref:expr, $extra_feature:expr, $min_fn:ident, $max_fn:ident, @@ -1321,6 +1324,7 @@ macro_rules! atomic_int { /// /// [module-level documentation]: crate::sync::atomic #[$stable] + #[rustc_diagnostic_item = $diag_item_name] #[repr(C, align($align))] pub struct $atomic_type { v: UnsafeCell<$int_type>, @@ -2097,6 +2101,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_i8_type", "i8", "../../../std/primitive.i8.html", "", atomic_min, atomic_max, @@ -2116,6 +2121,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_u8_type", "u8", "../../../std/primitive.u8.html", "", atomic_umin, atomic_umax, @@ -2135,6 +2141,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_i16_type", "i16", "../../../std/primitive.i16.html", "", atomic_min, atomic_max, @@ -2154,6 +2161,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_u16_type", "u16", "../../../std/primitive.u16.html", "", atomic_umin, atomic_umax, @@ -2173,6 +2181,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_i32_type", "i32", "../../../std/primitive.i32.html", "", atomic_min, atomic_max, @@ -2192,6 +2201,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_u32_type", "u32", "../../../std/primitive.u32.html", "", atomic_umin, atomic_umax, @@ -2211,6 +2221,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_i64_type", "i64", "../../../std/primitive.i64.html", "", atomic_min, atomic_max, @@ -2230,6 +2241,7 @@ atomic_int! { stable(feature = "integer_atomics_stable", since = "1.34.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_u64_type", "u64", "../../../std/primitive.u64.html", "", atomic_umin, atomic_umax, @@ -2249,6 +2261,7 @@ atomic_int! { unstable(feature = "integer_atomics", issue = "32976"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_i128_type", "i128", "../../../std/primitive.i128.html", "#![feature(integer_atomics)]\n\n", atomic_min, atomic_max, @@ -2268,6 +2281,7 @@ atomic_int! { unstable(feature = "integer_atomics", issue = "32976"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), unstable(feature = "integer_atomics", issue = "32976"), + "atomic_u128_type", "u128", "../../../std/primitive.u128.html", "#![feature(integer_atomics)]\n\n", atomic_umin, atomic_umax, @@ -2291,6 +2305,7 @@ macro_rules! atomic_int_ptr_sized { stable(feature = "atomic_nand", since = "1.27.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), stable(feature = "rust1", since = "1.0.0"), + "atomic_isize_type", "isize", "../../../std/primitive.isize.html", "", atomic_min, atomic_max, @@ -2311,6 +2326,7 @@ macro_rules! atomic_int_ptr_sized { stable(feature = "atomic_nand", since = "1.27.0"), rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), stable(feature = "rust1", since = "1.0.0"), + "atomic_usize_type", "usize", "../../../std/primitive.usize.html", "", atomic_umin, atomic_umax, @@ -2668,6 +2684,7 @@ unsafe fn atomic_umin(dst: *mut T, val: T, order: Ordering) -> T { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_diagnostic_item = "fence"] pub fn fence(order: Ordering) { // SAFETY: using an atomic fence is safe. unsafe { @@ -2749,6 +2766,7 @@ pub fn fence(order: Ordering) { /// [memory barriers]: https://www.kernel.org/doc/Documentation/memory-barriers.txt #[inline] #[stable(feature = "compiler_fences", since = "1.21.0")] +#[rustc_diagnostic_item = "compiler_fence"] pub fn compiler_fence(order: Ordering) { // SAFETY: using an atomic fence is safe. unsafe { diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-bool.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.rs new file mode 100644 index 0000000000000..52f28e09cf5ed --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.rs @@ -0,0 +1,27 @@ +use std::sync::atomic::{AtomicBool, Ordering}; + +fn main() { + let x = AtomicBool::new(true); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Allowed store ordering modes + x.store(false, Ordering::Release); + x.store(false, Ordering::SeqCst); + x.store(false, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(false, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(false, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr new file mode 100644 index 0000000000000..bc0512dd7c835 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr @@ -0,0 +1,35 @@ +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-bool.rs:12:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-bool.rs:14:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-bool.rs:23:20 + | +LL | x.store(false, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-bool.rs:25:20 + | +LL | x.store(false, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs new file mode 100644 index 0000000000000..734e3b1529100 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs @@ -0,0 +1,61 @@ +use std::sync::atomic::{AtomicPtr, Ordering}; + +fn main() { + let ptr = &mut 5; + let ptr2 = &mut 10; + // `compare_exchange_weak` testing + let x = AtomicPtr::new(ptr); + + // Allowed ordering combos + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Relaxed); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Acquire); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Relaxed); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Relaxed); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Acquire); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Relaxed); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Relaxed); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Acquire); + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::SeqCst); + + // AcqRel is always forbidden as a failure ordering + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + + // Release is always forbidden as a failure ordering + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); + //~^ ERROR compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + + // Release success order forbids failure order of Acquire or SeqCst + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + + // Relaxed success order also forbids failure order of Acquire or SeqCst + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + + // Acquire/AcqRel forbids failure order of SeqCst + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Acquire` + let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `AcqRel` +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr new file mode 100644 index 0000000000000..a576e21cb352a --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr @@ -0,0 +1,131 @@ +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:21:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:23:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:25:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:27:66 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:29:66 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:33:67 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:35:67 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:37:67 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:39:66 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:41:66 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:45:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:47:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:51:67 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:53:67 + | +LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Acquire` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:57:67 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:59:66 + | +LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: aborting due to 16 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs new file mode 100644 index 0000000000000..d81477067614d --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs @@ -0,0 +1,59 @@ +use std::sync::atomic::{AtomicUsize, Ordering}; + +fn main() { + // `compare_exchange` (not weak) testing + let x = AtomicUsize::new(0); + + // Allowed ordering combos + let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Relaxed); + let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Acquire); + let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Relaxed); + let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Relaxed); + let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Acquire); + let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Relaxed); + let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Relaxed); + let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Acquire); + let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::SeqCst); + + // AcqRel is always forbidden as a failure ordering + let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + + // Release is always forbidden as a failure ordering + let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); + //~^ ERROR compare_exchange's failure ordering may not be `Release` or `AcqRel` + + // Release success order forbids failure order of Acquire or SeqCst + let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + + // Relaxed success order also forbids failure order of Acquire or SeqCst + let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + + // Acquire/AcqRel forbids failure order of SeqCst + let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Acquire` + let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); + //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `AcqRel` +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr new file mode 100644 index 0000000000000..551cb5839eadc --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr @@ -0,0 +1,131 @@ +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:19:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:21:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:23:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:25:56 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:27:56 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:31:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:33:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:35:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:37:56 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:39:56 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:43:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:45:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:49:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:51:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `Acquire` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:55:57 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: compare_exchange's failure ordering may not be stronger than the success ordering of `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-exchange.rs:57:56 + | +LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: aborting due to 16 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fence.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.rs new file mode 100644 index 0000000000000..fef97626057fa --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.rs @@ -0,0 +1,20 @@ +use std::sync::atomic::{compiler_fence, fence, Ordering}; + +fn main() { + // Allowed ordering modes + fence(Ordering::Acquire); + fence(Ordering::Release); + fence(Ordering::AcqRel); + fence(Ordering::SeqCst); + + compiler_fence(Ordering::Acquire); + compiler_fence(Ordering::Release); + compiler_fence(Ordering::AcqRel); + compiler_fence(Ordering::SeqCst); + + // Disallowed ordering modes + fence(Ordering::Relaxed); + //~^ ERROR memory fences cannot have `Relaxed` ordering + compiler_fence(Ordering::Relaxed); + //~^ ERROR memory fences cannot have `Relaxed` ordering +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr new file mode 100644 index 0000000000000..6ca864a41c8e7 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr @@ -0,0 +1,19 @@ +error: memory fences cannot have `Relaxed` ordering + --> $DIR/lint-invalid-atomic-ordering-fence.rs:16:11 + | +LL | fence(Ordering::Relaxed); + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` + +error: memory fences cannot have `Relaxed` ordering + --> $DIR/lint-invalid-atomic-ordering-fence.rs:18:20 + | +LL | compiler_fence(Ordering::Relaxed); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs new file mode 100644 index 0000000000000..d9c4ba863043e --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs @@ -0,0 +1,59 @@ +use std::sync::atomic::{AtomicIsize, Ordering}; + +fn main() { + // `fetch_update` testing + let x = AtomicIsize::new(0); + + // Allowed ordering combos + let _ = x.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::Acquire, Ordering::Acquire, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::Acquire, Ordering::Relaxed, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::Release, Ordering::Relaxed, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::AcqRel, Ordering::Acquire, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::AcqRel, Ordering::Relaxed, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::SeqCst, Ordering::Acquire, |old| Some(old + 1)); + let _ = x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |old| Some(old + 1)); + + // AcqRel is always forbidden as a failure ordering + let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + + // Release is always forbidden as a failure ordering + let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be `Release` or `AcqRel` + + // Release success order forbids failure order of Acquire or SeqCst + let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Release` + let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Release` + + // Relaxed success order also forbids failure order of Acquire or SeqCst + let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + + // Acquire/AcqRel forbids failure order of SeqCst + let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Acquire` + let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); + //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `AcqRel` +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr new file mode 100644 index 0000000000000..d151abe948419 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr @@ -0,0 +1,131 @@ +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:19:47 + | +LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:21:47 + | +LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:23:47 + | +LL | let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:25:46 + | +LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:27:46 + | +LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:31:47 + | +LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:33:47 + | +LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:35:47 + | +LL | let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:37:46 + | +LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: fetch_update's failure ordering may not be `Release` or `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:39:46 + | +LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:43:47 + | +LL | let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:45:47 + | +LL | let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:49:47 + | +LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:51:47 + | +LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering mode `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `Acquire` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:55:47 + | +LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: fetch_update's failure ordering may not be stronger than the success ordering of `AcqRel` + --> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:57:46 + | +LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire` or `Relaxed` instead + +error: aborting due to 16 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-int.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-int.rs new file mode 100644 index 0000000000000..8814922015674 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-int.rs @@ -0,0 +1,128 @@ +use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering}; + +fn main() { + // `AtomicI8` test cases + let x = AtomicI8::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicI16` test cases + let x = AtomicI16::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicI32` test cases + let x = AtomicI32::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicI64` test cases + let x = AtomicI64::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicIsize` test cases + let x = AtomicIsize::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr new file mode 100644 index 0000000000000..fd29c3c753c64 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr @@ -0,0 +1,163 @@ +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:18:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:20:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:24:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:26:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:43:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:45:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:49:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:51:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:68:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:70:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:74:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:76:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:93:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:95:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:99:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:101:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:118:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:120:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:124:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-int.rs:126:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 20 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs new file mode 100644 index 0000000000000..da9a7b77b9202 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs @@ -0,0 +1,29 @@ +use std::sync::atomic::{AtomicPtr, Ordering}; + +fn main() { + let ptr = &mut 5; + let other_ptr = &mut 10; + let x = AtomicPtr::new(ptr); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Allowed store ordering modes + x.store(other_ptr, Ordering::Release); + x.store(other_ptr, Ordering::SeqCst); + x.store(other_ptr, Ordering::Relaxed); + + // Disallowed store ordering modes + x.store(other_ptr, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(other_ptr, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr new file mode 100644 index 0000000000000..513343687804f --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr @@ -0,0 +1,35 @@ +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-ptr.rs:14:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-ptr.rs:16:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-ptr.rs:25:24 + | +LL | x.store(other_ptr, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-ptr.rs:27:24 + | +LL | x.store(other_ptr, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-uint.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.rs new file mode 100644 index 0000000000000..e4dce35715654 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.rs @@ -0,0 +1,128 @@ +use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}; + +fn main() { + // `AtomicU8` test cases + let x = AtomicU8::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicU16` test cases + let x = AtomicU16::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicU32` test cases + let x = AtomicU32::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicU64` test cases + let x = AtomicU64::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + + // `AtomicUsize` test cases + let x = AtomicUsize::new(0); + + // Allowed load ordering modes + let _ = x.load(Ordering::Acquire); + let _ = x.load(Ordering::SeqCst); + let _ = x.load(Ordering::Relaxed); + + // Allowed store ordering modes + x.store(1, Ordering::Release); + x.store(1, Ordering::SeqCst); + x.store(1, Ordering::Relaxed); + + // Disallowed load ordering modes + let _ = x.load(Ordering::Release); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + let _ = x.load(Ordering::AcqRel); + //~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering + + // Disallowed store ordering modes + x.store(1, Ordering::Acquire); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering + x.store(1, Ordering::AcqRel); + //~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering +} diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr new file mode 100644 index 0000000000000..e977538233c37 --- /dev/null +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr @@ -0,0 +1,163 @@ +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:18:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[deny(invalid_atomic_ordering)]` on by default + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:20:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:24:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:26:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:43:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:45:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:49:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:51:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:68:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:70:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:74:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:76:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:93:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:95:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:99:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:101:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:118:20 + | +LL | let _ = x.load(Ordering::Release); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic loads cannot have `Release` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:120:20 + | +LL | let _ = x.load(Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:124:16 + | +LL | x.store(1, Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: atomic stores cannot have `Acquire` or `AcqRel` ordering + --> $DIR/lint-invalid-atomic-ordering-uint.rs:126:16 + | +LL | x.store(1, Ordering::AcqRel); + | ^^^^^^^^^^^^^^^^ + | + = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` + +error: aborting due to 20 previous errors + diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 2b99ed570b148..ed3916ac4c386 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -496,6 +496,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: "clippy::panic_params", "this lint has been uplifted to rustc and is now called `panic_fmt`", ); + store.register_removed( + "clippy::invalid_atomic_ordering", + "this lint has been uplifted to rustc and is now called `invalid_atomic_ordering`", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` From 5d59e7ab3ae2c967cb74983a0ec5a63c34b69107 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 2 Dec 2020 18:54:03 -0800 Subject: [PATCH 2/8] Truncate overlong error lines for tidy's sake --- .../lint-invalid-atomic-ordering-exchange-weak.rs | 12 ++++++------ .../ui/lint/lint-invalid-atomic-ordering-exchange.rs | 12 ++++++------ .../lint-invalid-atomic-ordering-fetch-update.rs | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs index 734e3b1529100..d50294e82f349 100644 --- a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs @@ -43,19 +43,19 @@ fn main() { // Release success order forbids failure order of Acquire or SeqCst let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger // Relaxed success order also forbids failure order of Acquire or SeqCst let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger // Acquire/AcqRel forbids failure order of SeqCst let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Acquire` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); - //~^ ERROR compare_exchange_weak's failure ordering may not be stronger than the success ordering of `AcqRel` + //~^ ERROR compare_exchange_weak's failure ordering may not be stronger } diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs index d81477067614d..95d58335125a7 100644 --- a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.rs @@ -41,19 +41,19 @@ fn main() { // Release success order forbids failure order of Acquire or SeqCst let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR compare_exchange's failure ordering may not be stronger let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR compare_exchange's failure ordering may not be stronger // Relaxed success order also forbids failure order of Acquire or SeqCst let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR compare_exchange's failure ordering may not be stronger let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR compare_exchange's failure ordering may not be stronger // Acquire/AcqRel forbids failure order of SeqCst let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `Acquire` + //~^ ERROR compare_exchange's failure ordering may not be stronger let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); - //~^ ERROR compare_exchange's failure ordering may not be stronger than the success ordering of `AcqRel` + //~^ ERROR compare_exchange's failure ordering may not be stronger } diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs index d9c4ba863043e..c8afc7fd3b231 100644 --- a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs +++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs @@ -41,19 +41,19 @@ fn main() { // Release success order forbids failure order of Acquire or SeqCst let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR fetch_update's failure ordering may not be stronger let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Release` + //~^ ERROR fetch_update's failure ordering may not be stronger // Relaxed success order also forbids failure order of Acquire or SeqCst let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR fetch_update's failure ordering may not be stronger let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` + //~^ ERROR fetch_update's failure ordering may not be stronger // Acquire/AcqRel forbids failure order of SeqCst let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `Acquire` + //~^ ERROR fetch_update's failure ordering may not be stronger let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); - //~^ ERROR fetch_update's failure ordering may not be stronger than the success ordering of `AcqRel` + //~^ ERROR fetch_update's failure ordering may not be stronger } From 4a9aaa0821276d534abc3976cb0716be1a2c837e Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 2 Dec 2020 19:27:02 -0800 Subject: [PATCH 3/8] Mark failing lint example as compile_fail --- compiler/rustc_lint/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 06c135a222723..cf81384f37208 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1367,7 +1367,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,compile_fail /// # use core::sync::atomic::{AtomicU8, Ordering}; /// let atom = AtomicU8::new(0); /// let value = atom.load(Ordering::Release); From e517634a753057606f3b70cd287955bcc7d0fe2f Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 3 Dec 2020 01:52:28 -0800 Subject: [PATCH 4/8] Undo the change that incorrectly deprecated the clippy lint --- src/tools/clippy/clippy_lints/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index ed3916ac4c386..2b99ed570b148 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -496,10 +496,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: "clippy::panic_params", "this lint has been uplifted to rustc and is now called `panic_fmt`", ); - store.register_removed( - "clippy::invalid_atomic_ordering", - "this lint has been uplifted to rustc and is now called `invalid_atomic_ordering`", - ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` From ace2c5d97b288ca6075fd38d1660f87888b21b47 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 3 Dec 2020 07:51:32 -0800 Subject: [PATCH 5/8] ignore rustc's invalid_atomic_ordering lint in the clippy lint tests for now --- src/tools/clippy/tests/ui/atomic_ordering_bool.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_exchange.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_fence.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_int.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_ptr.rs | 2 +- src/tools/clippy/tests/ui/atomic_ordering_uint.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/clippy/tests/ui/atomic_ordering_bool.rs b/src/tools/clippy/tests/ui/atomic_ordering_bool.rs index cdbde79b19ebf..9f6b0e497f481 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_bool.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_bool.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicBool, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs b/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs index 1ddc12f9ab213..92cd4c5223d03 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicUsize, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs b/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs index 5906990250728..bcce9496a8069 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicPtr, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fence.rs b/src/tools/clippy/tests/ui/atomic_ordering_fence.rs index 5ee5182ca051a..ba2e4bfd280e3 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_fence.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_fence.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{compiler_fence, fence, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs b/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs index 550bdb001e4cd..d2f95b261242d 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicIsize, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_int.rs b/src/tools/clippy/tests/ui/atomic_ordering_int.rs index 40a00ba3de350..2778099e0bc56 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_int.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_int.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs b/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs index ecbb05c7fbc39..0c26f65c589e6 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicPtr, Ordering}; fn main() { diff --git a/src/tools/clippy/tests/ui/atomic_ordering_uint.rs b/src/tools/clippy/tests/ui/atomic_ordering_uint.rs index a0d5d7c401035..c57b3cb9c4284 100644 --- a/src/tools/clippy/tests/ui/atomic_ordering_uint.rs +++ b/src/tools/clippy/tests/ui/atomic_ordering_uint.rs @@ -1,5 +1,5 @@ #![warn(clippy::invalid_atomic_ordering)] - +#![allow(invalid_atomic_ordering)] use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}; fn main() { From ee38c8972f0bdb5aa95503ac74fcb48c3772e4cb Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 9 Dec 2020 04:04:31 -0800 Subject: [PATCH 6/8] Deprecate clippy::invalid_atomic_ordering --- .../clippy_lints/src/atomic_ordering.rs | 229 ------------------ .../clippy_lints/src/deprecated_lints.rs | 9 + src/tools/clippy/clippy_lints/src/lib.rs | 9 +- .../clippy/tests/ui/atomic_ordering_bool.rs | 25 -- .../tests/ui/atomic_ordering_bool.stderr | 35 --- .../tests/ui/atomic_ordering_exchange.rs | 45 ---- .../tests/ui/atomic_ordering_exchange.stderr | 131 ---------- .../tests/ui/atomic_ordering_exchange_weak.rs | 47 ---- .../ui/atomic_ordering_exchange_weak.stderr | 131 ---------- .../clippy/tests/ui/atomic_ordering_fence.rs | 20 -- .../tests/ui/atomic_ordering_fence.stderr | 19 -- .../tests/ui/atomic_ordering_fetch_update.rs | 45 ---- .../ui/atomic_ordering_fetch_update.stderr | 131 ---------- .../clippy/tests/ui/atomic_ordering_int.rs | 86 ------- .../tests/ui/atomic_ordering_int.stderr | 163 ------------- .../clippy/tests/ui/atomic_ordering_ptr.rs | 27 --- .../tests/ui/atomic_ordering_ptr.stderr | 35 --- .../clippy/tests/ui/atomic_ordering_uint.rs | 86 ------- .../tests/ui/atomic_ordering_uint.stderr | 163 ------------- src/tools/clippy/tests/ui/deprecated.rs | 1 + src/tools/clippy/tests/ui/deprecated.stderr | 8 +- 21 files changed, 21 insertions(+), 1424 deletions(-) delete mode 100644 src/tools/clippy/clippy_lints/src/atomic_ordering.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_bool.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_bool.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_exchange.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_exchange.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_fence.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_fence.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_fetch_update.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_int.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_int.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_ptr.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_ptr.stderr delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_uint.rs delete mode 100644 src/tools/clippy/tests/ui/atomic_ordering_uint.stderr diff --git a/src/tools/clippy/clippy_lints/src/atomic_ordering.rs b/src/tools/clippy/clippy_lints/src/atomic_ordering.rs deleted file mode 100644 index 703d8a6f62bb1..0000000000000 --- a/src/tools/clippy/clippy_lints/src/atomic_ordering.rs +++ /dev/null @@ -1,229 +0,0 @@ -use crate::utils::{match_def_path, span_lint_and_help}; -use if_chain::if_chain; -use rustc_hir::def_id::DefId; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty; -use rustc_session::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for usage of invalid atomic - /// ordering in atomic loads/stores/exchanges/updates and - /// memory fences. - /// - /// **Why is this bad?** Using an invalid atomic ordering - /// will cause a panic at run-time. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```rust,no_run - /// # use std::sync::atomic::{self, AtomicU8, Ordering}; - /// - /// let x = AtomicU8::new(0); - /// - /// // Bad: `Release` and `AcqRel` cannot be used for `load`. - /// let _ = x.load(Ordering::Release); - /// let _ = x.load(Ordering::AcqRel); - /// - /// // Bad: `Acquire` and `AcqRel` cannot be used for `store`. - /// x.store(1, Ordering::Acquire); - /// x.store(2, Ordering::AcqRel); - /// - /// // Bad: `Relaxed` cannot be used as a fence's ordering. - /// atomic::fence(Ordering::Relaxed); - /// atomic::compiler_fence(Ordering::Relaxed); - /// - /// // Bad: `Release` and `AcqRel` are both always invalid - /// // for the failure ordering (the last arg). - /// let _ = x.compare_exchange(1, 2, Ordering::SeqCst, Ordering::Release); - /// let _ = x.compare_exchange_weak(2, 3, Ordering::AcqRel, Ordering::AcqRel); - /// - /// // Bad: The failure ordering is not allowed to be - /// // stronger than the success order, and `SeqCst` is - /// // stronger than `Relaxed`. - /// let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |val| Some(val + val)); - /// ``` - pub INVALID_ATOMIC_ORDERING, - correctness, - "usage of invalid atomic ordering in atomic operations and memory fences" -} - -declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]); - -const ATOMIC_TYPES: [&str; 12] = [ - "AtomicBool", - "AtomicI8", - "AtomicI16", - "AtomicI32", - "AtomicI64", - "AtomicIsize", - "AtomicPtr", - "AtomicU8", - "AtomicU16", - "AtomicU32", - "AtomicU64", - "AtomicUsize", -]; - -fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.typeck_results().expr_ty(expr).kind() { - ATOMIC_TYPES - .iter() - .any(|ty| match_def_path(cx, did, &["core", "sync", "atomic", ty])) - } else { - false - } -} - -fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str]) -> bool { - orderings - .iter() - .any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering])) -} - -fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "load" || method == "store"; - let ordering_arg = if method == "load" { &args[1] } else { &args[2] }; - if let ExprKind::Path(ref ordering_qpath) = ordering_arg.kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); - then { - if method == "load" && - match_ordering_def_path(cx, ordering_def_id, &["Release", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic loads cannot have `Release` and `AcqRel` ordering", - None, - "consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`" - ); - } else if method == "store" && - match_ordering_def_path(cx, ordering_def_id, &["Acquire", "AcqRel"]) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - ordering_arg.span, - "atomic stores cannot have `Acquire` and `AcqRel` ordering", - None, - "consider using ordering modes `Release`, `SeqCst` or `Relaxed`" - ); - } - } - } -} - -fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::Call(ref func, ref args) = expr.kind; - if let ExprKind::Path(ref func_qpath) = func.kind; - if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id(); - if ["fence", "compiler_fence"] - .iter() - .any(|func| match_def_path(cx, def_id, &["core", "sync", "atomic", func])); - if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; - if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); - if match_ordering_def_path(cx, ordering_def_id, &["Relaxed"]); - then { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - args[0].span, - "memory fences cannot have `Relaxed` ordering", - None, - "consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`" - ); - } - } -} - -fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option { - if let ExprKind::Path(ref ord_qpath) = ord_arg.kind { - cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id() - } else { - None - } -} - -fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) { - if_chain! { - if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind; - let method = method_path.ident.name.as_str(); - if type_is_atomic(cx, &args[0]); - if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update"; - let (success_order_arg, failure_order_arg) = if method == "fetch_update" { - (&args[1], &args[2]) - } else { - (&args[3], &args[4]) - }; - if let Some(fail_ordering_def_id) = opt_ordering_defid(cx, failure_order_arg); - then { - // Helper type holding on to some checking and error reporting data. Has - // - (success ordering name, - // - list of failure orderings forbidden by the success order, - // - suggestion message) - type OrdLintInfo = (&'static str, &'static [&'static str], &'static str); - let relaxed: OrdLintInfo = ("Relaxed", &["SeqCst", "Acquire"], "ordering mode `Relaxed`"); - let acquire: OrdLintInfo = ("Acquire", &["SeqCst"], "ordering modes `Acquire` or `Relaxed`"); - let seq_cst: OrdLintInfo = ("SeqCst", &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); - let release = ("Release", relaxed.1, relaxed.2); - let acqrel = ("AcqRel", acquire.1, acquire.2); - let search = [relaxed, acquire, seq_cst, release, acqrel]; - - let success_lint_info = opt_ordering_defid(cx, success_order_arg) - .and_then(|success_ord_def_id| -> Option { - search - .iter() - .find(|(ordering, ..)| { - match_def_path(cx, success_ord_def_id, - &["core", "sync", "atomic", "Ordering", ordering]) - }) - .copied() - }); - - if match_ordering_def_path(cx, fail_ordering_def_id, &["Release", "AcqRel"]) { - // If we don't know the success order is, use what we'd suggest - // if it were maximally permissive. - let suggested = success_lint_info.unwrap_or(seq_cst).2; - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be `Release` or `AcqRel`", - method, - ), - None, - &format!("consider using {} instead", suggested), - ); - } else if let Some((success_ord_name, bad_ords_given_success, suggested)) = success_lint_info { - if match_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) { - span_lint_and_help( - cx, - INVALID_ATOMIC_ORDERING, - failure_order_arg.span, - &format!( - "{}'s failure ordering may not be stronger than the success ordering of `{}`", - method, - success_ord_name, - ), - None, - &format!("consider using {} instead", suggested), - ); - } - } - } - } -} - -impl<'tcx> LateLintPass<'tcx> for AtomicOrdering { - fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - check_atomic_load_store(cx, expr); - check_memory_fence(cx, expr); - check_atomic_compare_exchange(cx, expr); - } -} diff --git a/src/tools/clippy/clippy_lints/src/deprecated_lints.rs b/src/tools/clippy/clippy_lints/src/deprecated_lints.rs index bec0c9f93a0d2..f554f1d6d60f8 100644 --- a/src/tools/clippy/clippy_lints/src/deprecated_lints.rs +++ b/src/tools/clippy/clippy_lints/src/deprecated_lints.rs @@ -166,3 +166,12 @@ declare_deprecated_lint! { pub PANIC_PARAMS, "this lint has been uplifted to rustc and is now called `panic_fmt`" } + +declare_deprecated_lint! { + /// **What it does:** Nothing. This lint has been deprecated. + /// + /// **Deprecation reason:** This lint has been uplifted to rustc and is now called + /// `invalid_atomic_ordering`. + pub INVALID_ATOMIC_ORDERING, + "this lint has been uplifted to rustc and is now called `invalid_atomic_ordering`" +} diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 2b99ed570b148..9e58be95807ca 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -160,7 +160,6 @@ mod asm_syntax; mod assertions_on_constants; mod assign_ops; mod async_yields_async; -mod atomic_ordering; mod attrs; mod await_holding_invalid; mod bit_mask; @@ -496,6 +495,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: "clippy::panic_params", "this lint has been uplifted to rustc and is now called `panic_fmt`", ); + store.register_removed( + "clippy::invalid_atomic_ordering", + "this lint has been uplifted to rustc and is now called `invalid_atomic_ordering`", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` // begin register lints, do not remove this comment, it’s used in `update_lints` @@ -528,7 +531,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &assign_ops::ASSIGN_OP_PATTERN, &assign_ops::MISREFACTORED_ASSIGN_OP, &async_yields_async::ASYNC_YIELDS_ASYNC, - &atomic_ordering::INVALID_ATOMIC_ORDERING, &attrs::BLANKET_CLIPPY_RESTRICTION_LINTS, &attrs::DEPRECATED_CFG_ATTR, &attrs::DEPRECATED_SEMVER, @@ -1156,7 +1158,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic); store.register_early_pass(|| box as_conversions::AsConversions); store.register_late_pass(|| box let_underscore::LetUnderscore); - store.register_late_pass(|| box atomic_ordering::AtomicOrdering); store.register_early_pass(|| box single_component_path_imports::SingleComponentPathImports); let max_fn_params_bools = conf.max_fn_params_bools; let max_struct_bools = conf.max_struct_bools; @@ -1351,7 +1352,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&assign_ops::ASSIGN_OP_PATTERN), LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP), LintId::of(&async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS), LintId::of(&attrs::DEPRECATED_CFG_ATTR), LintId::of(&attrs::DEPRECATED_SEMVER), @@ -1823,7 +1823,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_group(true, "clippy::correctness", Some("clippy_correctness"), vec![ LintId::of(&approx_const::APPROX_CONSTANT), LintId::of(&async_yields_async::ASYNC_YIELDS_ASYNC), - LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING), LintId::of(&attrs::DEPRECATED_SEMVER), LintId::of(&attrs::MISMATCHED_TARGET_OS), LintId::of(&attrs::USELESS_ATTRIBUTE), diff --git a/src/tools/clippy/tests/ui/atomic_ordering_bool.rs b/src/tools/clippy/tests/ui/atomic_ordering_bool.rs deleted file mode 100644 index 9f6b0e497f481..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_bool.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicBool, Ordering}; - -fn main() { - let x = AtomicBool::new(true); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(false, Ordering::Release); - x.store(false, Ordering::SeqCst); - x.store(false, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(false, Ordering::Acquire); - x.store(false, Ordering::AcqRel); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_bool.stderr b/src/tools/clippy/tests/ui/atomic_ordering_bool.stderr deleted file mode 100644 index 397b893aed964..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_bool.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:14:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:15:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:23:20 - | -LL | x.store(false, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_bool.rs:24:20 - | -LL | x.store(false, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 4 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs b/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs deleted file mode 100644 index 92cd4c5223d03..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicUsize, Ordering}; - -fn main() { - // `compare_exchange` (not weak) testing - let x = AtomicUsize::new(0); - - // Allowed ordering combos - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Relaxed); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::SeqCst); - - // AcqRel is always forbidden as a failure ordering - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); - - // Release is always forbidden as a failure ordering - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); - let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); - let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); - let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); - let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange.stderr b/src/tools/clippy/tests/ui/atomic_ordering_exchange.stderr deleted file mode 100644 index 4b9bfef79748c..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:21:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:22:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:23:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:24:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:25:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:28:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:29:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:30:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:31:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:32:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::SeqCst, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange.rs:35:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange.rs:36:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange.rs:39:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange.rs:40:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_exchange.rs:43:57 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_exchange.rs:44:56 - | -LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs b/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs deleted file mode 100644 index bcce9496a8069..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.rs +++ /dev/null @@ -1,47 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicPtr, Ordering}; - -fn main() { - let ptr = &mut 5; - let ptr2 = &mut 10; - // `compare_exchange_weak` testing - let x = AtomicPtr::new(ptr); - - // Allowed ordering combos - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Relaxed); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::SeqCst); - - // AcqRel is always forbidden as a failure ordering - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); - - // Release is always forbidden as a failure ordering - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); - let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); - let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.stderr b/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.stderr deleted file mode 100644 index de7026f3ffafa..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_exchange_weak.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:23:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:24:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:25:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:26:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:27:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:30:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:31:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:32:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:33:66 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:34:66 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange_weak.rs:37:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_exchange_weak.rs:38:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange_weak.rs:41:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_exchange_weak.rs:42:67 - | -LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_exchange_weak.rs:45:67 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: compare_exchange_weak's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_exchange_weak.rs:46:66 - | -LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fence.rs b/src/tools/clippy/tests/ui/atomic_ordering_fence.rs deleted file mode 100644 index ba2e4bfd280e3..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_fence.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{compiler_fence, fence, Ordering}; - -fn main() { - // Allowed fence ordering modes - fence(Ordering::Acquire); - fence(Ordering::Release); - fence(Ordering::AcqRel); - fence(Ordering::SeqCst); - - // Disallowed fence ordering modes - fence(Ordering::Relaxed); - - compiler_fence(Ordering::Acquire); - compiler_fence(Ordering::Release); - compiler_fence(Ordering::AcqRel); - compiler_fence(Ordering::SeqCst); - compiler_fence(Ordering::Relaxed); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fence.stderr b/src/tools/clippy/tests/ui/atomic_ordering_fence.stderr deleted file mode 100644 index 3ceff27d9ad5e..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_fence.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: memory fences cannot have `Relaxed` ordering - --> $DIR/atomic_ordering_fence.rs:13:11 - | -LL | fence(Ordering::Relaxed); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` - -error: memory fences cannot have `Relaxed` ordering - --> $DIR/atomic_ordering_fence.rs:19:20 - | -LL | compiler_fence(Ordering::Relaxed); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` - -error: aborting due to 2 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs b/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs deleted file mode 100644 index d2f95b261242d..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicIsize, Ordering}; - -fn main() { - // `fetch_update` testing - let x = AtomicIsize::new(0); - - // Allowed ordering combos - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |old| Some(old + 1)); - - // AcqRel is always forbidden as a failure ordering - let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); - - // Release is always forbidden as a failure ordering - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); - - // Release success order forbids failure order of Acquire or SeqCst - let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); - - // Relaxed success order also forbids failure order of Acquire or SeqCst - let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); - - // Acquire/AcqRel forbids failure order of SeqCst - let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); - let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.stderr b/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.stderr deleted file mode 100644 index 694548ece97b2..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_fetch_update.stderr +++ /dev/null @@ -1,131 +0,0 @@ -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:21:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:22:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:23:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:24:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:25:46 - | -LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:28:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:29:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:30:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:31:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be `Release` or `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:32:46 - | -LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_fetch_update.rs:35:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Release` - --> $DIR/atomic_ordering_fetch_update.rs:36:47 - | -LL | let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_fetch_update.rs:39:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Relaxed` - --> $DIR/atomic_ordering_fetch_update.rs:40:47 - | -LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering mode `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `Acquire` - --> $DIR/atomic_ordering_fetch_update.rs:43:47 - | -LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: fetch_update's failure ordering may not be stronger than the success ordering of `AcqRel` - --> $DIR/atomic_ordering_fetch_update.rs:44:46 - | -LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1)); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire` or `Relaxed` instead - -error: aborting due to 16 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_int.rs b/src/tools/clippy/tests/ui/atomic_ordering_int.rs deleted file mode 100644 index 2778099e0bc56..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_int.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering}; - -fn main() { - // `AtomicI8` test cases - let x = AtomicI8::new(0); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI16` test cases - let x = AtomicI16::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI32` test cases - let x = AtomicI32::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicI64` test cases - let x = AtomicI64::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicIsize` test cases - let x = AtomicIsize::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_int.stderr b/src/tools/clippy/tests/ui/atomic_ordering_int.stderr deleted file mode 100644 index bbaf234d3c9f8..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_int.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:15:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:16:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:24:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:25:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:33:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:34:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:39:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:40:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:48:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:49:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:54:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:55:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:63:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:64:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:69:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:70:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:78:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:79:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:84:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_int.rs:85:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 20 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs b/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs deleted file mode 100644 index 0c26f65c589e6..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_ptr.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicPtr, Ordering}; - -fn main() { - let ptr = &mut 5; - let other_ptr = &mut 10; - let x = AtomicPtr::new(ptr); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(other_ptr, Ordering::Release); - x.store(other_ptr, Ordering::SeqCst); - x.store(other_ptr, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(other_ptr, Ordering::Acquire); - x.store(other_ptr, Ordering::AcqRel); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_ptr.stderr b/src/tools/clippy/tests/ui/atomic_ordering_ptr.stderr deleted file mode 100644 index 558ae55518d5a..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_ptr.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:16:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:17:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:25:24 - | -LL | x.store(other_ptr, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_ptr.rs:26:24 - | -LL | x.store(other_ptr, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 4 previous errors - diff --git a/src/tools/clippy/tests/ui/atomic_ordering_uint.rs b/src/tools/clippy/tests/ui/atomic_ordering_uint.rs deleted file mode 100644 index c57b3cb9c4284..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_uint.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(clippy::invalid_atomic_ordering)] -#![allow(invalid_atomic_ordering)] -use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering}; - -fn main() { - // `AtomicU8` test cases - let x = AtomicU8::new(0); - - // Allowed load ordering modes - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - - // Disallowed load ordering modes - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - // Allowed store ordering modes - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - - // Disallowed store ordering modes - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU16` test cases - let x = AtomicU16::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU32` test cases - let x = AtomicU32::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicU64` test cases - let x = AtomicU64::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); - - // `AtomicUsize` test cases - let x = AtomicUsize::new(0); - - let _ = x.load(Ordering::Acquire); - let _ = x.load(Ordering::SeqCst); - let _ = x.load(Ordering::Relaxed); - let _ = x.load(Ordering::Release); - let _ = x.load(Ordering::AcqRel); - - x.store(1, Ordering::Release); - x.store(1, Ordering::SeqCst); - x.store(1, Ordering::Relaxed); - x.store(1, Ordering::Acquire); - x.store(1, Ordering::AcqRel); -} diff --git a/src/tools/clippy/tests/ui/atomic_ordering_uint.stderr b/src/tools/clippy/tests/ui/atomic_ordering_uint.stderr deleted file mode 100644 index 5703135bcf1e2..0000000000000 --- a/src/tools/clippy/tests/ui/atomic_ordering_uint.stderr +++ /dev/null @@ -1,163 +0,0 @@ -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:15:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings` - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:16:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:24:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:25:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:33:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:34:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:39:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:40:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:48:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:49:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:54:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:55:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:63:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:64:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:69:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:70:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:78:20 - | -LL | let _ = x.load(Ordering::Release); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic loads cannot have `Release` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:79:20 - | -LL | let _ = x.load(Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:84:16 - | -LL | x.store(1, Ordering::Acquire); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: atomic stores cannot have `Acquire` and `AcqRel` ordering - --> $DIR/atomic_ordering_uint.rs:85:16 - | -LL | x.store(1, Ordering::AcqRel); - | ^^^^^^^^^^^^^^^^ - | - = help: consider using ordering modes `Release`, `SeqCst` or `Relaxed` - -error: aborting due to 20 previous errors - diff --git a/src/tools/clippy/tests/ui/deprecated.rs b/src/tools/clippy/tests/ui/deprecated.rs index e1ee8dbca2c04..d74d4b28873cf 100644 --- a/src/tools/clippy/tests/ui/deprecated.rs +++ b/src/tools/clippy/tests/ui/deprecated.rs @@ -9,5 +9,6 @@ #[warn(clippy::drop_bounds)] #[warn(clippy::temporary_cstring_as_ptr)] #[warn(clippy::panic_params)] +#[warn(clippy::invalid_atomic_ordering)] fn main() {} diff --git a/src/tools/clippy/tests/ui/deprecated.stderr b/src/tools/clippy/tests/ui/deprecated.stderr index edbb891afe07b..ee75a01f8e3cf 100644 --- a/src/tools/clippy/tests/ui/deprecated.stderr +++ b/src/tools/clippy/tests/ui/deprecated.stderr @@ -66,11 +66,17 @@ error: lint `clippy::panic_params` has been removed: `this lint has been uplifte LL | #[warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ +error: lint `clippy::invalid_atomic_ordering` has been removed: `this lint has been uplifted to rustc and is now called `invalid_atomic_ordering`` + --> $DIR/deprecated.rs:12:8 + | +LL | #[warn(clippy::invalid_atomic_ordering)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` --> $DIR/deprecated.rs:1:8 | LL | #[warn(clippy::unstable_as_slice)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors From a02f7b72b67f35f242cbbc9c9bba3c1977305d83 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 10 Dec 2020 08:44:56 -0800 Subject: [PATCH 7/8] Teach rustc_diagnostic_item that enums have variants --- compiler/rustc_passes/src/diagnostic_items.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 699c96bc49d59..7b95d690f8bc4 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -28,6 +28,12 @@ struct DiagnosticItemCollector<'tcx> { impl<'v, 'tcx> ItemLikeVisitor<'v> for DiagnosticItemCollector<'tcx> { fn visit_item(&mut self, item: &hir::Item<'_>) { self.observe_item(&item.attrs, item.hir_id); + + if let hir::ItemKind::Enum(e, _) = &item.kind { + for variant in e.variants { + self.observe_item(variant.attrs, variant.id); + } + } } fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { From 844329c9b2e617605f79000ff8d32d9f3dacc04e Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 10 Dec 2020 08:46:47 -0800 Subject: [PATCH 8/8] Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint --- compiler/rustc_lint/src/types.rs | 31 +++++++++++++------------------ compiler/rustc_span/src/symbol.rs | 10 +++++----- library/core/src/sync/atomic.rs | 6 ++++++ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index cf81384f37208..08f8a7635cd79 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1434,10 +1434,8 @@ impl InvalidAtomicOrdering { } } - fn matches_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[Symbol]) -> bool { - orderings.iter().any(|ordering| { - cx.match_def_path(did, &[sym::core, sym::sync, sym::atomic, sym::Ordering, *ordering]) - }) + fn matches_ordering(cx: &LateContext<'_>, did: DefId, orderings: &[Symbol]) -> bool { + orderings.iter().any(|ordering| cx.tcx.is_diagnostic_item(*ordering, did)) } fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option { @@ -1459,14 +1457,14 @@ impl InvalidAtomicOrdering { if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, ordering_arg.hir_id).opt_def_id(); then { if method == sym::load && - Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Release, sym::AcqRel]) { + Self::matches_ordering(cx, ordering_def_id, &[sym::atomic_ordering_release, sym::atomic_ordering_acqrel]) { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| { diag.build("atomic loads cannot have `Release` or `AcqRel` ordering") .help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`") .emit(); }); } else if method == sym::store && - Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Acquire, sym::AcqRel]) { + Self::matches_ordering(cx, ordering_def_id, &[sym::atomic_ordering_acquire, sym::atomic_ordering_acqrel]) { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| { diag.build("atomic stores cannot have `Acquire` or `AcqRel` ordering") .help("consider using ordering modes `Release`, `SeqCst` or `Relaxed`") @@ -1486,7 +1484,7 @@ impl InvalidAtomicOrdering { cx.tcx.is_diagnostic_item(sym::compiler_fence, def_id); if let ExprKind::Path(ref ordering_qpath) = &args[0].kind; if let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id(); - if Self::matches_ordering_def_path(cx, ordering_def_id, &[sym::Relaxed]); + if Self::matches_ordering(cx, ordering_def_id, &[sym::atomic_ordering_relaxed]); then { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| { diag.build("memory fences cannot have `Relaxed` ordering") @@ -1515,11 +1513,11 @@ impl InvalidAtomicOrdering { // - list of failure orderings forbidden by the success order, // - suggestion message) type OrdLintInfo = (Symbol, &'static [Symbol], &'static str); - let relaxed: OrdLintInfo = (sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`"); - let acquire: OrdLintInfo = (sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`"); - let seq_cst: OrdLintInfo = (sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); - let release = (sym::Release, relaxed.1, relaxed.2); - let acqrel = (sym::AcqRel, acquire.1, acquire.2); + let relaxed: OrdLintInfo = (sym::atomic_ordering_relaxed, &[sym::atomic_ordering_seqcst, sym::atomic_ordering_acquire], "ordering mode `Relaxed`"); + let acquire: OrdLintInfo = (sym::atomic_ordering_acquire, &[sym::atomic_ordering_seqcst], "ordering modes `Acquire` or `Relaxed`"); + let seq_cst: OrdLintInfo = (sym::atomic_ordering_seqcst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`"); + let release = (sym::atomic_ordering_release, relaxed.1, relaxed.2); + let acqrel = (sym::atomic_ordering_acqrel, acquire.1, acquire.2); let search = [relaxed, acquire, seq_cst, release, acqrel]; let success_lint_info = Self::opt_ordering_defid(cx, success_order_arg) @@ -1527,14 +1525,11 @@ impl InvalidAtomicOrdering { search .iter() .find(|(ordering, ..)| { - cx.match_def_path( - success_ord_def_id, - &[sym::core, sym::sync, sym::atomic, sym::Ordering, *ordering], - ) + cx.tcx.is_diagnostic_item(*ordering, success_ord_def_id) }) .copied() }); - if Self::matches_ordering_def_path(cx, fail_ordering_def_id, &[sym::Release, sym::AcqRel]) { + if Self::matches_ordering(cx, fail_ordering_def_id, &[sym::atomic_ordering_seqcst, sym::atomic_ordering_acqrel]) { // If we don't know the success order is, use what we'd suggest // if it were maximally permissive. let suggested = success_lint_info.unwrap_or(seq_cst).2; @@ -1548,7 +1543,7 @@ impl InvalidAtomicOrdering { .emit(); }); } else if let Some((success_ord, bad_ords_given_success, suggested)) = success_lint_info { - if Self::matches_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) { + if Self::matches_ordering(cx, fail_ordering_def_id, bad_ords_given_success) { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| { let msg = format!( "{}'s failure ordering may not be stronger than the success ordering of `{}`", diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0d1f7e69d33c5..230d379ed6cde 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -121,8 +121,6 @@ symbols! { // There is currently no checking that all symbols are used; that would be // nice to have. Symbols { - AcqRel, - Acquire, Alignment, Arc, Argument, @@ -187,15 +185,12 @@ symbols! { RangeToInclusive, Rc, Ready, - Relaxed, - Release, Result, Return, Right, RustcDecodable, RustcEncodable, Send, - SeqCst, Some, StructuralEq, StructuralPartialEq, @@ -292,6 +287,11 @@ symbols! { atomic_i64_type, atomic_i8_type, atomic_isize_type, + atomic_ordering_acqrel, + atomic_ordering_acquire, + atomic_ordering_relaxed, + atomic_ordering_release, + atomic_ordering_seqcst, atomic_ptr_type, atomic_u128_type, atomic_u16_type, diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index b37e8bcdc75d1..47f5d4e066c56 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -213,6 +213,7 @@ unsafe impl Sync for AtomicPtr {} #[stable(feature = "rust1", since = "1.0.0")] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[non_exhaustive] +#[allow(unused_attributes)] pub enum Ordering { /// No ordering constraints, only atomic operations. /// @@ -220,6 +221,7 @@ pub enum Ordering { /// /// [`memory_order_relaxed`]: https://en.cppreference.com/w/cpp/atomic/memory_order#Relaxed_ordering #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_diagnostic_item = "atomic_ordering_relaxed"] Relaxed, /// When coupled with a store, all previous operations become ordered /// before any load of this value with [`Acquire`] (or stronger) ordering. @@ -235,6 +237,7 @@ pub enum Ordering { /// /// [`memory_order_release`]: https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_diagnostic_item = "atomic_ordering_release"] Release, /// When coupled with a load, if the loaded value was written by a store operation with /// [`Release`] (or stronger) ordering, then all subsequent operations @@ -250,6 +253,7 @@ pub enum Ordering { /// /// [`memory_order_acquire`]: https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_diagnostic_item = "atomic_ordering_acquire"] Acquire, /// Has the effects of both [`Acquire`] and [`Release`] together: /// For loads it uses [`Acquire`] ordering. For stores it uses the [`Release`] ordering. @@ -264,6 +268,7 @@ pub enum Ordering { /// /// [`memory_order_acq_rel`]: https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_diagnostic_item = "atomic_ordering_acqrel"] AcqRel, /// Like [`Acquire`]/[`Release`]/[`AcqRel`] (for load, store, and load-with-store /// operations, respectively) with the additional guarantee that all threads see all @@ -273,6 +278,7 @@ pub enum Ordering { /// /// [`memory_order_seq_cst`]: https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_diagnostic_item = "atomic_ordering_seqcst"] SeqCst, }