From 95bbc7f367ed7ffd2ea3cbc3cc3ddaaa0d68ad65 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Sat, 25 Jan 2025 00:56:07 +0800 Subject: [PATCH] Enforce `#[expect(lint)]` --- Cargo.toml | 3 +++ .../style-guidelines/rust-guidelines.md | 14 +++++++------- kernel/Cargo.toml | 3 +++ kernel/comps/block/Cargo.toml | 3 ++- kernel/comps/console/Cargo.toml | 3 ++- kernel/comps/framebuffer/Cargo.toml | 3 ++- kernel/comps/input/Cargo.toml | 3 ++- kernel/comps/logger/Cargo.toml | 3 +++ kernel/comps/mlsdisk/Cargo.toml | 3 +++ kernel/comps/network/Cargo.toml | 3 +++ kernel/comps/softirq/Cargo.toml | 3 ++- kernel/comps/time/Cargo.toml | 3 ++- kernel/comps/virtio/Cargo.toml | 3 +++ kernel/libs/aster-bigtcp/Cargo.toml | 3 +++ kernel/libs/aster-rights-proc/Cargo.toml | 3 +++ kernel/libs/aster-rights/Cargo.toml | 3 ++- kernel/libs/aster-util/Cargo.toml | 3 ++- kernel/libs/atomic-integer-wrapper/Cargo.toml | 3 +++ kernel/libs/cpio-decoder/Cargo.toml | 5 ++++- kernel/libs/int-to-c-enum/Cargo.toml | 3 +++ kernel/libs/int-to-c-enum/derive/Cargo.toml | 3 +++ kernel/libs/jhash/Cargo.toml | 3 +++ kernel/libs/keyable-arc/Cargo.toml | 2 ++ kernel/libs/typeflags-util/Cargo.toml | 3 +++ kernel/libs/typeflags/Cargo.toml | 3 +++ osdk/test-kernel/Cargo.toml | 3 +++ ostd/Cargo.toml | 3 +++ ostd/libs/align_ext/Cargo.toml | 7 ++++++- ostd/libs/id-alloc/Cargo.toml | 3 +++ ostd/libs/linux-bzimage/boot-params/Cargo.toml | 3 +++ ostd/libs/linux-bzimage/builder/Cargo.toml | 3 +++ ostd/libs/linux-bzimage/setup/Cargo.toml | 3 +++ ostd/libs/ostd-macros/Cargo.toml | 3 +++ ostd/libs/ostd-test/Cargo.toml | 5 +++++ 34 files changed, 103 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d780f6c0..8725b302 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,9 @@ exclude = [ "target/osdk/test-base", ] +[workspace.lints.clippy] +allow_attributes = "warn" + # Cargo only looks at the profile settings # in the Cargo.toml manifest at the root of the workspace diff --git a/docs/src/to-contribute/style-guidelines/rust-guidelines.md b/docs/src/to-contribute/style-guidelines/rust-guidelines.md index 1d0c92c4..18be6851 100644 --- a/docs/src/to-contribute/style-guidelines/rust-guidelines.md +++ b/docs/src/to-contribute/style-guidelines/rust-guidelines.md @@ -26,10 +26,10 @@ can easily be misinterpreted as the trait itself being dead code. Instead, the following pattern is preferred: ```rust trait SomeTrait { - #[allow(dead_code)] + #[expect(dead_code)] fn foo(); - #[allow(dead_code)] + #[expect(dead_code)] fn bar(); fn baz(); @@ -38,26 +38,26 @@ trait SomeTrait { There is one exception: If it is clear enough that every member will trigger the lint, -it is reasonable to allow the lint at the type level. +it is reasonable to expect the lint at the type level. For example, in the following code, -we add `#[allow(non_camel_case_types)]` for the type `SomeEnum`, +we add `#[expect(non_camel_case_types)]` for the type `SomeEnum`, instead of for each variant of the type: ```rust -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] enum SomeEnum { FOO_ABC, BAR_DEF, } ``` -### When to `#[allow(dead_code)]` +### When to `#[expect(dead_code)]` In general, dead code should be avoided because _(i)_ it introduces unnecessary maintenance overhead, and _(ii)_ its correctness can only be guaranteed by manual and error-pruned review of the code. -In the case where allowing dead code is necessary, +In the case where expecting dead code is necessary, it should fulfill the following requirements: 1. We have a _concrete case_ that will be implemented in the future and will turn the dead code into used code. diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index c2ff90b1..586bb4d0 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -71,3 +71,6 @@ riscv = { version = "0.11.1", features = ["s-mode"] } all = ["cvm_guest"] cvm_guest = ["dep:tdx-guest", "ostd/cvm_guest"] + +[lints] +workspace = true diff --git a/kernel/comps/block/Cargo.toml b/kernel/comps/block/Cargo.toml index 6dc5351e..24532ea6 100644 --- a/kernel/comps/block/Cargo.toml +++ b/kernel/comps/block/Cargo.toml @@ -17,4 +17,5 @@ log = "0.4" static_assertions = "1.1.0" bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] } -[features] +[lints] +workspace = true diff --git a/kernel/comps/console/Cargo.toml b/kernel/comps/console/Cargo.toml index 47469efe..fdfe9185 100644 --- a/kernel/comps/console/Cargo.toml +++ b/kernel/comps/console/Cargo.toml @@ -13,4 +13,5 @@ aster-util = { path = "../../libs/aster-util" } component = { path = "../../libs/comp-sys/component" } log = "0.4" -[features] +[lints] +workspace = true diff --git a/kernel/comps/framebuffer/Cargo.toml b/kernel/comps/framebuffer/Cargo.toml index b1382d83..e24d779a 100644 --- a/kernel/comps/framebuffer/Cargo.toml +++ b/kernel/comps/framebuffer/Cargo.toml @@ -15,4 +15,5 @@ font8x8 = { version = "0.2.5", default-features = false, features = [ "unicode", ] } -[features] +[lints] +workspace = true diff --git a/kernel/comps/input/Cargo.toml b/kernel/comps/input/Cargo.toml index ea4d55c6..001ff751 100644 --- a/kernel/comps/input/Cargo.toml +++ b/kernel/comps/input/Cargo.toml @@ -16,4 +16,5 @@ int-to-c-enum = { path = "../../libs/int-to-c-enum" } log = "0.4" ascii = { version = "1.1", default-features = false, features = ["alloc"] } -[features] +[lints] +workspace = true diff --git a/kernel/comps/logger/Cargo.toml b/kernel/comps/logger/Cargo.toml index 8c7bef55..f39ec451 100644 --- a/kernel/comps/logger/Cargo.toml +++ b/kernel/comps/logger/Cargo.toml @@ -18,3 +18,6 @@ cfg-if = "1.0" [features] default = ["log_color"] log_color = ["dep:owo-colors"] + +[lints] +workspace = true diff --git a/kernel/comps/mlsdisk/Cargo.toml b/kernel/comps/mlsdisk/Cargo.toml index 897f3d56..ae3f22aa 100644 --- a/kernel/comps/mlsdisk/Cargo.toml +++ b/kernel/comps/mlsdisk/Cargo.toml @@ -20,3 +20,6 @@ lru = "0.12.3" postcard = "1.0.6" serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] } static_assertions = "1.1.0" + +[lints] +workspace = true diff --git a/kernel/comps/network/Cargo.toml b/kernel/comps/network/Cargo.toml index 1c2ece6d..ee813256 100644 --- a/kernel/comps/network/Cargo.toml +++ b/kernel/comps/network/Cargo.toml @@ -17,3 +17,6 @@ int-to-c-enum = { path = "../../libs/int-to-c-enum" } log = "0.4" ostd = { path = "../../../ostd" } spin = "0.9.4" + +[lints] +workspace = true diff --git a/kernel/comps/softirq/Cargo.toml b/kernel/comps/softirq/Cargo.toml index 044013a1..c20a434c 100644 --- a/kernel/comps/softirq/Cargo.toml +++ b/kernel/comps/softirq/Cargo.toml @@ -12,4 +12,5 @@ aster-logger = { path = "../logger" } intrusive-collections = "0.9.5" spin = "0.9.4" -[features] \ No newline at end of file +[lints] +workspace = true diff --git a/kernel/comps/time/Cargo.toml b/kernel/comps/time/Cargo.toml index 24a9a1a0..6e409eca 100644 --- a/kernel/comps/time/Cargo.toml +++ b/kernel/comps/time/Cargo.toml @@ -16,4 +16,5 @@ spin = "0.9.4" [target.riscv64gc-unknown-none-elf.dependencies] chrono = { version = "0.4.38", default-features = false } -[features] +[lints] +workspace = true diff --git a/kernel/comps/virtio/Cargo.toml b/kernel/comps/virtio/Cargo.toml index a287ac16..cd34e6b2 100644 --- a/kernel/comps/virtio/Cargo.toml +++ b/kernel/comps/virtio/Cargo.toml @@ -24,3 +24,6 @@ component = { path = "../../libs/comp-sys/component" } log = "0.4" bit_field = "0.10.1" int-to-c-enum = { path = "../../libs/int-to-c-enum" } + +[lints] +workspace = true diff --git a/kernel/libs/aster-bigtcp/Cargo.toml b/kernel/libs/aster-bigtcp/Cargo.toml index 90b1e03c..b7459d8f 100644 --- a/kernel/libs/aster-bigtcp/Cargo.toml +++ b/kernel/libs/aster-bigtcp/Cargo.toml @@ -21,3 +21,6 @@ smoltcp = { git = "https://github.com/asterinas/smoltcp", tag = "r_2024-11-08_f0 spin = "0.9.4" static_assertions = "1.1.0" takeable = "0.2.2" + +[lints] +workspace = true diff --git a/kernel/libs/aster-rights-proc/Cargo.toml b/kernel/libs/aster-rights-proc/Cargo.toml index bcdc003f..c5c5a0c8 100644 --- a/kernel/libs/aster-rights-proc/Cargo.toml +++ b/kernel/libs/aster-rights-proc/Cargo.toml @@ -12,3 +12,6 @@ proc-macro = true proc-macro2 = "1.0" quote = "1.0" syn = {version = "1.0.90", features = ["full", "fold"]} + +[lints] +workspace = true diff --git a/kernel/libs/aster-rights/Cargo.toml b/kernel/libs/aster-rights/Cargo.toml index c9f4f522..ef7f477f 100644 --- a/kernel/libs/aster-rights/Cargo.toml +++ b/kernel/libs/aster-rights/Cargo.toml @@ -11,4 +11,5 @@ typeflags-util = { path = "../typeflags-util" } bitflags = "1.3" aster-rights-proc = { path = "../aster-rights-proc" } -[features] +[lints] +workspace = true diff --git a/kernel/libs/aster-util/Cargo.toml b/kernel/libs/aster-util/Cargo.toml index 7b6454e0..96623c54 100644 --- a/kernel/libs/aster-util/Cargo.toml +++ b/kernel/libs/aster-util/Cargo.toml @@ -12,4 +12,5 @@ aster-rights-proc = { path = "../aster-rights-proc" } aster-rights = { path = "../aster-rights" } inherit-methods-macro = { git = "https://github.com/asterinas/inherit-methods-macro", rev = "98f7e3e" } -[features] +[lints] +workspace = true diff --git a/kernel/libs/atomic-integer-wrapper/Cargo.toml b/kernel/libs/atomic-integer-wrapper/Cargo.toml index a91147dc..f7033019 100644 --- a/kernel/libs/atomic-integer-wrapper/Cargo.toml +++ b/kernel/libs/atomic-integer-wrapper/Cargo.toml @@ -10,3 +10,6 @@ proc-macro = true proc-macro2 = "1.0.86" quote = "1.0.37" syn = { version = "2.0.77", features = ["full"] } + +[lints] +workspace = true diff --git a/kernel/libs/cpio-decoder/Cargo.toml b/kernel/libs/cpio-decoder/Cargo.toml index f633ade3..9521632e 100644 --- a/kernel/libs/cpio-decoder/Cargo.toml +++ b/kernel/libs/cpio-decoder/Cargo.toml @@ -8,4 +8,7 @@ edition = "2021" [dependencies] int-to-c-enum = { path = "../../libs/int-to-c-enum" } core2 = { version = "0.4", default-features = false, features = ["alloc"] } -lending-iterator = "0.1.7" \ No newline at end of file +lending-iterator = "0.1.7" + +[lints] +workspace = true diff --git a/kernel/libs/int-to-c-enum/Cargo.toml b/kernel/libs/int-to-c-enum/Cargo.toml index 98443d32..3631f07b 100644 --- a/kernel/libs/int-to-c-enum/Cargo.toml +++ b/kernel/libs/int-to-c-enum/Cargo.toml @@ -15,3 +15,6 @@ int-to-c-enum-derive = { path = "derive", optional = true, version = "0.1.0"} [features] default = ["derive"] derive = ["int-to-c-enum-derive"] + +[lints] +workspace = true diff --git a/kernel/libs/int-to-c-enum/derive/Cargo.toml b/kernel/libs/int-to-c-enum/derive/Cargo.toml index badab5b6..56d0a792 100644 --- a/kernel/libs/int-to-c-enum/derive/Cargo.toml +++ b/kernel/libs/int-to-c-enum/derive/Cargo.toml @@ -15,3 +15,6 @@ proc-macro = true proc-macro2 = "1.0" quote = "1.0" syn = { version = "2.0.15", features = ["parsing"] } + +[lints] +workspace = true diff --git a/kernel/libs/jhash/Cargo.toml b/kernel/libs/jhash/Cargo.toml index 9c3614de..da1acc6e 100644 --- a/kernel/libs/jhash/Cargo.toml +++ b/kernel/libs/jhash/Cargo.toml @@ -4,3 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] + +[lints] +workspace = true diff --git a/kernel/libs/keyable-arc/Cargo.toml b/kernel/libs/keyable-arc/Cargo.toml index 38258725..9bdc2571 100644 --- a/kernel/libs/keyable-arc/Cargo.toml +++ b/kernel/libs/keyable-arc/Cargo.toml @@ -7,3 +7,5 @@ edition = "2021" [dependencies] +[lints] +workspace = true diff --git a/kernel/libs/typeflags-util/Cargo.toml b/kernel/libs/typeflags-util/Cargo.toml index 7c1cec8a..3d471d3c 100644 --- a/kernel/libs/typeflags-util/Cargo.toml +++ b/kernel/libs/typeflags-util/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[lints] +workspace = true diff --git a/kernel/libs/typeflags/Cargo.toml b/kernel/libs/typeflags/Cargo.toml index a4bd82e6..345ca49e 100644 --- a/kernel/libs/typeflags/Cargo.toml +++ b/kernel/libs/typeflags/Cargo.toml @@ -14,3 +14,6 @@ proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0.90" } typeflags-util = { path = "../typeflags-util" } + +[lints] +workspace = true diff --git a/osdk/test-kernel/Cargo.toml b/osdk/test-kernel/Cargo.toml index be821faa..2827ebaf 100644 --- a/osdk/test-kernel/Cargo.toml +++ b/osdk/test-kernel/Cargo.toml @@ -11,3 +11,6 @@ repository ="https://github.com/asterinas/asterinas" [dependencies] ostd = { version = "0.11.1", path = "../../ostd" } owo-colors = "4.0.0" + +[lints] +workspace = true diff --git a/ostd/Cargo.toml b/ostd/Cargo.toml index c44fb02d..b20f4311 100644 --- a/ostd/Cargo.toml +++ b/ostd/Cargo.toml @@ -65,3 +65,6 @@ fdt = { version = "0.1.5", features = ["pretty-printing"] } default = ["cvm_guest"] # The guest OS support for Confidential VMs (CVMs), e.g., Intel TDX cvm_guest = ["dep:tdx-guest", "dep:iced-x86"] + +[lints] +workspace = true diff --git a/ostd/libs/align_ext/Cargo.toml b/ostd/libs/align_ext/Cargo.toml index 637fe759..72f6f824 100644 --- a/ostd/libs/align_ext/Cargo.toml +++ b/ostd/libs/align_ext/Cargo.toml @@ -5,4 +5,9 @@ edition = "2021" description = " An extension trait for Rust integer types to make integers aligned to a power of two" license = "MPL-2.0" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html \ No newline at end of file +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lints] +workspace = true diff --git a/ostd/libs/id-alloc/Cargo.toml b/ostd/libs/id-alloc/Cargo.toml index 6a5bffc1..5cdd942e 100644 --- a/ostd/libs/id-alloc/Cargo.toml +++ b/ostd/libs/id-alloc/Cargo.toml @@ -10,3 +10,6 @@ repository = "https://github.com/asterinas/asterinas" [dependencies] bitvec = { version = "1.0", default-features = false, features = ["alloc"] } + +[lints] +workspace = true diff --git a/ostd/libs/linux-bzimage/boot-params/Cargo.toml b/ostd/libs/linux-bzimage/boot-params/Cargo.toml index fce48f27..7543e7b9 100644 --- a/ostd/libs/linux-bzimage/boot-params/Cargo.toml +++ b/ostd/libs/linux-bzimage/boot-params/Cargo.toml @@ -9,3 +9,6 @@ repository = "https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[lints] +workspace = true diff --git a/ostd/libs/linux-bzimage/builder/Cargo.toml b/ostd/libs/linux-bzimage/builder/Cargo.toml index 5c6a383b..89b8f4df 100644 --- a/ostd/libs/linux-bzimage/builder/Cargo.toml +++ b/ostd/libs/linux-bzimage/builder/Cargo.toml @@ -14,3 +14,6 @@ bitflags = "1.3" libflate = "2.1.0" serde = { version = "1.0.192", features = ["derive"] } xmas-elf = "0.9.1" + +[lints] +workspace = true diff --git a/ostd/libs/linux-bzimage/setup/Cargo.toml b/ostd/libs/linux-bzimage/setup/Cargo.toml index 831686a4..180c2047 100644 --- a/ostd/libs/linux-bzimage/setup/Cargo.toml +++ b/ostd/libs/linux-bzimage/setup/Cargo.toml @@ -32,3 +32,6 @@ tdx-guest = { version = "0.1.8", optional = true } default = ["cvm_guest"] debug_print = [] cvm_guest = ["dep:tdx-guest"] + +[lints] +workspace = true diff --git a/ostd/libs/ostd-macros/Cargo.toml b/ostd/libs/ostd-macros/Cargo.toml index 87eccdb6..db93f8d3 100644 --- a/ostd/libs/ostd-macros/Cargo.toml +++ b/ostd/libs/ostd-macros/Cargo.toml @@ -16,3 +16,6 @@ proc-macro2 = "1.0.78" quote = "1.0.35" rand = "0.8.5" syn = { version = "2.0.48", features = ["full"] } + +[lints] +workspace = true diff --git a/ostd/libs/ostd-test/Cargo.toml b/ostd/libs/ostd-test/Cargo.toml index 895f006f..b279af28 100644 --- a/ostd/libs/ostd-test/Cargo.toml +++ b/ostd/libs/ostd-test/Cargo.toml @@ -7,3 +7,8 @@ license = "MPL-2.0" repository ="https://github.com/asterinas/asterinas" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[lints] +workspace = true