Skip to content

Uplift the invalid_atomic_ordering lint from clippy to rustc #84039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -3923,6 +3923,7 @@ dependencies = [
name = "rustc_lint"
version = "0.0.0"
dependencies = [
"if_chain",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",
1 change: 1 addition & 0 deletions compiler/rustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ version = "0.0.0"
edition = "2018"

[dependencies]
if_chain = "1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh bold move!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we try to keep our external dependencies as small as possible and this doesn't seem like a necessary addition to me but we have no official policy saying that, so I don't think it should hold up this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wesleywiser if_chain is already in the source tree through clippy, this just adds it to rustc itself. I could rewrite it without if_chain, but it would be annoying and IMO a lot uglier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true but clippy isn't a dependency of rustc so any dependencies they pull in don't actually affect rustc. That's why you had to add it to the tidy allowed set of dependencies.

It's my personal preference and we already have quite a lot of external dependencies as that list showed so don't worry about it 🙂

tracing = "0.1"
unicode-security = "0.0.5"
rustc_middle = { path = "../rustc_middle" }
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -170,6 +170,7 @@ macro_rules! late_lint_passes {
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
NonPanicFmt: NonPanicFmt,
NoopMethodCall: NoopMethodCall,
InvalidAtomicOrdering: InvalidAtomicOrdering,
]
);
};
241 changes: 238 additions & 3 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
@@ -4,17 +4,19 @@ 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_middle::ty::layout::{IntegerExt, SizeSkeleton};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{self, AdtKind, DefIdTree, 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, Variants};
use rustc_target::spec::abi::Abi as SpecAbi;

use if_chain::if_chain;
use std::cmp;
use std::iter;
use std::ops::ControlFlow;
@@ -1379,3 +1381,236 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
}
}
}

declare_lint! {
/// The `invalid_atomic_ordering` lint detects passing an `Ordering`
/// to an atomic operation that does not support that ordering.
///
/// ### Example
///
/// ```rust,compile_fail
/// # 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 inherent_atomic_method_call<'hir>(
cx: &LateContext<'_>,
expr: &Expr<'hir>,
recognized_names: &[Symbol], // used for fast path calculation
) -> Option<(Symbol, &'hir [Expr<'hir>])> {
const ATOMIC_TYPES: &[Symbol] = &[
sym::AtomicBool,
sym::AtomicPtr,
sym::AtomicUsize,
sym::AtomicU8,
sym::AtomicU16,
sym::AtomicU32,
sym::AtomicU64,
sym::AtomicU128,
sym::AtomicIsize,
sym::AtomicI8,
sym::AtomicI16,
sym::AtomicI32,
sym::AtomicI64,
sym::AtomicI128,
];
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
if recognized_names.contains(&method_path.ident.name);
if let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_did) = cx.tcx.impl_of_method(m_def_id);
if let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def();
// skip extension traits, only lint functions from the standard library
if cx.tcx.trait_id_of_impl(impl_did).is_none();

if let Some(parent) = cx.tcx.parent(adt.did);
if cx.tcx.is_diagnostic_item(sym::atomic_mod, parent);
if ATOMIC_TYPES.contains(&cx.tcx.item_name(adt.did));
then {
return Some((method_path.ident.name, args));
}
}
None
}

fn matches_ordering(cx: &LateContext<'_>, did: DefId, orderings: &[Symbol]) -> bool {
let tcx = cx.tcx;
let atomic_ordering = tcx.get_diagnostic_item(sym::Ordering);
orderings.iter().any(|ordering| {
tcx.item_name(did) == *ordering && {
let parent = tcx.parent(did);
parent == atomic_ordering
// needed in case this is a ctor, not a variant
|| parent.map_or(false, |parent| tcx.parent(parent) == atomic_ordering)
}
})
}

fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId> {
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<'_>) {
use rustc_hir::def::{DefKind, Res};
use rustc_hir::QPath;
if_chain! {
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::load, sym::store]);
if let Some((ordering_arg, invalid_ordering)) = match method {
sym::load => Some((&args[1], sym::Release)),
sym::store => Some((&args[2], sym::Acquire)),
_ => None,
};

if let ExprKind::Path(QPath::Resolved(_, path)) = ordering_arg.kind;
if let Res::Def(DefKind::Ctor(..), ctor_id) = path.res;
if Self::matches_ordering(cx, ctor_id, &[invalid_ordering, sym::AcqRel]);
then {
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| {
if method == sym::load {
diag.build("atomic loads cannot have `Release` or `AcqRel` ordering")
.help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`")
.emit()
} else {
debug_assert_eq!(method, sym::store);
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(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 Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak]);
if let Some((success_order_arg, failure_order_arg)) = match method {
sym::fetch_update => Some((&args[1], &args[2])),
sym::compare_exchange | sym::compare_exchange_weak => Some((&args[3], &args[4])),
_ => None,
};

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);
const RELAXED: OrdLintInfo = (sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`");
const ACQUIRE: OrdLintInfo = (sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`");
const SEQ_CST: OrdLintInfo = (sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
const RELEASE: OrdLintInfo = (sym::Release, RELAXED.1, RELAXED.2);
const ACQREL: OrdLintInfo = (sym::AcqRel, ACQUIRE.1, ACQUIRE.2);
const SEARCH: [OrdLintInfo; 5] = [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<OrdLintInfo> {
SEARCH
.iter()
.copied()
.find(|(ordering, ..)| {
Self::matches_ordering(cx, success_ord_def_id, &[*ordering])
})
});
if Self::matches_ordering(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(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);
}
}
29 changes: 29 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -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,
Any,
Arc,
@@ -129,6 +131,20 @@ symbols! {
Arguments,
AsMut,
AsRef,
AtomicBool,
AtomicI128,
AtomicI16,
AtomicI32,
AtomicI64,
AtomicI8,
AtomicIsize,
AtomicPtr,
AtomicU128,
AtomicU16,
AtomicU32,
AtomicU64,
AtomicU8,
AtomicUsize,
BTreeEntry,
BTreeMap,
BTreeSet,
@@ -215,12 +231,15 @@ symbols! {
Rc,
Ready,
Receiver,
Relaxed,
Release,
Result,
Return,
Right,
RustcDecodable,
RustcEncodable,
Send,
SeqCst,
Some,
StructuralEq,
StructuralPartialEq,
@@ -311,6 +330,8 @@ symbols! {
assume_init,
async_await,
async_closure,
atomic,
atomic_mod,
atomics,
att_syntax,
attr,
@@ -390,8 +411,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,
@@ -575,6 +600,8 @@ symbols! {
fadd_fast,
fdiv_fast,
feature,
fence,
fetch_update,
ffi,
ffi_const,
ffi_pure,
@@ -728,6 +755,7 @@ symbols! {
lint_reasons,
literal,
llvm_asm,
load,
local,
local_inner_macros,
log10f32,
@@ -1217,6 +1245,7 @@ symbols! {
stmt,
stmt_expr_attributes,
stop_after_dataflow,
store,
str,
str_alloc,
string_type,
4 changes: 4 additions & 0 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
#![cfg_attr(not(target_has_atomic_load_store = "8"), allow(dead_code))]
#![cfg_attr(not(target_has_atomic_load_store = "8"), allow(unused_imports))]
#![rustc_diagnostic_item = "atomic_mod"]

use self::Ordering::*;

@@ -198,6 +199,7 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[non_exhaustive]
#[rustc_diagnostic_item = "Ordering"]
pub enum Ordering {
/// No ordering constraints, only atomic operations.
///
@@ -2664,6 +2666,7 @@ unsafe fn atomic_umin<T: Copy>(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 {
@@ -2745,6 +2748,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 {
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicBool, Ordering};

fn main() {
@@ -12,7 +11,9 @@ fn main() {

// 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);
@@ -21,5 +22,7 @@ fn main() {

// 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
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
error: atomic loads cannot have `Release` and `AcqRel` ordering
--> $DIR/atomic_ordering_bool.rs:14:20
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-bool.rs:13:20
|
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= note: `#[deny(invalid_atomic_ordering)]` on by default
= 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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-bool.rs:24: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-bool.rs:26:20
|
LL | x.store(false, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicPtr, Ordering};

fn main() {
@@ -21,27 +20,43 @@ fn main() {

// 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
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst);
//~^ 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
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire);
//~^ 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
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst);
//~^ ERROR compare_exchange_weak's failure ordering may not be stronger
}
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
--> $DIR/atomic_ordering_exchange_weak.rs:23:67
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:22:67
|
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= 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/atomic_ordering_exchange_weak.rs:24:67
--> $DIR/lint-invalid-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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:26: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:28: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:30: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:34: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:36: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:38: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:40: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:42: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:46: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:48: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:52: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:54: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:58: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
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:60:66
|
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst);
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicUsize, Ordering};

