@@ -391,16 +391,20 @@ pub fn derive_cluster(
391
391
let ( dparent, dname) = BlockPath :: parse_str ( dpath) ;
392
392
let rdpath;
393
393
let cluster_path;
394
- let d = ( if let Some ( dparent) = dparent {
394
+ if let Some ( dparent) = dparent {
395
395
cluster_path = dparent. new_cluster ( dname) ;
396
396
rdpath = dparent;
397
- index. clusters . get ( & cluster_path)
398
397
} else {
399
398
cluster_path = path. new_cluster ( dname) ;
400
399
rdpath = path. clone ( ) ;
401
- index. clusters . get ( & cluster_path)
402
- } )
403
- . ok_or_else ( || anyhow ! ( "cluster {} not found" , dpath) ) ?;
400
+ }
401
+ if & rdpath == path && dname == & c. name {
402
+ return Err ( anyhow ! ( "Cluster {cluster_path} is self-derived" ) ) ;
403
+ }
404
+ let d = index
405
+ . clusters
406
+ . get ( & cluster_path)
407
+ . ok_or_else ( || anyhow ! ( "cluster {} not found" , dpath) ) ?;
404
408
405
409
let mut cpath = None ;
406
410
if c. children . is_empty ( ) {
@@ -422,16 +426,20 @@ pub fn derive_register(
422
426
let ( dblock, dname) = RegisterPath :: parse_str ( dpath) ;
423
427
let rdpath;
424
428
let reg_path;
425
- let d = ( if let Some ( dblock) = dblock {
429
+ if let Some ( dblock) = dblock {
426
430
reg_path = dblock. new_register ( dname) ;
427
431
rdpath = dblock;
428
- index. registers . get ( & reg_path)
429
432
} else {
430
433
reg_path = path. new_register ( dname) ;
431
434
rdpath = path. clone ( ) ;
432
- index. registers . get ( & reg_path)
433
- } )
434
- . ok_or_else ( || anyhow ! ( "register {} not found" , dpath) ) ?;
435
+ }
436
+ if & rdpath == path && dname == & r. name {
437
+ return Err ( anyhow ! ( "Register {reg_path} is self-derived" ) ) ;
438
+ }
439
+ let d = index
440
+ . registers
441
+ . get ( & reg_path)
442
+ . ok_or_else ( || anyhow ! ( "register {} not found" , dpath) ) ?;
435
443
436
444
let mut rpath = None ;
437
445
if r. fields . is_none ( ) {
@@ -453,16 +461,20 @@ pub fn derive_field(
453
461
let ( dregister, dname) = FieldPath :: parse_str ( dpath) ;
454
462
let rdpath;
455
463
let field_path;
456
- let d = ( if let Some ( dregister) = dregister {
464
+ if let Some ( dregister) = dregister {
457
465
field_path = dregister. new_field ( dname) ;
458
466
rdpath = dregister;
459
- index. fields . get ( & field_path)
460
467
} else {
461
468
field_path = rpath. new_field ( dname) ;
462
469
rdpath = rpath. clone ( ) ;
463
- index. fields . get ( & field_path)
464
- } )
465
- . ok_or_else ( || anyhow ! ( "field {} not found" , dpath) ) ?;
470
+ }
471
+ if & rdpath == rpath && dname == & f. name {
472
+ return Err ( anyhow ! ( "Field {field_path} is self-derived" ) ) ;
473
+ }
474
+ let d = index
475
+ . fields
476
+ . get ( & field_path)
477
+ . ok_or_else ( || anyhow ! ( "field {} not found" , dpath) ) ?;
466
478
467
479
let mut fpath = None ;
468
480
if f. enumerated_values . is_empty ( ) {
@@ -556,6 +568,9 @@ pub fn derive_enumerated_values(
556
568
fpath : & FieldPath ,
557
569
index : & Index ,
558
570
) -> Result < EnumPath > {
571
+ if Some ( dpath) == ev. name . as_deref ( ) {
572
+ return Err ( anyhow ! ( "EnumeratedValues {fpath}.{dpath} is self-derived" ) ) ;
573
+ }
559
574
let mut v: Vec < & str > = dpath. split ( '.' ) . collect ( ) ;
560
575
let dname = v. pop ( ) . unwrap ( ) ;
561
576
let d = if v. is_empty ( ) {
@@ -590,6 +605,9 @@ pub fn derive_enumerated_values(
590
605
} ;
591
606
FieldPath :: new ( rdpath, fdname)
592
607
} ;
608
+ if & fdpath == fpath && Some ( dname) == ev. name . as_deref ( ) {
609
+ return Err ( anyhow ! ( "EnumeratedValues {fpath}.{dname} is self-derived" ) ) ;
610
+ }
593
611
let epath = EnumPath :: new ( fdpath, dname) ;
594
612
index. evs . get ( & epath) . map ( |d| ( d, epath) )
595
613
} ;
@@ -615,6 +633,9 @@ pub fn derive_peripheral(
615
633
dpath : & str ,
616
634
index : & Index ,
617
635
) -> Result < Option < BlockPath > > {
636
+ if dpath == & p. name {
637
+ return Err ( anyhow ! ( "Peripheral {dpath} is self-derived" ) ) ;
638
+ }
618
639
let mut path = None ;
619
640
let derpath = BlockPath :: new ( dpath) ;
620
641
let d = index
0 commit comments