1
Fork 0

lint: port atomic ordering diagnostics

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-28 09:59:30 +01:00
parent 14c3016583
commit 0602729c71
2 changed files with 43 additions and 25 deletions

View file

@ -233,3 +233,21 @@ lint-improper-ctypes-only-phantomdata = composed only of `PhantomData`
lint-variant-size-differences = lint-variant-size-differences =
enum variant is more than three times larger ({$largest} bytes) than the next largest enum variant is more than three times larger ({$largest} bytes) than the next largest
lint-atomic-ordering-load = atomic loads cannot have `Release` or `AcqRel` ordering
.help = consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
lint-atomic-ordering-store = atomic stores cannot have `Acquire` or `AcqRel` ordering
.help = consider using ordering modes `Release`, `SeqCst` or `Relaxed`
lint-atomic-ordering-fence = memory fences cannot have `Relaxed` ordering
.help = consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
lint-atomic-ordering-invalid = `{$method}`'s failure ordering may not be `Release` or `AcqRel`, since a failed `{$method}` does not result in a write
.label = invalid failure ordering
.help = consider using `Acquire` or `Relaxed` failure ordering instead
lint-atomic-ordering-invalid-fail-success = `{$method}`'s success ordering must be at least as strong as its failure ordering
.fail-label = `{$fail_ordering}` failure ordering
.success-label = `{$success_ordering}` success ordering
.suggestion = consider using `{$success_suggestion}` success ordering instead

View file

@ -1512,13 +1512,13 @@ impl InvalidAtomicOrdering {
{ {
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| {
if method == sym::load { if method == sym::load {
diag.build("atomic loads cannot have `Release` or `AcqRel` ordering") diag.build(fluent::lint::atomic_ordering_load)
.help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`") .help(fluent::lint::help)
.emit() .emit()
} else { } else {
debug_assert_eq!(method, sym::store); debug_assert_eq!(method, sym::store);
diag.build("atomic stores cannot have `Acquire` or `AcqRel` ordering") diag.build(fluent::lint::atomic_ordering_store)
.help("consider using ordering modes `Release`, `SeqCst` or `Relaxed`") .help(fluent::lint::help)
.emit(); .emit();
} }
}); });
@ -1533,8 +1533,8 @@ impl InvalidAtomicOrdering {
&& Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed) && Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed)
{ {
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| {
diag.build("memory fences cannot have `Relaxed` ordering") diag.build(fluent::lint::atomic_ordering_fence)
.help("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`") .help(fluent::lint::help)
.emit(); .emit();
}); });
} }
@ -1554,13 +1554,11 @@ impl InvalidAtomicOrdering {
if matches!(fail_ordering, sym::Release | sym::AcqRel) { if matches!(fail_ordering, sym::Release | sym::AcqRel) {
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg.span, |diag| { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg.span, |diag| {
diag.build(&format!( diag.build(fluent::lint::atomic_ordering_invalid)
"`{method}`'s failure ordering may not be `Release` or `AcqRel`, \ .set_arg("method", method)
since a failed `{method}` does not result in a write", .span_label(fail_order_arg.span, fluent::lint::label)
)) .help(fluent::lint::help)
.span_label(fail_order_arg.span, "invalid failure ordering") .emit();
.help("consider using `Acquire` or `Relaxed` failure ordering instead")
.emit();
}); });
} }
@ -1578,18 +1576,20 @@ impl InvalidAtomicOrdering {
fail_ordering fail_ordering
}; };
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, success_order_arg.span, |diag| { cx.struct_span_lint(INVALID_ATOMIC_ORDERING, success_order_arg.span, |diag| {
diag.build(&format!( diag.build(fluent::lint::atomic_ordering_invalid_fail_success)
"`{method}`'s success ordering must be at least as strong as its failure ordering" .set_arg("method", method)
)) .set_arg("fail_ordering", fail_ordering)
.span_label(fail_order_arg.span, format!("`{fail_ordering}` failure ordering")) .set_arg("success_ordering", success_ordering)
.span_label(success_order_arg.span, format!("`{success_ordering}` success ordering")) .set_arg("success_suggestion", success_suggestion)
.span_suggestion_short( .span_label(fail_order_arg.span, fluent::lint::fail_label)
success_order_arg.span, .span_label(success_order_arg.span, fluent::lint::success_label)
format!("consider using `{success_suggestion}` success ordering instead"), .span_suggestion_short(
format!("std::sync::atomic::Ordering::{success_suggestion}"), success_order_arg.span,
Applicability::MaybeIncorrect, fluent::lint::suggestion,
) format!("std::sync::atomic::Ordering::{success_suggestion}"),
.emit(); Applicability::MaybeIncorrect,
)
.emit();
}); });
} }
} }