fn main() {
@@ -19,27 +18,43 @@ fn main() {

// 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
let _ = x.compare_exchange(0, 0, Ordering::Release, Ordering::SeqCst);
//~^ 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
let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::Acquire);
//~^ 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
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst);
//~^ ERROR compare_exchange's failure ordering may not be stronger
}
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
error: compare_exchange's failure ordering may not be `Release` or `AcqRel`
--> $DIR/atomic_ordering_exchange.rs:21:57
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:20:57
|
LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= 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/atomic_ordering_exchange.rs:22:57
--> $DIR/lint-invalid-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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:24: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:26: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:28: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:32: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:34: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:36: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:38: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:40: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:44: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:46: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:50: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:52: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:56: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
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:58:56
|
LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst);
| ^^^^^^^^^^^^^^^^
18 changes: 18 additions & 0 deletions src/test/ui/lint/lint-invalid-atomic-ordering-false-positive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// only-x86_64
// check-pass
use std::sync::atomic::{AtomicUsize, Ordering};

trait Foo {
fn store(self, ordering: Ordering);
}

impl Foo for AtomicUsize {
fn store(self, _ordering: Ordering) {
AtomicUsize::store(&self, 4, Ordering::SeqCst);
}
}

fn main() {
let x = AtomicUsize::new(3);
x.store(Ordering::Acquire);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{compiler_fence, fence, Ordering};

fn main() {
// Allowed fence ordering modes
// Allowed 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);

// Disallowed ordering modes
fence(Ordering::Relaxed);
//~^ ERROR memory fences cannot have `Relaxed` ordering
compiler_fence(Ordering::Relaxed);
//~^ ERROR memory fences cannot have `Relaxed` ordering
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: memory fences cannot have `Relaxed` ordering
--> $DIR/atomic_ordering_fence.rs:13:11
--> $DIR/lint-invalid-atomic-ordering-fence.rs:17:11
|
LL | fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= 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/atomic_ordering_fence.rs:19:20
--> $DIR/lint-invalid-atomic-ordering-fence.rs:19:20
|
LL | compiler_fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicIsize, Ordering};

fn main() {
@@ -19,27 +18,43 @@ fn main() {

// 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
let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1));
//~^ 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
let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1));
//~^ 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
let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1));
//~^ ERROR fetch_update's failure ordering may not be stronger
}
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
error: fetch_update's failure ordering may not be `Release` or `AcqRel`
--> $DIR/atomic_ordering_fetch_update.rs:21:47
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:20:47
|
LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= 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/atomic_ordering_fetch_update.rs:22:47
--> $DIR/lint-invalid-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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:24: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:26: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:28: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:32: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:34: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:36: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:38: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:40: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:44: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:46: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:50: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:52: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:56: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
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:58:46
|
LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(clippy::invalid_atomic_ordering)]

