Skip to content

Commit 28b12ce

Browse files
committed
fix fmt
1 parent 127c0e6 commit 28b12ce

File tree

6 files changed

+58
-53
lines changed

6 files changed

+58
-53
lines changed

crates/ast_node/src/encoding/decode.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
66
match data {
77
Data::Struct(data) => {
88
let is_named = data.fields.iter().any(|field| field.ident.is_some());
9-
let names = data.fields.iter()
9+
let names = data
10+
.fields
11+
.iter()
1012
.enumerate()
1113
.map(|(idx, field)| match field.ident.as_ref() {
1214
Some(name) => name.clone(),
1315
None => {
1416
let name = format!("unit{idx}");
15-
let name = syn::Ident::new(&name, field.span());
16-
name
17+
syn::Ident::new(&name, field.span())
1718
}
1819
})
1920
.collect::<Vec<_>>();
@@ -31,13 +32,11 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
3132
let #field_name = #value;
3233
}
3334
});
34-
let build_struct: syn::Expr = is_named
35-
.then(|| syn::parse_quote! {
36-
#ident { #(#names),* }
37-
})
38-
.unwrap_or_else(|| syn::parse_quote! {
39-
#ident ( #(#names),* )
40-
});
35+
let build_struct: syn::Expr = if is_named {
36+
syn::parse_quote! { #ident { #(#names),* } }
37+
} else {
38+
syn::parse_quote! { #ident ( #(#names),* ) }
39+
};
4140

4241
let count = data.fields.len();
4342
let head: Option<syn::Expr> = (count != 1).then(|| {
@@ -61,28 +60,30 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
6160
}
6261
}
6362
Data::Enum(data) => {
64-
let enum_type = data.variants.iter()
65-
.filter(|v| !is_unknown(&v.attrs))
66-
.fold(None, |mut sum, next| {
63+
let enum_type = data.variants.iter().filter(|v| !is_unknown(&v.attrs)).fold(
64+
None,
65+
|mut sum, next| {
6766
let ty = match &next.fields {
6867
syn::Fields::Named(_) => EnumType::Struct,
6968
syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => EnumType::One,
7069
syn::Fields::Unit => EnumType::Unit,
71-
syn::Fields::Unnamed(_) => panic!("more than 1 unnamed member field are not allowed")
70+
syn::Fields::Unnamed(_) => {
71+
panic!("more than 1 unnamed member field are not allowed")
72+
}
7273
};
7374
match (*sum.get_or_insert(ty), ty) {
7475
(EnumType::Struct, EnumType::Struct)
75-
| (EnumType::Struct, EnumType::Unit)
76-
| (EnumType::Unit, EnumType::Unit)
77-
| (EnumType::One, EnumType::One)
78-
=> (),
76+
| (EnumType::Struct, EnumType::Unit)
77+
| (EnumType::Unit, EnumType::Unit)
78+
| (EnumType::One, EnumType::One) => (),
7979
(EnumType::Unit, EnumType::One)
8080
| (EnumType::One, EnumType::Unit)
8181
| (_, EnumType::Struct) => sum = Some(EnumType::Struct),
82-
_ => panic!("enum member types must be consistent: {:?} {:?}", sum, ty),
82+
_ => panic!("enum member types must be consistent: {:?}", (sum, ty)),
8383
}
8484
sum
85-
});
85+
},
86+
);
8687
let enum_type = enum_type.expect("enum cannot be empty");
8788
let mut iter = data.variants.iter().peekable();
8889

@@ -126,7 +127,10 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
126127
});
127128

128129
if matches!(enum_type, EnumType::Struct) {
129-
assert!(unknown_arm.is_none(), "struct enum does not allow unknown variants");
130+
assert!(
131+
unknown_arm.is_none(),
132+
"struct enum does not allow unknown variants"
133+
);
130134
}
131135

132136
let fields = iter
@@ -167,8 +171,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
167171
Some(name) => name.clone(),
168172
None => {
169173
let name = format!("unit{idx}");
170-
let name = syn::Ident::new(&name, field.span());
171-
name
174+
syn::Ident::new(&name, field.span())
172175
}
173176
})
174177
.collect::<Vec<_>>();
@@ -187,22 +190,20 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
187190
}
188191
}
189192
});
190-
let build_struct: syn::Expr = is_named
191-
.then(|| syn::parse_quote! {
192-
#ident::#name { #(#names),* }
193-
})
194-
.unwrap_or_else(|| syn::parse_quote! {
195-
#ident::#name ( #(#names),* )
196-
});
197-
193+
let build_struct: syn::Expr = if is_named {
194+
syn::parse_quote! { #ident::#name { #(#names),* } }
195+
} else {
196+
syn::parse_quote! { #ident::#name ( #(#names),* ) }
197+
};
198+
198199
syn::parse_quote!{
199200
#idx => {
200201
let len = cbor4ii::core::types::Array::len(reader)?;
201202
debug_assert_eq!(len, Some(#num));
202203
#(#stmt)*
203204
#build_struct
204205
},
205-
}
206+
}
206207
}
207208
}
208209
});

