1d07479b2SMiguel Ojeda.. SPDX-License-Identifier: GPL-2.0 2d07479b2SMiguel Ojeda 3d07479b2SMiguel OjedaCoding Guidelines 4d07479b2SMiguel Ojeda================= 5d07479b2SMiguel Ojeda 6d07479b2SMiguel OjedaThis document describes how to write Rust code in the kernel. 7d07479b2SMiguel Ojeda 8d07479b2SMiguel Ojeda 9d07479b2SMiguel OjedaStyle & formatting 10d07479b2SMiguel Ojeda------------------ 11d07479b2SMiguel Ojeda 12d07479b2SMiguel OjedaThe code should be formatted using ``rustfmt``. In this way, a person 13d07479b2SMiguel Ojedacontributing from time to time to the kernel does not need to learn and 14d07479b2SMiguel Ojedaremember one more style guide. More importantly, reviewers and maintainers 15d07479b2SMiguel Ojedado not need to spend time pointing out style issues anymore, and thus 16d07479b2SMiguel Ojedaless patch roundtrips may be needed to land a change. 17d07479b2SMiguel Ojeda 18d07479b2SMiguel Ojeda.. note:: Conventions on comments and documentation are not checked by 19d07479b2SMiguel Ojeda ``rustfmt``. Thus those are still needed to be taken care of. 20d07479b2SMiguel Ojeda 21d07479b2SMiguel OjedaThe default settings of ``rustfmt`` are used. This means the idiomatic Rust 22d07479b2SMiguel Ojedastyle is followed. For instance, 4 spaces are used for indentation rather 23d07479b2SMiguel Ojedathan tabs. 24d07479b2SMiguel Ojeda 25d07479b2SMiguel OjedaIt is convenient to instruct editors/IDEs to format while typing, 26d07479b2SMiguel Ojedawhen saving or at commit time. However, if for some reason reformatting 27d07479b2SMiguel Ojedathe entire kernel Rust sources is needed at some point, the following can be 28d07479b2SMiguel Ojedarun:: 29d07479b2SMiguel Ojeda 30d07479b2SMiguel Ojeda make LLVM=1 rustfmt 31d07479b2SMiguel Ojeda 32d07479b2SMiguel OjedaIt is also possible to check if everything is formatted (printing a diff 33d07479b2SMiguel Ojedaotherwise), for instance for a CI, with:: 34d07479b2SMiguel Ojeda 35d07479b2SMiguel Ojeda make LLVM=1 rustfmtcheck 36d07479b2SMiguel Ojeda 37d07479b2SMiguel OjedaLike ``clang-format`` for the rest of the kernel, ``rustfmt`` works on 38d07479b2SMiguel Ojedaindividual files, and does not require a kernel configuration. Sometimes it may 39d07479b2SMiguel Ojedaeven work with broken code. 40d07479b2SMiguel Ojeda 41d07479b2SMiguel Ojeda 42d07479b2SMiguel OjedaComments 43d07479b2SMiguel Ojeda-------- 44d07479b2SMiguel Ojeda 45d07479b2SMiguel Ojeda"Normal" comments (i.e. ``//``, rather than code documentation which starts 46d07479b2SMiguel Ojedawith ``///`` or ``//!``) are written in Markdown the same way as documentation 47d07479b2SMiguel Ojedacomments are, even though they will not be rendered. This improves consistency, 48d07479b2SMiguel Ojedasimplifies the rules and allows to move content between the two kinds of 49d07479b2SMiguel Ojedacomments more easily. For instance: 50d07479b2SMiguel Ojeda 51d07479b2SMiguel Ojeda.. code-block:: rust 52d07479b2SMiguel Ojeda 53d07479b2SMiguel Ojeda // `object` is ready to be handled now. 54d07479b2SMiguel Ojeda f(object); 55d07479b2SMiguel Ojeda 56d07479b2SMiguel OjedaFurthermore, just like documentation, comments are capitalized at the beginning 57d07479b2SMiguel Ojedaof a sentence and ended with a period (even if it is a single sentence). This 58d07479b2SMiguel Ojedaincludes ``// SAFETY:``, ``// TODO:`` and other "tagged" comments, e.g.: 59d07479b2SMiguel Ojeda 60d07479b2SMiguel Ojeda.. code-block:: rust 61d07479b2SMiguel Ojeda 62d07479b2SMiguel Ojeda // FIXME: The error should be handled properly. 63d07479b2SMiguel Ojeda 64d07479b2SMiguel OjedaComments should not be used for documentation purposes: comments are intended 65d07479b2SMiguel Ojedafor implementation details, not users. This distinction is useful even if the 66d07479b2SMiguel Ojedareader of the source file is both an implementor and a user of an API. In fact, 67d07479b2SMiguel Ojedasometimes it is useful to use both comments and documentation at the same time. 68d07479b2SMiguel OjedaFor instance, for a ``TODO`` list or to comment on the documentation itself. 69d07479b2SMiguel OjedaFor the latter case, comments can be inserted in the middle; that is, closer to 70d07479b2SMiguel Ojedathe line of documentation to be commented. For any other case, comments are 71d07479b2SMiguel Ojedawritten after the documentation, e.g.: 72d07479b2SMiguel Ojeda 73d07479b2SMiguel Ojeda.. code-block:: rust 74d07479b2SMiguel Ojeda 75d07479b2SMiguel Ojeda /// Returns a new [`Foo`]. 76d07479b2SMiguel Ojeda /// 77d07479b2SMiguel Ojeda /// # Examples 78d07479b2SMiguel Ojeda /// 79d07479b2SMiguel Ojeda // TODO: Find a better example. 80d07479b2SMiguel Ojeda /// ``` 81d07479b2SMiguel Ojeda /// let foo = f(42); 82d07479b2SMiguel Ojeda /// ``` 83d07479b2SMiguel Ojeda // FIXME: Use fallible approach. 84d07479b2SMiguel Ojeda pub fn f(x: i32) -> Foo { 85d07479b2SMiguel Ojeda // ... 86d07479b2SMiguel Ojeda } 87d07479b2SMiguel Ojeda 88d07479b2SMiguel OjedaOne special kind of comments are the ``// SAFETY:`` comments. These must appear 89d07479b2SMiguel Ojedabefore every ``unsafe`` block, and they explain why the code inside the block is 90d07479b2SMiguel Ojedacorrect/sound, i.e. why it cannot trigger undefined behavior in any case, e.g.: 91d07479b2SMiguel Ojeda 92d07479b2SMiguel Ojeda.. code-block:: rust 93d07479b2SMiguel Ojeda 94d07479b2SMiguel Ojeda // SAFETY: `p` is valid by the safety requirements. 95d07479b2SMiguel Ojeda unsafe { *p = 0; } 96d07479b2SMiguel Ojeda 97d07479b2SMiguel Ojeda``// SAFETY:`` comments are not to be confused with the ``# Safety`` sections 98d07479b2SMiguel Ojedain code documentation. ``# Safety`` sections specify the contract that callers 99d07479b2SMiguel Ojeda(for functions) or implementors (for traits) need to abide by. ``// SAFETY:`` 100d07479b2SMiguel Ojedacomments show why a call (for functions) or implementation (for traits) actually 101d07479b2SMiguel Ojedarespects the preconditions stated in a ``# Safety`` section or the language 102d07479b2SMiguel Ojedareference. 103d07479b2SMiguel Ojeda 104d07479b2SMiguel Ojeda 105d07479b2SMiguel OjedaCode documentation 106d07479b2SMiguel Ojeda------------------ 107d07479b2SMiguel Ojeda 108d07479b2SMiguel OjedaRust kernel code is not documented like C kernel code (i.e. via kernel-doc). 109d07479b2SMiguel OjedaInstead, the usual system for documenting Rust code is used: the ``rustdoc`` 110d07479b2SMiguel Ojedatool, which uses Markdown (a lightweight markup language). 111d07479b2SMiguel Ojeda 112d07479b2SMiguel OjedaTo learn Markdown, there are many guides available out there. For instance, 113d07479b2SMiguel Ojedathe one at: 114d07479b2SMiguel Ojeda 115d07479b2SMiguel Ojeda https://commonmark.org/help/ 116d07479b2SMiguel Ojeda 117d07479b2SMiguel OjedaThis is how a well-documented Rust function may look like: 118d07479b2SMiguel Ojeda 119d07479b2SMiguel Ojeda.. code-block:: rust 120d07479b2SMiguel Ojeda 121d07479b2SMiguel Ojeda /// Returns the contained [`Some`] value, consuming the `self` value, 122d07479b2SMiguel Ojeda /// without checking that the value is not [`None`]. 123d07479b2SMiguel Ojeda /// 124d07479b2SMiguel Ojeda /// # Safety 125d07479b2SMiguel Ojeda /// 126d07479b2SMiguel Ojeda /// Calling this method on [`None`] is *[undefined behavior]*. 127d07479b2SMiguel Ojeda /// 128d07479b2SMiguel Ojeda /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html 129d07479b2SMiguel Ojeda /// 130d07479b2SMiguel Ojeda /// # Examples 131d07479b2SMiguel Ojeda /// 132d07479b2SMiguel Ojeda /// ``` 133d07479b2SMiguel Ojeda /// let x = Some("air"); 134d07479b2SMiguel Ojeda /// assert_eq!(unsafe { x.unwrap_unchecked() }, "air"); 135d07479b2SMiguel Ojeda /// ``` 136d07479b2SMiguel Ojeda pub unsafe fn unwrap_unchecked(self) -> T { 137d07479b2SMiguel Ojeda match self { 138d07479b2SMiguel Ojeda Some(val) => val, 139d07479b2SMiguel Ojeda 140d07479b2SMiguel Ojeda // SAFETY: The safety contract must be upheld by the caller. 141d07479b2SMiguel Ojeda None => unsafe { hint::unreachable_unchecked() }, 142d07479b2SMiguel Ojeda } 143d07479b2SMiguel Ojeda } 144d07479b2SMiguel Ojeda 145d07479b2SMiguel OjedaThis example showcases a few ``rustdoc`` features and some conventions followed 146d07479b2SMiguel Ojedain the kernel: 147d07479b2SMiguel Ojeda 148d07479b2SMiguel Ojeda- The first paragraph must be a single sentence briefly describing what 149d07479b2SMiguel Ojeda the documented item does. Further explanations must go in extra paragraphs. 150d07479b2SMiguel Ojeda 151d07479b2SMiguel Ojeda- Unsafe functions must document their safety preconditions under 152d07479b2SMiguel Ojeda a ``# Safety`` section. 153d07479b2SMiguel Ojeda 154d07479b2SMiguel Ojeda- While not shown here, if a function may panic, the conditions under which 155d07479b2SMiguel Ojeda that happens must be described under a ``# Panics`` section. 156d07479b2SMiguel Ojeda 157d07479b2SMiguel Ojeda Please note that panicking should be very rare and used only with a good 158d07479b2SMiguel Ojeda reason. In almost all cases, a fallible approach should be used, typically 159d07479b2SMiguel Ojeda returning a ``Result``. 160d07479b2SMiguel Ojeda 161d07479b2SMiguel Ojeda- If providing examples of usage would help readers, they must be written in 162d07479b2SMiguel Ojeda a section called ``# Examples``. 163d07479b2SMiguel Ojeda 164d07479b2SMiguel Ojeda- Rust items (functions, types, constants...) must be linked appropriately 165d07479b2SMiguel Ojeda (``rustdoc`` will create a link automatically). 166d07479b2SMiguel Ojeda 167d07479b2SMiguel Ojeda- Any ``unsafe`` block must be preceded by a ``// SAFETY:`` comment 168d07479b2SMiguel Ojeda describing why the code inside is sound. 169d07479b2SMiguel Ojeda 170d07479b2SMiguel Ojeda While sometimes the reason might look trivial and therefore unneeded, 171d07479b2SMiguel Ojeda writing these comments is not just a good way of documenting what has been 172d07479b2SMiguel Ojeda taken into account, but most importantly, it provides a way to know that 173d07479b2SMiguel Ojeda there are no *extra* implicit constraints. 174d07479b2SMiguel Ojeda 175d07479b2SMiguel OjedaTo learn more about how to write documentation for Rust and extra features, 176d07479b2SMiguel Ojedaplease take a look at the ``rustdoc`` book at: 177d07479b2SMiguel Ojeda 178d07479b2SMiguel Ojeda https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html 179d07479b2SMiguel Ojeda 180bc2e7d5cSMiguel OjedaIn addition, the kernel supports creating links relative to the source tree by 181bc2e7d5cSMiguel Ojedaprefixing the link destination with ``srctree/``. For instance: 182bc2e7d5cSMiguel Ojeda 183bc2e7d5cSMiguel Ojeda.. code-block:: rust 184bc2e7d5cSMiguel Ojeda 185bc2e7d5cSMiguel Ojeda //! C header: [`include/linux/printk.h`](srctree/include/linux/printk.h) 186bc2e7d5cSMiguel Ojeda 187bc2e7d5cSMiguel Ojedaor: 188bc2e7d5cSMiguel Ojeda 189bc2e7d5cSMiguel Ojeda.. code-block:: rust 190bc2e7d5cSMiguel Ojeda 191bc2e7d5cSMiguel Ojeda /// [`struct mutex`]: srctree/include/linux/mutex.h 192bc2e7d5cSMiguel Ojeda 193d07479b2SMiguel Ojeda 194d07479b2SMiguel OjedaNaming 195d07479b2SMiguel Ojeda------ 196d07479b2SMiguel Ojeda 197d07479b2SMiguel OjedaRust kernel code follows the usual Rust naming conventions: 198d07479b2SMiguel Ojeda 199d07479b2SMiguel Ojeda https://rust-lang.github.io/api-guidelines/naming.html 200d07479b2SMiguel Ojeda 201d07479b2SMiguel OjedaWhen existing C concepts (e.g. macros, functions, objects...) are wrapped into 202d07479b2SMiguel Ojedaa Rust abstraction, a name as close as reasonably possible to the C side should 203d07479b2SMiguel Ojedabe used in order to avoid confusion and to improve readability when switching 204d07479b2SMiguel Ojedaback and forth between the C and Rust sides. For instance, macros such as 205d07479b2SMiguel Ojeda``pr_info`` from C are named the same in the Rust side. 206d07479b2SMiguel Ojeda 207d07479b2SMiguel OjedaHaving said that, casing should be adjusted to follow the Rust naming 208d07479b2SMiguel Ojedaconventions, and namespacing introduced by modules and types should not be 209d07479b2SMiguel Ojedarepeated in the item names. For instance, when wrapping constants like: 210d07479b2SMiguel Ojeda 211d07479b2SMiguel Ojeda.. code-block:: c 212d07479b2SMiguel Ojeda 213d07479b2SMiguel Ojeda #define GPIO_LINE_DIRECTION_IN 0 214d07479b2SMiguel Ojeda #define GPIO_LINE_DIRECTION_OUT 1 215d07479b2SMiguel Ojeda 216d07479b2SMiguel OjedaThe equivalent in Rust may look like (ignoring documentation): 217d07479b2SMiguel Ojeda 218d07479b2SMiguel Ojeda.. code-block:: rust 219d07479b2SMiguel Ojeda 220d07479b2SMiguel Ojeda pub mod gpio { 221d07479b2SMiguel Ojeda pub enum LineDirection { 222d07479b2SMiguel Ojeda In = bindings::GPIO_LINE_DIRECTION_IN as _, 223d07479b2SMiguel Ojeda Out = bindings::GPIO_LINE_DIRECTION_OUT as _, 224d07479b2SMiguel Ojeda } 225d07479b2SMiguel Ojeda } 226d07479b2SMiguel Ojeda 227d07479b2SMiguel OjedaThat is, the equivalent of ``GPIO_LINE_DIRECTION_IN`` would be referred to as 228d07479b2SMiguel Ojeda``gpio::LineDirection::In``. In particular, it should not be named 229d07479b2SMiguel Ojeda``gpio::gpio_line_direction::GPIO_LINE_DIRECTION_IN``. 230139d3965SMiguel Ojeda 231139d3965SMiguel Ojeda 232139d3965SMiguel OjedaLints 233139d3965SMiguel Ojeda----- 234139d3965SMiguel Ojeda 235139d3965SMiguel OjedaIn Rust, it is possible to ``allow`` particular warnings (diagnostics, lints) 236139d3965SMiguel Ojedalocally, making the compiler ignore instances of a given warning within a given 237139d3965SMiguel Ojedafunction, module, block, etc. 238139d3965SMiguel Ojeda 239139d3965SMiguel OjedaIt is similar to ``#pragma GCC diagnostic push`` + ``ignored`` + ``pop`` in C 240139d3965SMiguel Ojeda[#]_: 241139d3965SMiguel Ojeda 242139d3965SMiguel Ojeda.. code-block:: c 243139d3965SMiguel Ojeda 244139d3965SMiguel Ojeda #pragma GCC diagnostic push 245139d3965SMiguel Ojeda #pragma GCC diagnostic ignored "-Wunused-function" 246139d3965SMiguel Ojeda static void f(void) {} 247139d3965SMiguel Ojeda #pragma GCC diagnostic pop 248139d3965SMiguel Ojeda 249139d3965SMiguel Ojeda.. [#] In this particular case, the kernel's ``__{always,maybe}_unused`` 250139d3965SMiguel Ojeda attributes (C23's ``[[maybe_unused]]``) may be used; however, the example 251139d3965SMiguel Ojeda is meant to reflect the equivalent lint in Rust discussed afterwards. 252139d3965SMiguel Ojeda 253139d3965SMiguel OjedaBut way less verbose: 254139d3965SMiguel Ojeda 255139d3965SMiguel Ojeda.. code-block:: rust 256139d3965SMiguel Ojeda 257139d3965SMiguel Ojeda #[allow(dead_code)] 258139d3965SMiguel Ojeda fn f() {} 259139d3965SMiguel Ojeda 260139d3965SMiguel OjedaBy that virtue, it makes it possible to comfortably enable more diagnostics by 261139d3965SMiguel Ojedadefault (i.e. outside ``W=`` levels). In particular, those that may have some 262139d3965SMiguel Ojedafalse positives but that are otherwise quite useful to keep enabled to catch 263139d3965SMiguel Ojedapotential mistakes. 264139d3965SMiguel Ojeda 26504866494SMiguel OjedaOn top of that, Rust provides the ``expect`` attribute which takes this further. 26604866494SMiguel OjedaIt makes the compiler warn if the warning was not produced. For instance, the 26704866494SMiguel Ojedafollowing will ensure that, when ``f()`` is called somewhere, we will have to 26804866494SMiguel Ojedaremove the attribute: 26904866494SMiguel Ojeda 27004866494SMiguel Ojeda.. code-block:: rust 27104866494SMiguel Ojeda 27204866494SMiguel Ojeda #[expect(dead_code)] 27304866494SMiguel Ojeda fn f() {} 27404866494SMiguel Ojeda 27504866494SMiguel OjedaIf we do not, we get a warning from the compiler:: 27604866494SMiguel Ojeda 27704866494SMiguel Ojeda warning: this lint expectation is unfulfilled 27804866494SMiguel Ojeda --> x.rs:3:10 27904866494SMiguel Ojeda | 28004866494SMiguel Ojeda 3 | #[expect(dead_code)] 28104866494SMiguel Ojeda | ^^^^^^^^^ 28204866494SMiguel Ojeda | 28304866494SMiguel Ojeda = note: `#[warn(unfulfilled_lint_expectations)]` on by default 28404866494SMiguel Ojeda 28504866494SMiguel OjedaThis means that ``expect``\ s do not get forgotten when they are not needed, which 28604866494SMiguel Ojedamay happen in several situations, e.g.: 28704866494SMiguel Ojeda 28804866494SMiguel Ojeda- Temporary attributes added while developing. 28904866494SMiguel Ojeda 29004866494SMiguel Ojeda- Improvements in lints in the compiler, Clippy or custom tools which may 29104866494SMiguel Ojeda remove a false positive. 29204866494SMiguel Ojeda 29304866494SMiguel Ojeda- When the lint is not needed anymore because it was expected that it would be 29404866494SMiguel Ojeda removed at some point, such as the ``dead_code`` example above. 29504866494SMiguel Ojeda 29604866494SMiguel OjedaIt also increases the visibility of the remaining ``allow``\ s and reduces the 29704866494SMiguel Ojedachance of misapplying one. 29804866494SMiguel Ojeda 299b160dc46SMiguel OjedaThus prefer ``expect`` over ``allow`` unless: 30004866494SMiguel Ojeda 30104866494SMiguel Ojeda- Conditional compilation triggers the warning in some cases but not others. 30204866494SMiguel Ojeda 30304866494SMiguel Ojeda If there are only a few cases where the warning triggers (or does not 30404866494SMiguel Ojeda trigger) compared to the total number of cases, then one may consider using 30504866494SMiguel Ojeda a conditional ``expect`` (i.e. ``cfg_attr(..., expect(...))``). Otherwise, 30604866494SMiguel Ojeda it is likely simpler to just use ``allow``. 30704866494SMiguel Ojeda 30804866494SMiguel Ojeda- Inside macros, when the different invocations may create expanded code that 30904866494SMiguel Ojeda triggers the warning in some cases but not in others. 31004866494SMiguel Ojeda 31104866494SMiguel Ojeda- When code may trigger a warning for some architectures but not others, such 31204866494SMiguel Ojeda as an ``as`` cast to a C FFI type. 31304866494SMiguel Ojeda 31404866494SMiguel OjedaAs a more developed example, consider for instance this program: 31504866494SMiguel Ojeda 31604866494SMiguel Ojeda.. code-block:: rust 31704866494SMiguel Ojeda 31804866494SMiguel Ojeda fn g() {} 31904866494SMiguel Ojeda 32004866494SMiguel Ojeda fn main() { 32104866494SMiguel Ojeda #[cfg(CONFIG_X)] 32204866494SMiguel Ojeda g(); 32304866494SMiguel Ojeda } 32404866494SMiguel Ojeda 32504866494SMiguel OjedaHere, function ``g()`` is dead code if ``CONFIG_X`` is not set. Can we use 32604866494SMiguel Ojeda``expect`` here? 32704866494SMiguel Ojeda 32804866494SMiguel Ojeda.. code-block:: rust 32904866494SMiguel Ojeda 33004866494SMiguel Ojeda #[expect(dead_code)] 33104866494SMiguel Ojeda fn g() {} 33204866494SMiguel Ojeda 33304866494SMiguel Ojeda fn main() { 33404866494SMiguel Ojeda #[cfg(CONFIG_X)] 33504866494SMiguel Ojeda g(); 33604866494SMiguel Ojeda } 33704866494SMiguel Ojeda 33804866494SMiguel OjedaThis would emit a lint if ``CONFIG_X`` is set, since it is not dead code in that 33904866494SMiguel Ojedaconfiguration. Therefore, in cases like this, we cannot use ``expect`` as-is. 34004866494SMiguel Ojeda 34104866494SMiguel OjedaA simple possibility is using ``allow``: 34204866494SMiguel Ojeda 34304866494SMiguel Ojeda.. code-block:: rust 34404866494SMiguel Ojeda 34504866494SMiguel Ojeda #[allow(dead_code)] 34604866494SMiguel Ojeda fn g() {} 34704866494SMiguel Ojeda 34804866494SMiguel Ojeda fn main() { 34904866494SMiguel Ojeda #[cfg(CONFIG_X)] 35004866494SMiguel Ojeda g(); 35104866494SMiguel Ojeda } 35204866494SMiguel Ojeda 35304866494SMiguel OjedaAn alternative would be using a conditional ``expect``: 35404866494SMiguel Ojeda 35504866494SMiguel Ojeda.. code-block:: rust 35604866494SMiguel Ojeda 35704866494SMiguel Ojeda #[cfg_attr(not(CONFIG_X), expect(dead_code))] 35804866494SMiguel Ojeda fn g() {} 35904866494SMiguel Ojeda 36004866494SMiguel Ojeda fn main() { 36104866494SMiguel Ojeda #[cfg(CONFIG_X)] 36204866494SMiguel Ojeda g(); 36304866494SMiguel Ojeda } 36404866494SMiguel Ojeda 36504866494SMiguel OjedaThis would ensure that, if someone introduces another call to ``g()`` somewhere 36604866494SMiguel Ojeda(e.g. unconditionally), then it would be spotted that it is not dead code 36704866494SMiguel Ojedaanymore. However, the ``cfg_attr`` is more complex than a simple ``allow``. 36804866494SMiguel Ojeda 36904866494SMiguel OjedaTherefore, it is likely that it is not worth using conditional ``expect``\ s when 37004866494SMiguel Ojedamore than one or two configurations are involved or when the lint may be 37104866494SMiguel Ojedatriggered due to non-local changes (such as ``dead_code``). 37204866494SMiguel Ojeda 373139d3965SMiguel OjedaFor more information about diagnostics in Rust, please see: 374139d3965SMiguel Ojeda 375139d3965SMiguel Ojeda https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html 376*562cc3cdSDirk Behme 377*562cc3cdSDirk BehmeError handling 378*562cc3cdSDirk Behme-------------- 379*562cc3cdSDirk Behme 380*562cc3cdSDirk BehmeFor some background and guidelines about Rust for Linux specific error handling, 381*562cc3cdSDirk Behmeplease see: 382*562cc3cdSDirk Behme 383*562cc3cdSDirk Behme https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust 384