Skip to content

Commit 0de0226

Browse files
committed
fix: clippy fixes for collapsing if-statements
1 parent 12a446e commit 0de0226

15 files changed

Lines changed: 293 additions & 314 deletions

File tree

crates/rmcp-macros/src/common.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,15 @@ pub fn extract_doc_line(
5555
/// Returns the full Parameters<T> type if found
5656
pub fn find_parameters_type_in_sig(sig: &Signature) -> Option<Box<Type>> {
5757
sig.inputs.iter().find_map(|input| {
58-
if let FnArg::Typed(pat_type) = input {
59-
if let Type::Path(type_path) = &*pat_type.ty {
60-
if type_path
61-
.path
62-
.segments
63-
.last()
64-
.is_some_and(|type_name| type_name.ident == "Parameters")
65-
{
66-
return Some(pat_type.ty.clone());
67-
}
68-
}
58+
if let FnArg::Typed(pat_type) = input
59+
&& let Type::Path(type_path) = &*pat_type.ty
60+
&& type_path
61+
.path
62+
.segments
63+
.last()
64+
.is_some_and(|type_name| type_name.ident == "Parameters")
65+
{
66+
return Some(pat_type.ty.clone());
6967
}
7068
None
7169
})

crates/rmcp-macros/src/prompt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ pub fn prompt(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream>
132132
// 3. make body: { Box::pin(async move { #body }) }
133133
let new_output = syn::parse2::<ReturnType>({
134134
let mut lt = quote! { 'static };
135-
if let Some(receiver) = fn_item.sig.receiver() {
136-
if let Some((_, receiver_lt)) = receiver.reference.as_ref() {
137-
if let Some(receiver_lt) = receiver_lt {
138-
lt = quote! { #receiver_lt };
139-
} else {
140-
lt = quote! { '_ };
141-
}
135+
if let Some(receiver) = fn_item.sig.receiver()
136+
&& let Some((_, receiver_lt)) = receiver.reference.as_ref()
137+
{
138+
if let Some(receiver_lt) = receiver_lt {
139+
lt = quote! { #receiver_lt };
140+
} else {
141+
lt = quote! { '_ };
142142
}
143143
}
144144
match &fn_item.sig.output {

crates/rmcp-macros/src/tool.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ use crate::common::extract_doc_line;
77

88
/// Check if a type is Json<T> and extract the inner type T
99
fn extract_json_inner_type(ty: &syn::Type) -> Option<&syn::Type> {
10-
if let syn::Type::Path(type_path) = ty {
11-
if let Some(last_segment) = type_path.path.segments.last() {
12-
if last_segment.ident == "Json" {
13-
if let syn::PathArguments::AngleBracketed(args) = &last_segment.arguments {
14-
if let Some(syn::GenericArgument::Type(inner_type)) = args.args.first() {
15-
return Some(inner_type);
16-
}
17-
}
18-
}
19-
}
10+
if let syn::Type::Path(type_path) = ty
11+
&& let Some(last_segment) = type_path.path.segments.last()
12+
&& last_segment.ident == "Json"
13+
&& let syn::PathArguments::AngleBracketed(args) = &last_segment.arguments
14+
&& let Some(syn::GenericArgument::Type(inner_type)) = args.args.first()
15+
{
16+
return Some(inner_type);
2017
}
2118
None
2219
}
@@ -286,13 +283,13 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
286283
let omit_send = cfg!(feature = "local") || attribute.local;
287284
let new_output = syn::parse2::<ReturnType>({
288285
let mut lt = quote! { 'static };
289-
if let Some(receiver) = fn_item.sig.receiver() {
290-
if let Some((_, receiver_lt)) = receiver.reference.as_ref() {
291-
if let Some(receiver_lt) = receiver_lt {
292-
lt = quote! { #receiver_lt };
293-
} else {
294-
lt = quote! { '_ };
295-
}
286+
if let Some(receiver) = fn_item.sig.receiver()
287+
&& let Some((_, receiver_lt)) = receiver.reference.as_ref()
288+
{
289+
if let Some(receiver_lt) = receiver_lt {
290+
lt = quote! { #receiver_lt };
291+
} else {
292+
lt = quote! { '_ };
296293
}
297294
}
298295
match &fn_item.sig.output {

crates/rmcp/src/handler/server/router/tool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ where
550550
}
551551

552552
fn notify_if_visible(&self, name: &str) {
553-
if self.map.contains_key(name) {
554-
if let Some(notifier) = &self.notifier {
555-
notifier();
556-
}
553+
if self.map.contains_key(name)
554+
&& let Some(notifier) = &self.notifier
555+
{
556+
notifier();
557557
}
558558
}
559559

crates/rmcp/src/model/elicitation_schema.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,15 @@ impl EnumSchemaBuilder<MultiSelect> {
983983
return Err("One of the provided default values is not in enum values".to_string());
984984
}
985985
}
986-
if let Some(min) = self.min_items {
987-
if (default_values.len() as u64) < min {
988-
return Err("Number of provided default values is less than min_items".to_string());
989-
}
986+
if let Some(min) = self.min_items
987+
&& (default_values.len() as u64) < min
988+
{
989+
return Err("Number of provided default values is less than min_items".to_string());
990990
}
991-
if let Some(max) = self.max_items {
992-
if (default_values.len() as u64) > max {
993-
return Err(
994-
"Number of provided default values is greater than max_items".to_string(),
995-
);
996-
}
991+
if let Some(max) = self.max_items
992+
&& (default_values.len() as u64) > max
993+
{
994+
return Err("Number of provided default values is greater than max_items".to_string());
997995
}
998996
self.default = default_values;
999997
Ok(self)

crates/rmcp/src/service.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,10 @@ impl<R: ServiceRole> RequestHandle<R> {
554554
None => None,
555555
}
556556
}, if reset_timeout_on_progress && idle_sleep.is_some() && self.progress_reset_rx.is_some() => {
557-
if progress.is_some() {
558-
if let Some((timeout, sleep)) = idle_sleep.as_mut() {
557+
if progress.is_some()
558+
&& let Some((timeout, sleep)) = idle_sleep.as_mut() {
559559
sleep.as_mut().reset(tokio::time::Instant::now() + *timeout);
560560
}
561-
}
562561
}
563562
}
564563
}
@@ -1351,11 +1350,10 @@ where
13511350
tracing::trace!(?evt, "new event");
13521351
match evt {
13531352
Event::SendTaskResult(SendTaskResult::Request { id, result }) => {
1354-
if let Err(e) = result {
1355-
if let Some(responder) = local_responder_pool.remove(&id) {
1353+
if let Err(e) = result
1354+
&& let Some(responder) = local_responder_pool.remove(&id) {
13561355
let _ = responder.send(Err(ServiceError::TransportSend(e)));
13571356
}
1358-
}
13591357
}
13601358
Event::SendTaskResult(SendTaskResult::Notification {
13611359
responder,
@@ -1368,16 +1366,14 @@ where
13681366
Ok(())
13691367
};
13701368
let _ = responder.send(response);
1371-
if let Some(param) = cancellation_param {
1372-
if let Some(request_id) = &param.request_id {
1373-
if let Some(responder) = local_responder_pool.remove(request_id) {
1369+
if let Some(param) = cancellation_param
1370+
&& let Some(request_id) = &param.request_id
1371+
&& let Some(responder) = local_responder_pool.remove(request_id) {
13741372
tracing::info!(id = %request_id, reason = param.reason, "cancelled");
13751373
let _response_result = responder.send(Err(ServiceError::Cancelled {
13761374
reason: param.reason.clone(),
13771375
}));
13781376
}
1379-
}
1380-
}
13811377
}
13821378
Event::ResponseSendTaskResult(result) => {
13831379
if let Err(error) = result {

crates/rmcp/src/transport/async_rw.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,12 @@ fn try_parse_with_compatibility<T: serde::de::DeserializeOwned>(
320320
Ok(item) => Ok(Some(item)),
321321
Err(e) => {
322322
// Check if this is a notification that should be ignored for compatibility
323-
if let Ok(json_value) = serde_json::from_str::<serde_json::Value>(line_str) {
324-
if let Some(method) =
323+
if let Ok(json_value) = serde_json::from_str::<serde_json::Value>(line_str)
324+
&& let Some(method) =
325325
json_value.get("method").and_then(serde_json::Value::as_str)
326-
{
327-
if should_ignore_notification(&json_value, method) {
328-
return Ok(None);
329-
}
330-
}
326+
&& should_ignore_notification(&json_value, method)
327+
{
328+
return Ok(None);
331329
}
332330

333331
tracing::debug!(

crates/rmcp/src/transport/auth.rs

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,56 +1248,56 @@ impl AuthorizationManager {
12481248
/// the client if credentials are found. Returns `false` when credentials
12491249
/// are absent or discarded after an authorization-server change.
12501250
pub async fn initialize_from_store(&mut self) -> Result<bool, AuthError> {
1251-
if let Some(stored) = self.credential_store.load().await? {
1252-
if stored.token_response.is_some() {
1253-
if self.metadata.is_none() {
1254-
let metadata = self.discover_metadata().await?;
1255-
self.metadata = Some(metadata);
1256-
}
1257-
1258-
if let (Some(stored_issuer), Some(current_issuer)) =
1259-
(stored.issuer.as_deref(), self.metadata_issuer().as_deref())
1260-
{
1261-
// A CIMD client ID is the client's metadata URL, so it is
1262-
// portable across authorization servers and exempt here.
1263-
if stored_issuer != current_issuer {
1264-
if is_https_url(&stored.client_id) {
1265-
// A CIMD client ID is the client's metadata URL, so it is
1266-
// portable across authorization servers — but the tokens
1267-
// were minted by the previous AS and must not be reused.
1268-
tracing::warn!(
1269-
stored_issuer,
1270-
current_issuer,
1271-
"authorization server issuer changed; discarding tokens but keeping portable CIMD client ID"
1272-
);
1273-
self.credential_store
1274-
.save(
1275-
StoredCredentials::new(
1276-
stored.client_id.clone(),
1277-
None,
1278-
vec![],
1279-
None,
1280-
)
1281-
.with_issuer(self.metadata_issuer()),
1282-
)
1283-
.await?;
1284-
self.configure_client_id(&stored.client_id)?;
1285-
return Ok(false);
1286-
}
1251+
if let Some(stored) = self.credential_store.load().await?
1252+
&& stored.token_response.is_some()
1253+
{
1254+
if self.metadata.is_none() {
1255+
let metadata = self.discover_metadata().await?;
1256+
self.metadata = Some(metadata);
1257+
}
12871258

1259+
if let (Some(stored_issuer), Some(current_issuer)) =
1260+
(stored.issuer.as_deref(), self.metadata_issuer().as_deref())
1261+
{
1262+
// A CIMD client ID is the client's metadata URL, so it is
1263+
// portable across authorization servers and exempt here.
1264+
if stored_issuer != current_issuer {
1265+
if is_https_url(&stored.client_id) {
1266+
// A CIMD client ID is the client's metadata URL, so it is
1267+
// portable across authorization servers — but the tokens
1268+
// were minted by the previous AS and must not be reused.
12881269
tracing::warn!(
12891270
stored_issuer,
12901271
current_issuer,
1291-
"authorization server issuer changed; clearing stored credentials bound to the previous issuer"
1272+
"authorization server issuer changed; discarding tokens but keeping portable CIMD client ID"
12921273
);
1293-
self.credential_store.clear().await?;
1274+
self.credential_store
1275+
.save(
1276+
StoredCredentials::new(
1277+
stored.client_id.clone(),
1278+
None,
1279+
vec![],
1280+
None,
1281+
)
1282+
.with_issuer(self.metadata_issuer()),
1283+
)
1284+
.await?;
1285+
self.configure_client_id(&stored.client_id)?;
12941286
return Ok(false);
12951287
}
1296-
}
12971288

1298-
self.configure_client_id(&stored.client_id)?;
1299-
return Ok(true);
1289+
tracing::warn!(
1290+
stored_issuer,
1291+
current_issuer,
1292+
"authorization server issuer changed; clearing stored credentials bound to the previous issuer"
1293+
);
1294+
self.credential_store.clear().await?;
1295+
return Ok(false);
1296+
}
13001297
}
1298+
1299+
self.configure_client_id(&stored.client_id)?;
1300+
return Ok(true);
13011301
}
13021302
Ok(false)
13031303
}
@@ -1425,10 +1425,10 @@ impl AuthorizationManager {
14251425

14261426
// RFC 8414 RECOMMENDS response_types_supported in the metadata. This field is optional,
14271427
// but if present and does not include the flow we use ("code"), bail out early with a clear error.
1428-
if let Some(response_types_supported) = metadata.response_types_supported.as_ref() {
1429-
if !response_types_supported.contains(&response_type.to_string()) {
1430-
return Err(AuthError::InvalidScope(response_type.to_string()));
1431-
}
1428+
if let Some(response_types_supported) = metadata.response_types_supported.as_ref()
1429+
&& !response_types_supported.contains(&response_type.to_string())
1430+
{
1431+
return Err(AuthError::InvalidScope(response_type.to_string()));
14321432
}
14331433

14341434
// The client always sends an S256 challenge. A server that advertises
@@ -1713,12 +1713,11 @@ impl AuthorizationManager {
17131713
}
17141714

17151715
// nothing requested or challenged yet: seed from AS metadata, then caller defaults
1716-
if let Some(metadata) = &self.metadata {
1717-
if let Some(scopes_supported) = &metadata.scopes_supported {
1718-
if !scopes_supported.is_empty() {
1719-
return scopes_supported.clone();
1720-
}
1721-
}
1716+
if let Some(metadata) = &self.metadata
1717+
&& let Some(scopes_supported) = &metadata.scopes_supported
1718+
&& !scopes_supported.is_empty()
1719+
{
1720+
return scopes_supported.clone();
17221721
}
17231722

17241723
default_scopes.iter().map(|s| s.to_string()).collect()
@@ -1730,12 +1729,11 @@ impl AuthorizationManager {
17301729
if scopes.is_empty() || scopes.iter().any(|s| s == "offline_access") {
17311730
return;
17321731
}
1733-
if let Some(metadata) = &self.metadata {
1734-
if let Some(supported) = &metadata.scopes_supported {
1735-
if supported.iter().any(|s| s == "offline_access") {
1736-
scopes.push("offline_access".to_string());
1737-
}
1738-
}
1732+
if let Some(metadata) = &self.metadata
1733+
&& let Some(supported) = &metadata.scopes_supported
1734+
&& supported.iter().any(|s| s == "offline_access")
1735+
{
1736+
scopes.push("offline_access".to_string());
17391737
}
17401738
}
17411739

@@ -2255,10 +2253,10 @@ impl AuthorizationManager {
22552253
self.validate_resource_metadata_resource(&resource_metadata)?;
22562254

22572255
// store scopes_supported from protected resource metadata for select_scopes()
2258-
if let Some(scopes) = resource_metadata.scopes_supported {
2259-
if !scopes.is_empty() {
2260-
*self.resource_scopes.write().await = scopes;
2261-
}
2256+
if let Some(scopes) = resource_metadata.scopes_supported
2257+
&& !scopes.is_empty()
2258+
{
2259+
*self.resource_scopes.write().await = scopes;
22622260
}
22632261

22642262
let mut candidates = Vec::new();
@@ -2701,20 +2699,18 @@ impl AuthorizationManager {
27012699
if let ClientCredentialsConfig::PrivateKeyJwt {
27022700
signing_algorithm, ..
27032701
} = config
2704-
{
2705-
if let Some(algs) = metadata
2702+
&& let Some(algs) = metadata
27062703
.additional_fields
27072704
.get("token_endpoint_auth_signing_alg_values_supported")
27082705
.and_then(|v| v.as_array())
2709-
{
2710-
let alg_str = signing_algorithm.as_str();
2711-
if !algs.iter().any(|a| a.as_str() == Some(alg_str)) {
2712-
let supported: Vec<&str> = algs.iter().filter_map(|a| a.as_str()).collect();
2713-
return Err(AuthError::ClientCredentialsError(format!(
2714-
"Authorization server does not support signing algorithm '{}'. Supported: {:?}",
2715-
alg_str, supported
2716-
)));
2717-
}
2706+
{
2707+
let alg_str = signing_algorithm.as_str();
2708+
if !algs.iter().any(|a| a.as_str() == Some(alg_str)) {
2709+
let supported: Vec<&str> = algs.iter().filter_map(|a| a.as_str()).collect();
2710+
return Err(AuthError::ClientCredentialsError(format!(
2711+
"Authorization server does not support signing algorithm '{}'. Supported: {:?}",
2712+
alg_str, supported
2713+
)));
27182714
}
27192715
}
27202716

0 commit comments

Comments
 (0)