@@ -190,13 +190,27 @@ impl<'de> Deserialize<'de> for GroupImportsTactic {
190
190
lines. push ( elem) ;
191
191
}
192
192
193
- lines
193
+ let value = lines
194
194
. into_iter ( )
195
195
. map ( TryFrom :: try_from)
196
196
. collect :: < Result < Vec < _ > , _ > > ( )
197
197
. map ( WildcardGroups )
198
- . map ( GroupImportsTactic :: Wildcards )
199
- . map_err ( serde:: de:: Error :: custom)
198
+ . map_err ( serde:: de:: Error :: custom) ?;
199
+
200
+ if value
201
+ . 0
202
+ . iter ( )
203
+ . filter ( |g| matches ! ( g, WildcardGroup :: Fallback ) )
204
+ . count ( )
205
+ > 1
206
+ {
207
+ return Err ( serde:: de:: Error :: custom ( concat ! (
208
+ "Wildcard format group must include at " ,
209
+ "most one fallback (i.e \" *\" ) group."
210
+ ) ) ) ;
211
+ }
212
+
213
+ Ok ( GroupImportsTactic :: Wildcards ( value) )
200
214
}
201
215
}
202
216
@@ -246,7 +260,7 @@ impl WildcardGroup {
246
260
}
247
261
248
262
impl TryFrom < Vec < String > > for WildcardGroup {
249
- type Error = regex :: Error ;
263
+ type Error = anyhow :: Error ;
250
264
251
265
fn try_from ( i : Vec < String > ) -> Result < Self , Self :: Error > {
252
266
enum Kind {
@@ -258,7 +272,14 @@ impl TryFrom<Vec<String>> for WildcardGroup {
258
272
return Ok ( Self :: Fallback ) ;
259
273
}
260
274
261
- i. into_iter ( )
275
+ if i. iter ( ) . any ( |x| x == "*" ) {
276
+ return Err ( anyhow:: anyhow!( concat!(
277
+ "'*' is a special wildcard for a fallback group " ,
278
+ "and could only be a single item within this group"
279
+ ) ) ) ;
280
+ }
281
+
282
+ Ok ( i. into_iter ( )
262
283
. map ( |s| {
263
284
let ( s, kind) = if let Some ( tail) = s. strip_prefix ( "$std" ) {
264
285
( tail, Some ( Kind :: Std ) )
@@ -279,7 +300,7 @@ impl TryFrom<Vec<String>> for WildcardGroup {
279
300
regex:: Regex :: new ( & format ! ( "^{wildcard}$" ) )
280
301
} )
281
302
. collect :: < Result < _ , _ > > ( )
282
- . map ( Self :: Group )
303
+ . map ( Self :: Group ) ? )
283
304
}
284
305
}
285
306
0 commit comments