@@ -339,8 +339,9 @@ pub fn build_func_map<'a>(
339
339
Ok ( decl_map)
340
340
}
341
341
342
- #[ allow( clippy:: collapsible_if) ]
343
- pub fn validate_rules ( statements : & BTreeSet < ValidatedStatement > ) -> Result < ( ) , CascadeErrors > {
342
+ pub fn validate_fs_context_duplicates (
343
+ statements : & BTreeSet < ValidatedStatement > ,
344
+ ) -> Result < ( ) , CascadeErrors > {
344
345
let mut errors = CascadeErrors :: new ( ) ;
345
346
let mut fsc_rules: BTreeMap < & String , BTreeSet < & FileSystemContextRule > > = BTreeMap :: new ( ) ;
346
347
@@ -368,7 +369,7 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
368
369
continue ' key_loop;
369
370
}
370
371
FSContextType :: GenFSCon => {
371
- // genfscon gets more complicated. We can have simlar rules as long as the paths different.
372
+ // genfscon gets more complicated. We can have similar rules as long as the paths are different.
372
373
// If we find a genfscon with the same path, they must have the same context and object type.
373
374
if let Some ( path) = & rule. path {
374
375
for inner_rule in & v {
@@ -383,25 +384,19 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
383
384
inner_rule. context,
384
385
) ) ) ) ;
385
386
continue ' key_loop;
386
- // else if let is not suppored currently (https://github.com/rust-lang/rust/issues/53667).
387
- // Thus we check if we are not none and then unwrap
388
387
} else if path == inner_path
388
+ && rule. file_type != inner_rule. file_type
389
389
&& rule. file_type . is_some ( )
390
- && inner_rule. file_type . is_some ( )
391
390
{
392
- if rule. file_type . as_ref ( ) . unwrap ( )
393
- != inner_rule. file_type . as_ref ( ) . unwrap ( )
394
- {
395
- errors. append ( CascadeErrors :: from ( InvalidFileSystemError :: new ( & format ! (
396
- "Duplicate genfscon.\n Found duplicate genfscon rules with differing object types: {}\
397
- \n \t Path: {}\n \t Object Type 1: {}\n \t Object Type 2: {}",
398
- rule. fs_name,
399
- path,
400
- rule. file_type. as_ref( ) . unwrap( ) ,
401
- inner_rule. file_type. as_ref( ) . unwrap( ) ,
402
- ) ) ) ) ;
403
- continue ' key_loop;
404
- }
391
+ errors. append ( CascadeErrors :: from ( InvalidFileSystemError :: new ( & format ! (
392
+ "Duplicate genfscon.\n Found duplicate genfscon rules with differing object types: {}\
393
+ \n \t Path: {}\n \t Object Type 1: {}\n \t Object Type 2: {}",
394
+ rule. fs_name,
395
+ path,
396
+ rule. file_type. as_ref( ) . unwrap( ) ,
397
+ inner_rule. file_type. as_ref( ) . unwrap( ) ,
398
+ ) ) ) ) ;
399
+ continue ' key_loop;
405
400
}
406
401
}
407
402
}
@@ -410,7 +405,15 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
410
405
}
411
406
}
412
407
}
408
+ errors. into_result ( ( ) )
409
+ }
410
+
411
+ pub fn validate_rules ( statements : & BTreeSet < ValidatedStatement > ) -> Result < ( ) , CascadeErrors > {
412
+ let mut errors = CascadeErrors :: new ( ) ;
413
413
414
+ if let Err ( call_errors) = validate_fs_context_duplicates ( statements) {
415
+ errors. append ( call_errors) ;
416
+ }
414
417
errors. into_result ( ( ) )
415
418
}
416
419
0 commit comments