Skip to content

compiler_fence does not cause a panic but a compilation error #148972

@CatCode79

Description

@CatCode79

Location (URL)

https://doc.rust-lang.org/std/sync/atomic/fn.compiler_fence.html

Summary

Halfway through the page it says ‘Panics if order is Relaxed’, but since compiler_fence is, as the name suggests, evaluated at compile time, it seemed strange to me.
In fact, I quickly checked with the line:
compiler_fence(Ordering::Relaxed);

and got a compilation error:
error: memory fences cannot have Relaxed ordering
--> src\main.rs:34:20
|
34 | compiler_fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
|
= help: consider using ordering modes Acquire, Release, AcqRel or SeqCst
= note: #[deny(invalid_atomic_ordering)] on by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions