Skip to content

Add new cgp-field crate for deriving HasField field accessors #9

Add new cgp-field crate for deriving HasField field accessors

Add new cgp-field crate for deriving HasField field accessors #9

GitHub Actions / clippy-all-features failed Jul 4, 2024 in 0s

clippy-all-features

1 error

Details

Results

Message level Amount
Internal compiler error 0
Error 1
Warning 0
Note 0
Help 0

Versions

  • rustc 1.79.0 (129f3b996 2024-06-10)
  • cargo 1.79.0 (ffa9cf99a 2024-06-03)
  • clippy 0.1.79 (129f3b9 2024-06-10)

Annotations

Check failure on line 44 in crates/cgp-field-macro-lib/src/field.rs

See this annotation in the file changed.

@github-actions github-actions / clippy-all-features

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
  --> crates/cgp-field-macro-lib/src/field.rs:14:5
   |
14 | /     match &item_struct.fields {
15 | |         Fields::Named(fields) => {
16 | |             for field in fields.named.iter() {
17 | |                 let field_ident = field.ident.as_ref().unwrap();
...  |
43 | |         _ => {}
44 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
   = note: `-D clippy::single-match` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::single_match)]`
help: try
   |
14 ~     if let Fields::Named(fields) = &item_struct.fields {
15 +         for field in fields.named.iter() {
16 +             let field_ident = field.ident.as_ref().unwrap();
17 + 
18 +             let field_symbol = symbol_from_string(&field_ident.to_string());
19 + 
20 +             let field_type = &field.ty;
21 + 
22 +             let item_impl: ItemImpl = parse_quote! {
23 +                 impl #impl_generics HasField< #field_symbol >
24 +                     for #struct_ident #ty_generics
25 +                 #where_clause
26 +                 {
27 +                     type Field = #field_type;
28 + 
29 +                     fn get_field(
30 +                         &self,
31 +                         key: ::core::marker::PhantomData< #field_symbol >,
32 +                     ) -> &Self::Field
33 +                     {
34 +                         &self. #field_ident
35 +                     }
36 +                 }
37 +             };
38 + 
39 +             item_impls.push(item_impl);
40 +         }
41 +     }
   |