@@ -289,10 +289,16 @@ impl RegisterExt for Register {
289
289
}
290
290
291
291
fn modify_field ( & mut self , fspec : & str , fmod : & Hash , rpath : & RegisterPath ) -> PatchResult {
292
+ let ( fspec, ignore) = fspec. spec ( ) ;
292
293
let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
293
294
let field_builder = make_field ( fmod, Some ( rpath) ) ?;
294
295
let dim = make_dim_element ( fmod) ?;
295
- if !ftags. is_empty ( ) {
296
+ if ftags. is_empty ( ) && !ignore {
297
+ let present = self . present_fields ( ) ;
298
+ return Err ( anyhow ! (
299
+ "Could not find `{rpath}:{fspec}. Present fields: {present}.`"
300
+ ) ) ;
301
+ } else {
296
302
for ftag in ftags {
297
303
modify_dim_element ( ftag, & dim) ?;
298
304
if let Some ( value) = fmod
@@ -362,6 +368,7 @@ impl RegisterExt for Register {
362
368
dpath. into ( )
363
369
}
364
370
}
371
+ let ( fspec, ignore) = fspec. spec ( ) ;
365
372
let info = if let Some ( dpath) = fderive. as_str ( ) {
366
373
FieldInfo :: builder ( ) . derived_from ( Some ( make_path ( dpath, rpath) ) )
367
374
} else if let Some ( hash) = fderive. as_hash ( ) {
@@ -372,18 +379,15 @@ impl RegisterExt for Register {
372
379
} else {
373
380
return Err ( anyhow ! ( "derive: incorrect syntax for {fspec}" ) ) ;
374
381
} ;
375
-
376
- let mut found = false ;
377
- for field in self . iter_fields ( fspec) {
378
- found = true ;
379
- field. modify_from ( info. clone ( ) , VAL_LVL ) ?;
380
- }
381
- if !found {
382
- {
383
- super :: check_dimable_name ( fspec) ?;
384
- let field = info. name ( fspec. into ( ) ) . build ( VAL_LVL ) ?. single ( ) ;
385
- self . fields . get_or_insert ( Vec :: new ( ) ) . push ( field) ;
382
+ let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
383
+ if !ftags. is_empty ( ) {
384
+ for field in ftags {
385
+ field. modify_from ( info. clone ( ) , VAL_LVL ) ?;
386
386
}
387
+ } else if !ignore {
388
+ super :: check_dimable_name ( fspec) ?;
389
+ let field = info. name ( fspec. into ( ) ) . build ( VAL_LVL ) ?. single ( ) ;
390
+ self . fields . get_or_insert ( Vec :: new ( ) ) . push ( field) ;
387
391
}
388
392
Ok ( ( ) )
389
393
}
0 commit comments