Skip to content

Commit 054c2fd

Browse files
authored
Clippy fixes (#1124)
* Print clippy version on CI * First bunch of lint fixes * More clippy fixes * div_ceil lint
1 parent 6391121 commit 054c2fd

File tree

26 files changed

+97
-9
lines changed

26 files changed

+97
-9
lines changed

.github/workflows/solana.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
cd /solana/contracts &&\
122122
anchor build &&\
123123
cargo check &&\
124+
cargo clippy -- --version &&\
124125
cargo clippy -- -D warnings &&\
125126
cargo test --workspace"
126127

chains/solana/contracts/crates/build-commit/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ pub fn cargo_instructions(source_file: &str, version: &str) {
1111

1212
// ensure it is re-run when the build script changes
1313
println!("cargo:rerun-if-changed=build.rs");
14-
println!("cargo:rerun-if-changed={}", source_file);
14+
println!("cargo:rerun-if-changed={source_file}");
1515
println!("cargo:rerun-if-changed={}", file!());
1616

1717
// set environment variables for the build
18-
println!("cargo:rustc-env=CCIP_BUILD_PROGRAM_NAME={}", program_name);
19-
println!(
20-
"cargo:rustc-env=CCIP_BUILD_TYPE_VERSION={} {}",
21-
program_name, version,
22-
);
18+
println!("cargo:rustc-env=CCIP_BUILD_PROGRAM_NAME={program_name}");
19+
println!("cargo:rustc-env=CCIP_BUILD_TYPE_VERSION={program_name} {version}");
2320
}
2421

2522
#[cfg(test)]

chains/solana/contracts/programs/access-controller/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ anchor-lang = "0.29.0"
1919
bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]}
2020
static_assertions = "1.1.0"
2121
arrayvec = { version = "1.0.0", path = "../../crates/arrayvec" }
22+
23+
[lints.rust.unexpected_cfgs]
24+
level = "warn"
25+
check-cfg = ['cfg(target_os, values("solana"))', 'cfg(feature, values("anchor-debug", "custom-panic", "no-log-ix-name"))']

chains/solana/contracts/programs/base-token-pool/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ anchor-spl = "0.29.0"
2121
solana-program = "1.17.25" # pin solana to 1.17
2222
spl-math = { version = "0.2.0", features = [ "no-entrypoint" ] }
2323
rmn_remote = {path = "../rmn-remote", features = ["cpi"]}
24+
25+
[lints.rust.unexpected_cfgs]
26+
level = "warn"
27+
check-cfg = ['cfg(target_os, values("solana"))', 'cfg(feature, values("anchor-debug", "custom-panic"))']

chains/solana/contracts/programs/burnmint-token-pool/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ ccip_common = {path = "../ccip-common"}
2626

2727
[build-dependencies]
2828
build_commit = { path = "../../crates/build-commit" }
29+
30+
[lints.rust.unexpected_cfgs]
31+
level = "warn"
32+
check-cfg = ['cfg(target_os, values("solana"))', 'cfg(feature, values("anchor-debug", "custom-panic"))']

chains/solana/contracts/programs/ccip-common/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ default = ["no-entrypoint"]
2020
solana-program = "1.17.25" # pin solana to 1.17
2121
anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
2222
anchor-spl = "0.29.0"
23-
ethnum = "1.5"
23+
ethnum = "1.5"
24+
25+
[lints.rust.unexpected_cfgs]
26+
level = "warn"
27+
check-cfg = ['cfg(target_os, values("solana"))', 'cfg(feature, values("anchor-debug", "custom-panic"))']

chains/solana/contracts/programs/ccip-offramp/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ hex = "0.4.3"
3030

3131
[build-dependencies]
3232
build_commit = { path = "../../crates/build-commit" }
33+
34+
[lints.rust.unexpected_cfgs]
35+
level = "warn"
36+
check-cfg = ['cfg(target_os, values("solana"))', 'cfg(feature, values("anchor-debug", "custom-panic", "custom-heap"))']

chains/solana/contracts/programs/ccip-offramp/src/instructions/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::state::CodeVersion;
33
use super::interfaces::*;
44
use super::v1;
55

6+
#[allow(clippy::empty_line_after_doc_comments)]
67
/**
78
* This file routes traffic between multiple versions of our business logic, which can be upgraded in a
89
* backwards-compatible way and so we can gradually shift traffic between versions (and rollback if there are issues).

chains/solana/contracts/programs/ccip-offramp/src/instructions/v1/buffering.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,16 @@ pub fn deserialize_from_buffer_account(
174174
))
175175
}
176176

177+
// Using a.div_ceil(b) is unstable on Rust 1.68, so we implement our own version even though clippy may complain.
178+
// See https://github.com/rust-lang/rust/issues/88581 for more info.
179+
// Whenever we upgrade Anchor & Rust, we can remove this.
177180
fn div_ceil<T: Into<u32>>(a: T, b: T) -> u32 {
178181
let (a, b) = (a.into(), b.into());
179182
assert!(a + b - 1 > 0);
183+
184+
// on newer rust version, this would require #[allow(clippy::manual_div_ceil)]
185+
// or be replaced with `a.div_ceil(b)` directly. However, on older rust versions,
186+
// there is no support for clippy's lint and the div_ceil method is unstable.
180187
(a + b - 1) / b
181188
}
182189

chains/solana/contracts/programs/ccip-offramp/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod ccip_offramp {
2323

2424
use super::*;
2525

26+
#[allow(clippy::empty_line_after_outer_attr)]
2627
//////////////////////////
2728
/// Initialization Flow //
2829
//////////////////////////
@@ -144,6 +145,7 @@ pub mod ccip_offramp {
144145
router::admin(default_code_version).accept_ownership(ctx)
145146
}
146147

148+
#[allow(clippy::empty_line_after_outer_attr)]
147149
/////////////
148150
// Config //
149151
/////////////
@@ -360,6 +362,7 @@ pub mod ccip_offramp {
360362
)
361363
}
362364

365+
#[allow(clippy::empty_line_after_outer_attr)]
363366
////////////////////
364367
/// Off Ramp Flow //
365368
////////////////////

0 commit comments

Comments
 (0)