Skip to content

Commit 5e90da3

Browse files
authored
linera-web: fix Clippy warnings and check Clippy in CI (#4117)
## Motivation #4113. Specifically, ``` $ nix develop ..#nightly -c cargo clippy warning: unstable feature specified for `-Ctarget-feature`: `atomics` | = note: this feature is not stably supported; its behavior can change in the future warning: `linera-witty` (lib) generated 1 warning warning: `linera-base` (lib) generated 1 warning (1 duplicate) warning: `linera-views` (lib) generated 1 warning (1 duplicate) warning: `linera-execution` (lib) generated 1 warning (1 duplicate) warning: `linera-chain` (lib) generated 1 warning (1 duplicate) warning: `linera-storage` (lib) generated 1 warning (1 duplicate) warning: `linera-version` (lib) generated 1 warning (1 duplicate) warning: `linera-persistent` (lib) generated 1 warning (1 duplicate) warning: `linera-core` (lib) generated 1 warning (1 duplicate) warning: `linera-rpc` (lib) generated 1 warning (1 duplicate) warning: `linera-client` (lib) generated 1 warning (1 duplicate) warning: `linera-faucet-client` (lib) generated 1 warning (1 duplicate) Checking linera-web v0.14.0 (/home/twey/dev/linera/protocol/main/linera-web) warning: casting `f64` to `u8` may truncate the value --> linera-web/src/signer.rs:51:19 | 51 | match fnum as u8 { | ^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation = note: `-W clippy::cast-possible-truncation` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_possible_truncation)]` warning: question mark operator is useless here --> linera-web/src/signer.rs:98:9 | 98 | Ok(serde_wasm_bindgen::from_value(js_bool).map_err(|_| JsSignerError::JsConversion)?) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `serde_wasm_bindgen::from_value(js_bool).map_err(|_| JsSignerError::JsConversion)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark = note: `#[warn(clippy::needless_question_mark)]` on by default warning: usage of an `Arc` that is not `Send` and `Sync` --> linera-web/src/lib.rs:202:30 | 202 | let client_context = Arc::new(AsyncMutex::new(ClientContext::new( | ______________________________^ 203 | | storage.clone(), 204 | | OPTIONS, 205 | | wallet.0, 206 | | signer, 207 | | ))); | |___________^ | = note: `Arc<Mutex<ClientContext<Impl<DbStorage<MemoryStore>, NodeProvider, JsSigner>, Memory<Wallet>>>>` is not `Send` and `Sync` as `Mutex<ClientContext<Impl<DbStorage<MemoryStore>, NodeProvider, JsSigner>, Memory<Wallet>>>` is neither `Send` nor `Sync` = help: if the `Arc` will not used be across threads replace it with an `Rc` = help: otherwise make `Mutex<ClientContext<Impl<DbStorage<MemoryStore>, NodeProvider, JsSigner>, Memory<Wallet>>>` `Send` and `Sync` or consider a wrapper type such as `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `#[warn(clippy::arc_with_non_send_sync)]` on by default ``` ## Proposal Fix the lints: - use `num_traits` to do the cast safely - remove the redundant question mark - disable the warning, which requires a new type parameter on `ChainListener` to fix (we're hoping `ChainListener` won't be around much longer anyway) Add Clippy on the Web to CI to prevent this in the future. ## Test Plan CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist) - Fixes #4113.
1 parent 85009b0 commit 5e90da3

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ jobs:
248248
run: |
249249
ln -sf toolchains/nightly/rust-toolchain.toml
250250
- uses: actions-rust-lang/setup-rust-toolchain@v1
251-
- name: Compile `linera-web` for the browser
252-
run: |
251+
- name: Check `linera-web` for the browser
252+
run: |
253253
cd linera-web
254+
cargo clippy
254255
cargo build
255256
- name: Install chromedriver
256257
uses: nanasess/setup-chromedriver@v2

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-web/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ js-sys.workspace = true
2020
linera-persistent.workspace = true
2121
log.workspace = true
2222
nonzero_lit.workspace = true
23+
num-traits.workspace = true
2324
serde.workspace = true
2425
serde-wasm-bindgen.workspace = true
2526
tokio-util.workspace = true

linera-web/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ impl Client {
199199
.genesis_config()
200200
.initialize_storage(&mut storage)
201201
.await?;
202+
// The `Arc` here is useless, but it is required by the `ChainListener` API.
203+
#[expect(clippy::arc_with_non_send_sync)]
202204
let client_context = Arc::new(AsyncMutex::new(ClientContext::new(
203205
storage.clone(),
204206
OPTIONS,

linera-web/src/signer.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@ impl Display for JsSignerError {
4747

4848
impl From<JsValue> for JsSignerError {
4949
fn from(value: JsValue) -> Self {
50-
if let Some(fnum) = value.as_f64() {
51-
match fnum as u8 {
52-
0 => JsSignerError::MissingKey,
53-
1 => JsSignerError::SigningError,
54-
2 => JsSignerError::PublicKeyParse,
55-
3 => JsSignerError::JsConversion,
56-
4 => JsSignerError::UnexpectedSignatureFormat,
57-
5 => JsSignerError::InvalidAccountOwnerType,
58-
_ => JsSignerError::Unknown,
59-
}
60-
} else {
61-
JsSignerError::Unknown
50+
match value.as_f64().and_then(num_traits::cast) {
51+
Some(0u8) => JsSignerError::MissingKey,
52+
Some(1) => JsSignerError::SigningError,
53+
Some(2) => JsSignerError::PublicKeyParse,
54+
Some(3) => JsSignerError::JsConversion,
55+
Some(4) => JsSignerError::UnexpectedSignatureFormat,
56+
Some(5) => JsSignerError::InvalidAccountOwnerType,
57+
_ => JsSignerError::Unknown,
6258
}
6359
}
6460
}
@@ -95,7 +91,7 @@ impl Signer for JsSigner {
9591
.await
9692
.map_err(JsSignerError::from)?;
9793

98-
Ok(serde_wasm_bindgen::from_value(js_bool).map_err(|_| JsSignerError::JsConversion)?)
94+
serde_wasm_bindgen::from_value(js_bool).map_err(|_| JsSignerError::JsConversion)
9995
}
10096

10197
async fn sign(

0 commit comments

Comments
 (0)