Skip to content

Commit e11cff8

Browse files
committed
Fix clippy warnings in WpDeriveParamsField macro
Address clippy issues identified in cargo clippy --tests: Changes: - Remove redundant enum variant prefixes (AppendQueryMethod variants) - Collapse nested if statements in is_wp_date_time_option method using let-chain patterns - Update all enum variant references and test assertions
1 parent bcb879a commit e11cff8

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

wp_derive/src/params_field.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ enum FromQueryMethod {
4343

4444
#[derive(Debug, Clone, Copy)]
4545
enum AppendQueryMethod {
46-
AppendValue,
47-
AppendOption,
48-
AppendVec,
46+
Value,
47+
Option,
48+
Vec,
4949
}
5050

5151
impl ParsedParamsStruct {
@@ -308,23 +308,23 @@ impl ParsedParamsStruct {
308308

309309
// Otherwise use auto-detection
310310
match field.detect_append_query_method() {
311-
AppendQueryMethod::AppendOption => {
311+
AppendQueryMethod::Option => {
312312
quote! {
313313
append_option_query_value_pair(
314314
#enum_name::#variant_name,
315315
self.#field_ident.as_ref()
316316
)
317317
}
318318
}
319-
AppendQueryMethod::AppendVec => {
319+
AppendQueryMethod::Vec => {
320320
quote! {
321321
append_vec_query_value_pair(
322322
#enum_name::#variant_name,
323323
&self.#field_ident
324324
)
325325
}
326326
}
327-
AppendQueryMethod::AppendValue => {
327+
AppendQueryMethod::Value => {
328328
quote! {
329329
append_query_value_pair(
330330
#enum_name::#variant_name,
@@ -429,29 +429,26 @@ impl ParsedField {
429429
syn::Type::Path(type_path) => {
430430
if let Some(last_segment) = type_path.path.segments.last() {
431431
match last_segment.ident.to_string().as_str() {
432-
"Option" => AppendQueryMethod::AppendOption,
433-
"Vec" => AppendQueryMethod::AppendVec,
434-
_ => AppendQueryMethod::AppendValue, // fallback for non-generic types
432+
"Option" => AppendQueryMethod::Option,
433+
"Vec" => AppendQueryMethod::Vec,
434+
_ => AppendQueryMethod::Value, // fallback for non-generic types
435435
}
436436
} else {
437-
AppendQueryMethod::AppendValue
437+
AppendQueryMethod::Value
438438
}
439439
}
440-
_ => AppendQueryMethod::AppendValue, // fallback for other types
440+
_ => AppendQueryMethod::Value, // fallback for other types
441441
}
442442
}
443443

444444
/// Check if this field is Option<WpGmtDateTime>
445445
fn is_wp_date_time_option(&self, option_segment: &syn::PathSegment) -> bool {
446446
// Check if Option has generic arguments
447-
if let syn::PathArguments::AngleBracketed(ref args) = option_segment.arguments {
448-
if let Some(syn::GenericArgument::Type(inner_type)) = args.args.first() {
449-
if let syn::Type::Path(inner_path) = inner_type {
450-
if let Some(last_segment) = inner_path.path.segments.last() {
451-
return last_segment.ident == "WpGmtDateTime";
452-
}
453-
}
454-
}
447+
if let syn::PathArguments::AngleBracketed(ref args) = option_segment.arguments
448+
&& let Some(syn::GenericArgument::Type(syn::Type::Path(inner_path))) = args.args.first()
449+
&& let Some(last_segment) = inner_path.path.segments.last()
450+
{
451+
return last_segment.ident == "WpGmtDateTime";
455452
}
456453
false
457454
}
@@ -509,7 +506,7 @@ mod tests {
509506
));
510507
assert!(matches!(
511508
field.detect_append_query_method(),
512-
AppendQueryMethod::AppendOption
509+
AppendQueryMethod::Option
513510
));
514511
}
515512

@@ -530,7 +527,7 @@ mod tests {
530527
));
531528
assert!(matches!(
532529
field.detect_append_query_method(),
533-
AppendQueryMethod::AppendVec
530+
AppendQueryMethod::Vec
534531
));
535532
}
536533

@@ -551,7 +548,7 @@ mod tests {
551548
));
552549
assert!(matches!(
553550
field.detect_append_query_method(),
554-
AppendQueryMethod::AppendOption
551+
AppendQueryMethod::Option
555552
));
556553
}
557554

@@ -572,7 +569,7 @@ mod tests {
572569
));
573570
assert!(matches!(
574571
field.detect_append_query_method(),
575-
AppendQueryMethod::AppendValue
572+
AppendQueryMethod::Value
576573
));
577574
}
578575
}

0 commit comments

Comments
 (0)