Skip to content

Commit 366d6ad

Browse files
Update Rust style guide (Clippy lints part)
1 parent 5312962 commit 366d6ad

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

book/src/06_rust_api/rust_style_guide.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Exceptions can (and sometimes should) be made, however:
1111
* [Toolchain](#toolchain)
1212
* [Basic Rules](#basic-rules)
1313
* [Creating a new crate](#creating-a-new-crate)
14-
* [Exceptions for clippy](#exceptions-for-clippy)
14+
* [Motivation for enabling lints](#motivation-for-enabling-lints)
15+
* [Exceptions for clippy](#exceptions-for-clippy)
1516
* [Guidelines](#guidelines)
1617
* [Prefer references over generics](#prefer-references-over-generics)
1718
* [Abbreviations and naming things](#abbreviations-and-naming-things)
@@ -59,25 +60,26 @@ before submitting a PR
5960

6061
### Creating a new crate
6162

62-
We add the following preamble to all crates' `lib.rs`:
63+
All rust projects must have the same `Cargo.toml`, `clippy.toml`, `deny.toml`, `nextest.toml`, `rust-toolchain.toml`
64+
and `rustfmt.toml` configurations as defined in the `catalyst-ci` repository in the [`stdcfgs` folder][rust-stdcfgs].
65+
See also [examples][rust-examples] in the same repository.
6366

64-
```rust
65-
#![warn(clippy::pedantic)]
66-
#![forbid(clippy::integer_arithmetic)]
67-
#![forbid(missing_docs)]
68-
#![forbid(unsafe_code)]
69-
#![allow(/* known bad lints outlined below */)]
70-
```
67+
[rust-stdcfgs]: https://github.com/input-output-hk/catalyst-ci/tree/master/earthly/rust/stdcfgs
68+
[rust-examples]: https://github.com/input-output-hk/catalyst-ci/tree/master/examples/rust
69+
70+
#### Motivation for enabling lints
7171

72-
We enable `#![forbid(missing_docs)]` for a couple of reasons:
72+
Generally we prefer to enable all meaningful lints to prevent as many potential errors as possible.
73+
74+
We enable `#![deny(missing_docs)]` for a couple of reasons:
7375

7476
* it forces developers to write doc comments for publicly exported items
7577
* it serves as a reminder that the item you're working on is part of your **public API**
7678

77-
We enable `#![forbid(unsafe_code)]` to reinforce the fact that **unsafe code should not be mixed in with the rest of our code**.
79+
We enable `#![deny(unsafe_code)]` to reinforce the fact that **unsafe code should not be mixed in with the rest of our code**.
7880
More details are below.
7981

80-
We enable `#![forbid(integer_arithmetic)]` to prevent you from writing code like:
82+
We enable `#![deny(arithmetic_side_effects)]` to prevent you from writing code like:
8183

8284
```rust
8385
let x = 1;
@@ -100,20 +102,11 @@ By forbidding integer arithmetic, you have to choose a behaviour, by writing eit
100102
By being explicit, we prevent the developer from "simply not considering" how their code behaves in the presence of overflows.
101103
In a ledger application, silently wrapping could be catastrophic, so we really want to be explicit about what behaviour we expect.
102104

103-
### Exceptions for `clippy`
104-
105-
These lints are disabled:
105+
#### Exceptions for `clippy`
106106

107-
* `clippy::match_bool` - sometimes a `match` statement with `true =>` and `false =>` arms is sometimes more concise and equally readable
108-
* `clippy::module_name_repetition` - warns when creating an item with a name than ends with the name of the module it's in
109-
* `clippy::derive_partial_eq_without_eq` - warns when deriving `PartialEq` and not `Eq`.
110-
This is a semver hazard. Deriving `Eq` is a stronger semver guarantee than just `PartialEq`, and shouldn't be the default.
111-
* `clippy::missing_panics_doc` - this lint warns when a function might panic, but the docs don't have a `panics` section.
112-
This lint is buggy, and doesn't correctly identify all panics.
113-
Code should be written to explicitly avoid intentional panics.
114-
You should still add panic docs if a function is **intended to panic** under some conditions.
115-
If a panic may occur, but you'd consider it a bug if it did, don't document it.
116-
We disable this lint because it creates a false sense of security.
107+
While all lints are enabled by default, there are some cases when it is acceptable to suppress a lint locally. Still
108+
one shouldn't do that without good reasons. For example, it is often ok to allow `clippy::module_name_repetitions`
109+
especially if the type is reexported.
117110

118111
## Guidelines
119112

0 commit comments

Comments
 (0)