[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240717221133.459589-6-benno.lossin@proton.me>
Date: Wed, 17 Jul 2024 22:13:01 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Jonathan Corbet <corbet@....net>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...sung.com>, Alice Ryhl <aliceryhl@...gle.com>
Cc: linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: [RFC PATCH 5/5] doc: rust: safety standard: add justifications
Add standardized justifications that are used to justify the safety
requirements.
Signed-off-by: Benno Lossin <benno.lossin@...ton.me>
---
Documentation/rust/safety-standard/index.rst | 5 +++
.../rust/safety-standard/justifications.rst | 40 +++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 Documentation/rust/safety-standard/justifications.rst
diff --git a/Documentation/rust/safety-standard/index.rst b/Documentation/rust/safety-standard/index.rst
index 2ef82d7dfbd8..db62ad01ebe0 100644
--- a/Documentation/rust/safety-standard/index.rst
+++ b/Documentation/rust/safety-standard/index.rst
@@ -191,6 +191,8 @@ block. For example::
In this case it is more readable to not split the block into multiple parts.
+See justifications.rst for a full list of standardized justifications.
+
``unsafe`` Traits
-----------------
@@ -225,6 +227,8 @@ similarly to :ref:`unsafe-Blocks`::
// SAFETY: <justification>
unsafe impl Foo for Bar {}
+See justifications.rst for a full list of standardized justifications.
+
Guarantees
==========
@@ -267,6 +271,7 @@ Further Pages
guarantee
type-invariants
requirements
+ justifications
.. only:: subproject and html
diff --git a/Documentation/rust/safety-standard/justifications.rst b/Documentation/rust/safety-standard/justifications.rst
new file mode 100644
index 000000000000..72b6943f3d40
--- /dev/null
+++ b/Documentation/rust/safety-standard/justifications.rst
@@ -0,0 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. highlight:: rust
+
+==============
+Justifications
+==============
+
+Since there are so many different safety-requirements.rst, there are also many different ways to
+justify them.
+
+Justifications are listed in an unordered markdown list in the ``SAFETY`` comments on ``unsafe``
+blocks and ``unsafe impl``. The order and elements of the list must match the list present in the
+``# Safety`` section on the respective ``unsafe`` item (e.g. the function or the trait).
+
+Common Justifications
+=====================
+
+In order to use the justifications from the table below, first repeat the safety requirement and
+then write ``by <justification>`` where justification is from the table below.
+If you need the conjunction of multiple justifications, then you just intersperse them with "and".
+
+The term "goal safety requirement" is referring to the requirement that you are trying to justify.
+
++---------------------------+----------------------------------------------------------------------+
+| Syntax | Meaning/Justified Safety Requirement |
++===========================+======================================================================+
+| function requirements | The goal safety requirement is provided by the surrounding function, |
+| | as it also has it (or a stronger statement) as a safety requirement. |
++---------------------------+----------------------------------------------------------------------+
+| type invariant of ``T`` | The given safety requirement is provided by the type invariant of |
+| | ``T``, as it also has it (or a stronger statement) as a type |
+| | invariant. |
++---------------------------+----------------------------------------------------------------------+
+| reference validity | When turning a (mutable) reference into a pointer, that pointer will |
+| | be valid for reads (and writes). |
++---------------------------+----------------------------------------------------------------------+
+| function guarantee of | The goal safety requirement is provided by the called function |
+| ``$function`` | ``$function``, as it has it (or a stronger statement) listed as a |
+| | :doc:`guarantee <guarantee>`. |
++---------------------------+----------------------------------------------------------------------+
--
2.45.1
Powered by blists - more mailing lists