Skip to content

Commit 865b802

Browse files
committed
Documentation: rust: add coding guidelines on lints
In the C side, disabling diagnostics locally, i.e. within the source code, is rare (at least in the kernel). Sometimes warnings are manipulated via the flags at the translation unit level, but that is about it. In Rust, it is easier to change locally the "level" of lints (e.g. allowing them locally). In turn, this means it is easier to globally enable more lints that may trigger a few false positives here and there that need to be allowed ocally, but that generally can spot issues or bugs. Thus document this. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 26d09e3 commit 865b802

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Documentation/rust/coding-guidelines.rst

+29
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,32 @@ The equivalent in Rust may look like (ignoring documentation):
227227
That is, the equivalent of ``GPIO_LINE_DIRECTION_IN`` would be referred to as
228228
``gpio::LineDirection::In``. In particular, it should not be named
229229
``gpio::gpio_line_direction::GPIO_LINE_DIRECTION_IN``.
230+
231+
232+
Lints
233+
-----
234+
235+
In Rust, it is possible to ``allow`` particular warnings (diagnostics, lints)
236+
locally, making the compiler ignore instances of a given warning within a given
237+
function, module, block, etc.
238+
239+
It is similar to ``#pragma GCC diagnostic push`` + ``ignored`` + ``pop`` in C:
240+
241+
.. code-block:: c
242+
243+
#pragma GCC diagnostic push
244+
#pragma GCC diagnostic ignored "-Wunused-function"
245+
static void f(void) {}
246+
#pragma GCC diagnostic pop
247+
248+
But way less verbose:
249+
250+
.. code-block:: rust
251+
252+
#[allow(dead_code)]
253+
fn f() {}
254+
255+
By that virtue, it makes it possible to comfortably enable more diagnostics by
256+
default (i.e. outside ``W=`` levels). In particular, those that may have some
257+
false positives but that are otherwise quite useful to keep enabled to catch
258+
potential mistakes.

0 commit comments

Comments
 (0)