Skip to content

Commit 0602729

Browse files
committed
lint: port atomic ordering diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 14c3016 commit 0602729

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,21 @@ lint-improper-ctypes-only-phantomdata = composed only of `PhantomData`
233233
234234
lint-variant-size-differences =
235235
enum variant is more than three times larger ({$largest} bytes) than the next largest
236+
237+
lint-atomic-ordering-load = atomic loads cannot have `Release` or `AcqRel` ordering
238+
.help = consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
239+
240+
lint-atomic-ordering-store = atomic stores cannot have `Acquire` or `AcqRel` ordering
241+
.help = consider using ordering modes `Release`, `SeqCst` or `Relaxed`
242+
243+
lint-atomic-ordering-fence = memory fences cannot have `Relaxed` ordering
244+
.help = consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
245+
246+
lint-atomic-ordering-invalid = `{$method}`'s failure ordering may not be `Release` or `AcqRel`, since a failed `{$method}` does not result in a write
247+
.label = invalid failure ordering
248+
.help = consider using `Acquire` or `Relaxed` failure ordering instead
249+
250+
lint-atomic-ordering-invalid-fail-success = `{$method}`'s success ordering must be at least as strong as its failure ordering
251+
.fail-label = `{$fail_ordering}` failure ordering
252+
.success-label = `{$success_ordering}` success ordering
253+
.suggestion = consider using `{$success_suggestion}` success ordering instead

compiler/rustc_lint/src/types.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,13 @@ impl InvalidAtomicOrdering {
15121512
{
15131513
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| {
15141514
if method == sym::load {
1515-
diag.build("atomic loads cannot have `Release` or `AcqRel` ordering")
1516-
.help("consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`")
1515+
diag.build(fluent::lint::atomic_ordering_load)
1516+
.help(fluent::lint::help)
15171517
.emit()
15181518
} else {
15191519
debug_assert_eq!(method, sym::store);
1520-
diag.build("atomic stores cannot have `Acquire` or `AcqRel` ordering")
1521-
.help("consider using ordering modes `Release`, `SeqCst` or `Relaxed`")
1520+
diag.build(fluent::lint::atomic_ordering_store)
1521+
.help(fluent::lint::help)
15221522
.emit();
15231523
}
15241524
});
@@ -1533,8 +1533,8 @@ impl InvalidAtomicOrdering {
15331533
&& Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed)
15341534
{
15351535
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| {
1536-
diag.build("memory fences cannot have `Relaxed` ordering")
1537-
.help("consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`")
1536+
diag.build(fluent::lint::atomic_ordering_fence)
1537+
.help(fluent::lint::help)
15381538
.emit();
15391539
});
15401540
}
@@ -1554,13 +1554,11 @@ impl InvalidAtomicOrdering {
15541554

15551555
if matches!(fail_ordering, sym::Release | sym::AcqRel) {
15561556
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg.span, |diag| {
1557-
diag.build(&format!(
1558-
"`{method}`'s failure ordering may not be `Release` or `AcqRel`, \
1559-
since a failed `{method}` does not result in a write",
1560-
))
1561-
.span_label(fail_order_arg.span, "invalid failure ordering")
1562-
.help("consider using `Acquire` or `Relaxed` failure ordering instead")
1563-
.emit();
1557+
diag.build(fluent::lint::atomic_ordering_invalid)
1558+
.set_arg("method", method)
1559+
.span_label(fail_order_arg.span, fluent::lint::label)
1560+
.help(fluent::lint::help)
1561+
.emit();
15641562
});
15651563
}
15661564

@@ -1578,18 +1576,20 @@ impl InvalidAtomicOrdering {
15781576
fail_ordering
15791577
};
15801578
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, success_order_arg.span, |diag| {
1581-
diag.build(&format!(
1582-
"`{method}`'s success ordering must be at least as strong as its failure ordering"
1583-
))
1584-
.span_label(fail_order_arg.span, format!("`{fail_ordering}` failure ordering"))
1585-
.span_label(success_order_arg.span, format!("`{success_ordering}` success ordering"))
1586-
.span_suggestion_short(
1587-
success_order_arg.span,
1588-
format!("consider using `{success_suggestion}` success ordering instead"),
1589-
format!("std::sync::atomic::Ordering::{success_suggestion}"),
1590-
Applicability::MaybeIncorrect,
1591-
)
1592-
.emit();
1579+
diag.build(fluent::lint::atomic_ordering_invalid_fail_success)
1580+
.set_arg("method", method)
1581+
.set_arg("fail_ordering", fail_ordering)
1582+
.set_arg("success_ordering", success_ordering)
1583+
.set_arg("success_suggestion", success_suggestion)
1584+
.span_label(fail_order_arg.span, fluent::lint::fail_label)
1585+
.span_label(success_order_arg.span, fluent::lint::success_label)
1586+
.span_suggestion_short(
1587+
success_order_arg.span,
1588+
fluent::lint::suggestion,
1589+
format!("std::sync::atomic::Ordering::{success_suggestion}"),
1590+
Applicability::MaybeIncorrect,
1591+
)
1592+
.emit();
15931593
});
15941594
}
15951595
}

0 commit comments

Comments
 (0)