Skip to content

Commit 83bfd85

Browse files
committed
Fix clippy issues, enforce in CI
We weren't checking for any clippy issues. This fixes most of them and adds a few exceptions for ones not worth fixing or ones that will be fixed with future changes.
1 parent 1f4adce commit 83bfd85

16 files changed

Lines changed: 113 additions & 198 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
run: |
2929
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ matrix.toolchain }}
3030
rustup override set ${{ matrix.toolchain }}
31+
if [ "${{ matrix.msrv }}" = "true" ]; then rustup component add clippy; fi
3132
- name: Check formatting
3233
if: matrix.check-fmt
3334
run: rustup component add rustfmt && cargo fmt --all -- --check
@@ -37,6 +38,9 @@ jobs:
3738
echo "No packages need pinning for MSRV ${{ matrix.toolchain }}"
3839
- name: Build on Rust ${{ matrix.toolchain }}
3940
run: cargo build --verbose --color always
41+
- name: Check clippy if on msrv
42+
if: matrix.msrv
43+
run: cargo clippy --all-features -- -D warnings
4044
- name: Test on Rust ${{ matrix.toolchain }}
4145
run: cargo test
4246
- name: Cargo check release on Rust ${{ matrix.toolchain }}

ldk-server-protos/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ edition = "2021"
55

66
build = "build.rs"
77

8+
# We use a cfg instead of a feature for genproto to prevent it from being
9+
# enabled with --all-features. Proto generation is a developer-only tool that
10+
# requires external dependencies (protoc) and shouldn't be triggered accidentally.
11+
# This lint configuration tells Cargo that genproto is an expected custom cfg.
12+
[lints.rust]
13+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(genproto)'] }
14+
815
[features]
916
default = []
1017
serde = ["dep:serde", "dep:bytes"]

ldk-server/src/api/bolt11_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::str::FromStr;
1818
pub(crate) fn handle_bolt11_send_request(
1919
context: Context, request: Bolt11SendRequest,
2020
) -> Result<Bolt11SendResponse, LdkServerError> {
21-
let invoice = Bolt11Invoice::from_str(&request.invoice.as_str())
21+
let invoice = Bolt11Invoice::from_str(request.invoice.as_str())
2222
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;
2323

2424
let route_parameters = match request.route_parameters {

ldk-server/src/api/bolt12_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn handle_bolt12_send_request(
1919
context: Context, request: Bolt12SendRequest,
2020
) -> Result<Bolt12SendResponse, LdkServerError> {
2121
let offer =
22-
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
22+
Offer::from_str(request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
2323

2424
let route_parameters = match request.route_parameters {
2525
Some(params) => {

ldk-server/src/api/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ impl fmt::Display for LdkServerError {
3838
}
3939

4040
#[derive(Clone, Debug, PartialEq, Eq)]
41+
#[allow(clippy::enum_variant_names)]
4142
pub(crate) enum LdkServerErrorCode {
4243
/// Please refer to [`protos::error::ErrorCode::InvalidRequestError`].
4344
InvalidRequestError,
4445

45-
/// Please refer to [`protos::error::ErrorCode::AuthError`].
46-
AuthError,
47-
4846
/// Please refer to [`protos::error::ErrorCode::LightningError`].
4947
LightningError,
5048

@@ -56,7 +54,6 @@ impl fmt::Display for LdkServerErrorCode {
5654
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5755
match self {
5856
LdkServerErrorCode::InvalidRequestError => write!(f, "InvalidRequestError"),
59-
LdkServerErrorCode::AuthError => write!(f, "AuthError"),
6057
LdkServerErrorCode::LightningError => write!(f, "LightningError"),
6158
LdkServerErrorCode::InternalServerError => write!(f, "InternalServerError"),
6259
}

ldk-server/src/api/get_payment_details.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ pub(crate) fn handle_get_payment_details_request(
2828

2929
let payment_details = context.node.payment(&PaymentId(payment_id_bytes));
3030

31-
let response = GetPaymentDetailsResponse {
32-
payment: payment_details.map(|payment| payment_to_proto(payment)),
33-
};
31+
let response = GetPaymentDetailsResponse { payment: payment_details.map(payment_to_proto) };
3432

3533
Ok(response)
3634
}

ldk-server/src/api/list_channels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ldk_server_protos::api::{ListChannelsRequest, ListChannelsResponse};
1515
pub(crate) fn handle_list_channels_request(
1616
context: Context, _request: ListChannelsRequest,
1717
) -> Result<ListChannelsResponse, LdkServerError> {
18-
let channels = context.node.list_channels().into_iter().map(|c| channel_to_proto(c)).collect();
18+
let channels = context.node.list_channels().into_iter().map(channel_to_proto).collect();
1919

2020
let response = ListChannelsResponse { channels };
2121
Ok(response)

ldk-server/src/api/onchain_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn handle_onchain_send_request(
2727
)
2828
})?;
2929

30-
let fee_rate = request.fee_rate_sat_per_vb.map(FeeRate::from_sat_per_vb).flatten();
30+
let fee_rate = request.fee_rate_sat_per_vb.and_then(FeeRate::from_sat_per_vb);
3131
let txid = match (request.amount_sats, request.send_all) {
3232
(Some(amount_sats), None) => {
3333
context.node.onchain_payment().send_to_address(&address, amount_sats, fee_rate)?

ldk-server/src/io/events/event_publisher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ pub trait EventPublisher: Send + Sync {
5050
async fn publish(&self, event: EventEnvelope) -> Result<(), LdkServerError>;
5151
}
5252

53+
/// A no-op implementation of the [`EventPublisher`] trait.
54+
#[cfg(not(feature = "events-rabbitmq"))]
5355
pub(crate) struct NoopEventPublisher;
5456

5557
#[async_trait]
58+
#[cfg(not(feature = "events-rabbitmq"))]
5659
impl EventPublisher for NoopEventPublisher {
5760
/// Publishes an event to a no-op sink, effectively discarding it.
5861
///

ldk-server/src/io/persist/paginated_kv_store.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,6 @@ pub trait PaginatedKVStore: Send + Sync {
5858
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, time: i64, buf: &[u8],
5959
) -> Result<(), io::Error>;
6060

61-
/// Removes any data that had previously been persisted under the given `key`.
62-
///
63-
/// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
64-
/// remove the given `key` at some point in time after the method returns, e.g., as part of an
65-
/// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
66-
/// [`PaginatedKVStore::list`] might include the removed key until the changes are actually persisted.
67-
///
68-
/// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
69-
/// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
70-
/// potentially get lost on crash after the method returns. Therefore, this flag should only be
71-
/// set for `remove` operations that can be safely replayed at a later time.
72-
///
73-
/// Returns successfully if no data will be stored for the given `primary_namespace`,
74-
/// `secondary_namespace`, and `key`, independently of whether it was present before its
75-
/// invocation or not.
76-
fn remove(
77-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
78-
) -> Result<(), io::Error>;
79-
8061
/// Returns a paginated list of keys that are stored under the given `secondary_namespace` in
8162
/// `primary_namespace`, ordered in descending order of `time`.
8263
///

0 commit comments

Comments
 (0)