Skip to content

Commit 840a5b3

Browse files
authored
Ramp up linting (#1672)
This enables a number of rustc lints. The deny-by-default lints indicate a lack of compiler guarantees, future incompatibility (with no guarantees in the meantime), introduce surprising behavior, or are likely to cause undesired behavior. The warn-by-default lints indicate possible errors, future incompatibility (with guaranteed behavior in the meantime), or any other stylistic issues (including idoms).
1 parent 3ba41c9 commit 840a5b3

File tree

101 files changed

+690
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+690
-312
lines changed

.bazelrc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,47 @@ build:self_execute --platform_suffix=self-execute
5353
build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
5454
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
5555

56+
# Keep this in sync with the top-level Cargo.toml
57+
build --@rules_rust//:extra_rustc_flag=-Dambiguous_glob_reexports
58+
build --@rules_rust//:extra_rustc_flag=-Dclashing_extern_declarations
59+
build --@rules_rust//:extra_rustc_flag=-Dconst_item_mutation
60+
build --@rules_rust//:extra_rustc_flag=-Ddangling_pointers_from_temporaries
61+
build --@rules_rust//:extra_rustc_flag=-Dderef_nullptr
62+
build --@rules_rust//:extra_rustc_flag=-Ddrop_bounds
63+
build --@rules_rust//:extra_rustc_flag=-Dfuture_incompatible
64+
build --@rules_rust//:extra_rustc_flag=-Dhidden_glob_reexports
65+
build --@rules_rust//:extra_rustc_flag=-Dimproper_ctypes
66+
build --@rules_rust//:extra_rustc_flag=-Dimproper_ctypes_definitions
67+
build --@rules_rust//:extra_rustc_flag=-Dinvalid_from_utf8
68+
build --@rules_rust//:extra_rustc_flag=-Dinvalid_macro_export_arguments
69+
build --@rules_rust//:extra_rustc_flag=-Dinvalid_nan_comparisons
70+
build --@rules_rust//:extra_rustc_flag=-Dinvalid_reference_casting
71+
build --@rules_rust//:extra_rustc_flag=-Dinvalid_value
72+
build --@rules_rust//:extra_rustc_flag=-Dopaque_hidden_inferred_bound
73+
build --@rules_rust//:extra_rustc_flag=-Doverlapping_range_endpoints
74+
build --@rules_rust//:extra_rustc_flag=-Dsuspicious_double_ref_op
75+
build --@rules_rust//:extra_rustc_flag=-Dunconditional_recursion
76+
build --@rules_rust//:extra_rustc_flag=-Dunexpected_cfgs
77+
build --@rules_rust//:extra_rustc_flag=-Dunnameable_test_items
78+
build --@rules_rust//:extra_rustc_flag=-Dunsafe_op_in_unsafe_fn
79+
build --@rules_rust//:extra_rustc_flag=-Dunstable_syntax_pre_expansion
80+
build --@rules_rust//:extra_rustc_flag=-Wkeyword_idents
81+
build --@rules_rust//:extra_rustc_flag=-Wlet_underscore
82+
build --@rules_rust//:extra_rustc_flag=-Wmacro_use_extern_crate
83+
build --@rules_rust//:extra_rustc_flag=-Wmeta_variable_misuse
84+
build --@rules_rust//:extra_rustc_flag=-Wmissing_abi
85+
build --@rules_rust//:extra_rustc_flag=-Wmissing_copy_implementations
86+
build --@rules_rust//:extra_rustc_flag=-Wmissing_debug_implementations
87+
build --@rules_rust//:extra_rustc_flag=-Wnoop_method_call
88+
build --@rules_rust//:extra_rustc_flag=-Wsingle_use_lifetimes
89+
build --@rules_rust//:extra_rustc_flag=-Wtrivial_casts
90+
build --@rules_rust//:extra_rustc_flag=-Wtrivial_numeric_casts
91+
build --@rules_rust//:extra_rustc_flag=-Wunreachable_pub
92+
build --@rules_rust//:extra_rustc_flag=-Wunused
93+
build --@rules_rust//:extra_rustc_flag=-Wunused_import_braces
94+
build --@rules_rust//:extra_rustc_flag=-Wunused_lifetimes
95+
build --@rules_rust//:extra_rustc_flag=-Wunused_qualifications
96+
build --@rules_rust//:extra_rustc_flag=-Wvariant_size_differences
5697
# TODO(aaronmondal): Extend these flags until we can run with clippy::pedantic.
5798
build --@rules_rust//:clippy_flags=-Dwarnings,-Dclippy::missing_const_for_fn,-Dclippy::uninlined_format_args,-Dclippy::manual_string_new,-Dclippy::manual_let_else,-Dclippy::single_match_else,-Dclippy::redundant_closure_for_method_calls,-Dclippy::semicolon_if_nothing_returned,-Dclippy::unreadable_literal,-Dclippy::range_plus_one,-Dclippy::inconsistent_struct_constructor,-Dclippy::match_wildcard_for_single_variants,-Dclippy::implicit_clone,-Dclippy::needless_pass_by_value,-Dclippy::explicit_deref_methods,-Dclippy::trivially_copy_pass_by_ref,-Dclippy::unnecessary_wraps,-Dclippy::cast_lossless,-Dclippy::map_unwrap_or,-Dclippy::ref_as_ptr,-Dclippy::inline_always,-Dclippy::redundant_else,-Dclippy::return_self_not_must_use,-Dclippy::match_same_arms,-Dclippy::explicit_iter_loop,-Dclippy::items_after_statements,-Dclippy::explicit_into_iter_loop,-Dclippy::stable_sort_primitive,-Dclippy::ptr_as_ptr,-Dclippy::needless_raw_string_hashes,-Dclippy::default_trait_access,-Dclippy::ignored_unit_patterns,-Dclippy::needless_continue,-Dclippy::wildcard_imports,-Dclippy::doc_markdown,-Dclippy::struct_field_names,-Dclippy::implicit_hasher
5899
build --@rules_rust//:clippy.toml=//:clippy.toml

Cargo.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,49 @@ tokio-stream = ["fs"]
7575
tonic-build = ["prost"]
7676
tonic = ["transport", "tls"]
7777
uuid = ["v4", "serde"]
78+
79+
[workspace.lints.rust]
80+
ambiguous-glob-reexports = "deny"
81+
clashing-extern-declarations = "deny"
82+
const-item-mutation = "deny"
83+
dangling-pointers-from-temporaries = "deny"
84+
deref-nullptr = "deny"
85+
drop-bounds = "deny"
86+
future-incompatible = "deny"
87+
hidden-glob-reexports = "deny"
88+
improper-ctypes = "deny"
89+
improper-ctypes-definitions = "deny"
90+
invalid-from-utf8 = "deny"
91+
invalid-macro-export-arguments = "deny"
92+
invalid-nan-comparisons = "deny"
93+
invalid-reference-casting = "deny"
94+
invalid-value = "deny"
95+
opaque-hidden-inferred-bound = "deny"
96+
overlapping-range-endpoints = "deny"
97+
suspicious-double-ref-op = "deny"
98+
unconditional-recursion = "deny"
99+
unexpected-cfgs = "deny"
100+
unnameable-test-items = "deny"
101+
unsafe-op-in-unsafe-fn = "deny"
102+
unstable-syntax-pre-expansion = "deny"
103+
104+
keyword-idents = "warn"
105+
let-underscore = "warn"
106+
macro-use-extern-crate = "warn"
107+
meta-variable-misuse = "warn"
108+
missing-abi = "warn"
109+
missing-copy-implementations = "warn"
110+
missing-debug-implementations = "warn"
111+
noop-method-call = "warn"
112+
single-use-lifetimes = "warn"
113+
trivial-casts = "warn"
114+
trivial-numeric-casts = "warn"
115+
unreachable-pub = "warn"
116+
unused = { level = "warn", priority = -1 }
117+
unused-import-braces = "warn"
118+
unused-lifetimes = "warn"
119+
unused-qualifications = "warn"
120+
variant-size-differences = "warn"
121+
122+
[workspace.lints.clippy]
123+
all = { level = "warn", priority = -1 }

nativelink-config/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "nativelink-config"
35
version = "0.6.0"

nativelink-config/src/cas_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub struct TlsConfig {
327327
///
328328
/// Note: All of these default to hyper's default values unless otherwise
329329
/// specified.
330-
#[derive(Deserialize, Debug, Default)]
330+
#[derive(Deserialize, Debug, Default, Clone, Copy)]
331331
#[serde(deny_unknown_fields)]
332332
pub struct HttpServerConfig {
333333
/// Interval to send keep-alive pings via HTTP2.

nativelink-config/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ pub struct NamedConfig<Spec> {
3232
pub spec: Spec,
3333
}
3434

35-
pub type StoreConfig = NamedConfig<crate::stores::StoreSpec>;
36-
pub type SchedulerConfig = NamedConfig<crate::schedulers::SchedulerSpec>;
35+
pub type StoreConfig = NamedConfig<stores::StoreSpec>;
36+
pub type SchedulerConfig = NamedConfig<schedulers::SchedulerSpec>;
3737

3838
// TODO(aaronmondal): Remove all the iterator impls and the Deserializer once we
3939
// fully migrate to the new config schema.
40-
pub type StoreConfigs = NamedConfigs<crate::stores::StoreSpec>;
41-
pub type SchedulerConfigs = NamedConfigs<crate::schedulers::SchedulerSpec>;
40+
pub type StoreConfigs = NamedConfigs<stores::StoreSpec>;
41+
pub type SchedulerConfigs = NamedConfigs<schedulers::SchedulerSpec>;
4242

4343
#[derive(Debug)]
4444
pub struct NamedConfigs<T>(pub Vec<NamedConfig<T>>);

nativelink-config/src/stores.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ pub struct FastSlowSpec {
524524
pub slow: StoreSpec,
525525
}
526526

527-
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
527+
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
528528
#[serde(deny_unknown_fields)]
529529
pub struct MemorySpec {
530530
/// Policy used to evict items out of the store. Failure to set this
@@ -664,7 +664,7 @@ pub struct Lz4Config {
664664
pub max_decode_block_size: u32,
665665
}
666666

667-
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
667+
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
668668
#[serde(rename_all = "snake_case")]
669669
pub enum CompressionAlgorithm {
670670
/// LZ4 compression algorithm is extremely fast for compression and
@@ -695,7 +695,7 @@ pub struct CompressionSpec {
695695
/// is touched it updates the timestamp. Inserts and updates will execute the
696696
/// eviction policy removing any expired entries and/or the oldest entries
697697
/// until the store size becomes smaller than `max_bytes`.
698-
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
698+
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
699699
#[serde(deny_unknown_fields)]
700700
pub struct EvictionPolicy {
701701
/// Maximum number of bytes before eviction takes place.
@@ -851,7 +851,7 @@ pub struct GrpcSpec {
851851
}
852852

853853
/// The possible error codes that might occur on an upstream request.
854-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
854+
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
855855
pub enum ErrorCode {
856856
Cancelled = 1,
857857
Unknown = 2,
@@ -991,7 +991,7 @@ pub struct RedisSpec {
991991
pub retry: Retry,
992992
}
993993

994-
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
994+
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
995995
#[serde(rename_all = "snake_case")]
996996
pub enum RedisMode {
997997
Cluster,
@@ -1000,7 +1000,7 @@ pub enum RedisMode {
10001000
Standard,
10011001
}
10021002

1003-
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1003+
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)]
10041004
pub struct NoopSpec {}
10051005

10061006
/// Retry configuration. This configuration is exponential and each iteration

nativelink-error/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "nativelink-error"
35
version = "0.6.0"

nativelink-error/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ pub trait ResultExt<T> {
249249
fn err_tip_with_code<F, S>(self, tip_fn: F) -> Result<T, Error>
250250
where
251251
Self: Sized,
252-
S: std::string::ToString,
253-
F: (std::ops::FnOnce(&Error) -> (Code, S)) + Sized;
252+
S: ToString,
253+
F: (FnOnce(&Error) -> (Code, S)) + Sized;
254254

255255
#[inline]
256256
fn err_tip<F, S>(self, tip_fn: F) -> Result<T, Error>
257257
where
258258
Self: Sized,
259-
S: std::string::ToString,
260-
F: (std::ops::FnOnce() -> S) + Sized,
259+
S: ToString,
260+
F: (FnOnce() -> S) + Sized,
261261
{
262262
self.err_tip_with_code(|e| (e.code, tip_fn()))
263263
}
@@ -275,8 +275,8 @@ impl<T, E: Into<Error>> ResultExt<T> for Result<T, E> {
275275
fn err_tip_with_code<F, S>(self, tip_fn: F) -> Result<T, Error>
276276
where
277277
Self: Sized,
278-
S: std::string::ToString,
279-
F: (std::ops::FnOnce(&Error) -> (Code, S)) + Sized,
278+
S: ToString,
279+
F: (FnOnce(&Error) -> (Code, S)) + Sized,
280280
{
281281
self.map_err(|e| {
282282
let mut error: Error = e.into();
@@ -310,8 +310,8 @@ impl<T> ResultExt<T> for Option<T> {
310310
fn err_tip_with_code<F, S>(self, tip_fn: F) -> Result<T, Error>
311311
where
312312
Self: Sized,
313-
S: std::string::ToString,
314-
F: (std::ops::FnOnce(&Error) -> (Code, S)) + Sized,
313+
S: ToString,
314+
F: (FnOnce(&Error) -> (Code, S)) + Sized,
315315
{
316316
self.ok_or_else(|| {
317317
let mut error = Error {
@@ -375,7 +375,7 @@ impl ErrorKindExt for std::io::ErrorKind {
375375
}
376376

377377
// Serde definition for tonic::Code. See: https://serde.rs/remote-derive.html
378-
#[derive(Serialize, Deserialize)]
378+
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
379379
#[serde(remote = "Code")]
380380
pub enum CodeDef {
381381
Ok = 0,

nativelink-macro/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "nativelink-macro"
35
version = "0.6.0"

nativelink-macro/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
extern crate proc_macro;
16-
1715
use proc_macro::TokenStream;
1816
use quote::quote;
1917
use syn::{ItemFn, parse_macro_input};

0 commit comments

Comments
 (0)