// FIXME: add support for `// only-atomic` to compiletest/header.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's file an issue to track this improvement but this is fine to land.

// only-x86_64
use std::sync::atomic::{AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, Ordering};

fn main() {
@@ -11,76 +11,120 @@ fn main() {
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 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);
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 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);
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 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);
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 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);
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 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
}
Original file line number Diff line number Diff line change
@@ -1,158 +1,158 @@
error: atomic loads cannot have `Release` and `AcqRel` ordering
--> $DIR/atomic_ordering_int.rs:15:20
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:20:20
|
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= note: `#[deny(invalid_atomic_ordering)]` on by default
= 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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:22: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:26: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:28: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:45: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:47: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:51: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:53: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:70: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:72: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:76: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:78: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:95: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:97: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:101: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:103: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:120: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:122: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:126: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:128:16
|
LL | x.store(1, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicPtr, Ordering};

fn main() {
@@ -14,7 +13,9 @@ fn main() {

// 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);
@@ -23,5 +24,7 @@ fn main() {

// 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
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
error: atomic loads cannot have `Release` and `AcqRel` ordering
--> $DIR/atomic_ordering_ptr.rs:16:20
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-ptr.rs:15:20
|
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= note: `#[deny(invalid_atomic_ordering)]` on by default
= 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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-ptr.rs:26: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-ptr.rs:28:24
|
LL | x.store(other_ptr, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::invalid_atomic_ordering)]

// only-x86_64
use std::sync::atomic::{AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, Ordering};

fn main() {
@@ -11,76 +10,120 @@ fn main() {
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 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);
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 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);
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 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);
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 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);
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 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
}
Original file line number Diff line number Diff line change
@@ -1,158 +1,158 @@
error: atomic loads cannot have `Release` and `AcqRel` ordering
--> $DIR/atomic_ordering_uint.rs:15:20
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:19:20
|
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= note: `#[deny(invalid_atomic_ordering)]` on by default
= 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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:21: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:25: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:27: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:44: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:46: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:50: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:52: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:69: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:71: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:75: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:77: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:94: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:96: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:100: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:102: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:119: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
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:121: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:125: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
error: atomic stores cannot have `Acquire` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:127:16
|
LL | x.store(1, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^
230 changes: 0 additions & 230 deletions src/tools/clippy/clippy_lints/src/atomic_ordering.rs

This file was deleted.

6 changes: 1 addition & 5 deletions src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -165,7 +165,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;
@@ -537,7 +536,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,
@@ -1174,7 +1172,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),
@@ -1670,7 +1667,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS),
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),
@@ -2044,7 +2040,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;
@@ -2183,6 +2178,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
ls.register_renamed("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr");
ls.register_renamed("clippy::panic_params", "non_fmt_panics");
ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints");
ls.register_renamed("clippy::invalid_atomic_ordering", "invalid_atomic_ordering");
}

// only exists to let the dogfood integration test works.
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/deprecated.rs
Original file line number Diff line number Diff line change
@@ -14,5 +14,6 @@
#[warn(clippy::filter_map)]
#[warn(clippy::pub_enum_variant_names)]
#[warn(clippy::wrong_pub_self_convention)]
#[warn(clippy::invalid_atomic_ordering)]

fn main() {}
8 changes: 7 additions & 1 deletion src/tools/clippy/tests/ui/deprecated.stderr
Original file line number Diff line number Diff line change
@@ -96,5 +96,11 @@ error: lint `clippy::wrong_pub_self_convention` has been removed: set the `avoid
LL | #[warn(clippy::wrong_pub_self_convention)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 16 previous errors
error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering`
--> $DIR/deprecated.rs:17:8
|
LL | #[warn(clippy::invalid_atomic_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering`

error: aborting due to 17 previous errors

1 change: 1 addition & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
@@ -121,6 +121,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
"hashbrown",
"hermit-abi",
"humantime",
"if_chain",
"indexmap",
"instant",
"itertools",