@@ -377,8 +377,13 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
377
377
// on other hash map entries. We *must* put it back into the hash map at
378
378
// the end of this method. This allows us to side-step HashMap's lack of
379
379
// an analog to slice::split_at_mut.
380
- let mut used_by_this_id =
381
- self . used . get_mut ( & id) . unwrap ( ) . take ( ) . unwrap ( ) ;
380
+ let mut used_by_this_id = self . used
381
+ . get_mut ( & id)
382
+ . expect ( "Should have a set of used template params for every item \
383
+ id")
384
+ . take ( )
385
+ . expect ( "Should maintain the invariant that all used template param \
386
+ sets are `Some` upon entry of `constrain`") ;
382
387
383
388
let original_len = used_by_this_id. len ( ) ;
384
389
@@ -415,27 +420,31 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
415
420
// Otherwise, add the union of each of its referent item's template
416
421
// parameter usage.
417
422
_ => {
418
- item. trace ( self . ctx ,
419
- & mut |sub_id, edge_kind| {
423
+ item. trace ( self . ctx , & mut |sub_id, edge_kind| {
420
424
if sub_id == id || !Self :: consider_edge ( edge_kind) {
421
425
return ;
422
426
}
423
427
424
428
let used_by_sub_id = self . used [ & sub_id]
425
429
. as_ref ( )
426
- . unwrap ( )
430
+ . expect ( "Because sub_id != id, and all used template \
431
+ param sets other than id's are `Some`, \
432
+ sub_id's used template param set should be \
433
+ `Some`")
427
434
. iter ( )
428
435
. cloned ( ) ;
429
436
used_by_this_id. extend ( used_by_sub_id) ;
430
- } ,
431
- & ( ) ) ;
437
+ } , & ( ) ) ;
432
438
}
433
439
}
434
440
435
441
let new_len = used_by_this_id. len ( ) ;
436
- assert ! ( new_len >= original_len) ;
442
+ assert ! ( new_len >= original_len,
443
+ "This is the property that ensures this function is monotone -- \
444
+ if it doesn't hold, the analysis might never terminate!") ;
437
445
438
446
// Put the set back in the hash map and restore our invariant.
447
+ debug_assert ! ( self . used[ & id] . is_none( ) ) ;
439
448
self . used . insert ( id, Some ( used_by_this_id) ) ;
440
449
debug_assert ! ( self . used. values( ) . all( |v| v. is_some( ) ) ) ;
441
450
0 commit comments