rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: "Jonathan Corbet" <corbet@lwn.net>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org
Subject: [RFC PATCH 5/5] doc: rust: safety standard: add justifications
Date: Wed, 17 Jul 2024 22:13:01 +0000	[thread overview]
Message-ID: <20240717221133.459589-6-benno.lossin@proton.me> (raw)
In-Reply-To: <20240717221133.459589-1-benno.lossin@proton.me>

Add standardized justifications that are used to justify the safety
requirements.

Signed-off-by: Benno Lossin <benno.lossin@proton.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



      parent reply	other threads:[~2024-07-17 22:13 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17 22:12 [RFC PATCH 0/5] Introduce the Rust Safety Standard Benno Lossin
2024-07-17 22:12 ` [RFC PATCH 1/5] doc: rust: create safety standard Benno Lossin
2024-07-18  4:45   ` Greg KH
2024-07-24 19:13     ` Benno Lossin
2024-07-25  4:57       ` Greg KH
2024-07-18 12:20   ` Alice Ryhl
2024-07-24 19:36     ` Benno Lossin
2024-07-19 16:24   ` Daniel Almeida
2024-07-19 16:46     ` Alice Ryhl
2024-07-19 17:10     ` Danilo Krummrich
2024-07-19 18:09       ` Daniel Almeida
2024-07-19 19:20         ` Danilo Krummrich
2024-07-19 17:28     ` Miguel Ojeda
2024-07-19 18:18       ` Daniel Almeida
2024-07-19 17:56     ` Miguel Ojeda
2024-07-24 20:31     ` Benno Lossin
2024-07-24 21:20       ` Miguel Ojeda
2024-07-24 21:28         ` Benno Lossin
2024-08-08 13:01       ` Daniel Almeida
2024-08-08 13:08         ` Miguel Ojeda
2024-07-19 22:11   ` Boqun Feng
2024-07-24 22:01     ` Benno Lossin
2024-07-20  7:45   ` Dirk Behme
2024-07-17 22:12 ` [RFC PATCH 2/5] doc: rust: safety standard: add examples Benno Lossin
2024-07-19 16:28   ` Daniel Almeida
2024-07-19 16:36   ` Daniel Almeida
2024-07-25  7:47     ` Benno Lossin
2024-08-08 13:10       ` Daniel Almeida
2024-08-08 14:33         ` Benno Lossin
2024-07-17 22:12 ` [RFC PATCH 3/5] doc: rust: safety standard: add guarantees and type invariants Benno Lossin
2024-07-17 22:12 ` [RFC PATCH 4/5] doc: rust: safety standard: add safety requirements Benno Lossin
2024-07-17 22:13 ` Benno Lossin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240717221133.459589-6-benno.lossin@proton.me \
    --to=benno.lossin@proton.me \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=corbet@lwn.net \
    --cc=gary@garyguo.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).