crates/ast_node/src/encoding/encode.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,30 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
4949
}
5050
}
5151
Data::Enum(data) => {
52-
let enum_type = data.variants.iter()
53-
.filter(|v| !is_unknown(&v.attrs))
54-
.fold(None, |mut sum, next| {
52+
let enum_type = data.variants.iter().filter(|v| !is_unknown(&v.attrs)).fold(
53+
None,
54+
|mut sum, next| {
5555
let ty = match &next.fields {
5656
syn::Fields::Named(_) => EnumType::Struct,
5757
syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => EnumType::One,
5858
syn::Fields::Unit => EnumType::Unit,
59-
syn::Fields::Unnamed(_) => panic!("more than 1 unnamed member field are not allowed")
59+
syn::Fields::Unnamed(_) => {
60+
panic!("more than 1 unnamed member field are not allowed")
61+
}
6062
};
6163
match (*sum.get_or_insert(ty), ty) {
6264
(EnumType::Struct, EnumType::Struct)
63-
| (EnumType::Struct, EnumType::Unit)
64-
| (EnumType::Unit, EnumType::Unit)
65-
| (EnumType::One, EnumType::One)
66-
=> (),
65+
| (EnumType::Struct, EnumType::Unit)
66+
| (EnumType::Unit, EnumType::Unit)
67+
| (EnumType::One, EnumType::One) => (),
6768
(EnumType::Unit, EnumType::One)
6869
| (EnumType::One, EnumType::Unit)
6970
| (_, EnumType::Struct) => sum = Some(EnumType::Struct),
70-
_ => panic!("enum member types must be consistent: {:?} {:?}", sum, ty),
71+
_ => panic!("enum member types must be consistent: {:?}", (sum, ty)),
7172
}
7273
sum
73-
});
74+
},
75+
);
7476
let enum_type = enum_type.expect("enum cannot be empty");
7577
let mut iter = data.variants.iter().peekable();
7678

@@ -109,7 +111,10 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
109111
});
110112

111113
if matches!(enum_type, EnumType::Struct) {
112-
assert!(unknown_arm.is_none(), "struct enum does not allow unknown variants");
114+
assert!(
115+
unknown_arm.is_none(),
116+
"struct enum does not allow unknown variants"
117+
);
113118
}
114119

115120
let fields = iter.enumerate().map(|(idx, field)| -> syn::Arm {
@@ -165,8 +170,7 @@ pub fn expand(DeriveInput { ident, data, .. }: DeriveInput) -> syn::ItemImpl {
165170
Some(name) => name.clone(),
166171
None => {
167172
let name = format!("unit{idx}");
168-
let name = syn::Ident::new(&name, field.span());
169-
name
173+
syn::Ident::new(&name, field.span())
170174
}
171175
})
172176
.collect::<Vec<_>>();

crates/ast_node/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn ast_node(
178178
match &input.data {
179179
Data::Enum(data) => {
180180
use syn::parse::Parser;
181-
181+
182182
let attrs = <syn::punctuated::Punctuated<syn::Ident, syn::Token![,]>>::parse_terminated
183183
.parse(args)
184184
.expect("failed to parse #[ast_node]");
@@ -191,7 +191,7 @@ pub fn ast_node(
191191
} else if attr == "no_unknown" {
192192
has_no_unknown = true;
193193
} else {
194-
panic!("unknown attribute: {:?}", attr)
194+
panic!("unknown attribute: {attr:?}")
195195
}
196196
}
197197

crates/swc_common/src/serializer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ impl<'de> cbor4ii::core::dec::Decode<'de> for WithChar<char> {
3636
reader: &mut R,
3737
) -> Result<Self, cbor4ii::core::dec::Error<R::Error>> {
3838
let n = u32::decode(reader)?;
39-
let value =
40-
char::from_u32(n).ok_or_else(|| cbor4ii::core::dec::Error::Mismatch {
41-
name: &"Token::Delim",
42-
found: 0,
43-
})?;
39+
let value = char::from_u32(n).ok_or_else(|| cbor4ii::core::dec::Error::Mismatch {
40+
name: &"Token::Delim",
41+
found: 0,
42+
})?;
4443
Ok(WithChar(value))
4544
}
4645
}

crates/swc_common/src/unknown.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use cbor4ii::core::{dec, enc};
2+
23
use crate::eq::EqIgnoreSpan;
34

45
#[derive(Clone)]

crates/swc_css_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub enum Token {
155155
raw: Atom,
156156
},
157157
Dimension {
158-
dimension: Box<DimensionToken>
158+
dimension: Box<DimensionToken>,
159159
},
160160
/// One or more whitespace.
161161
WhiteSpace {

0 commit comments

Comments
 (0)