@@ -179,17 +179,10 @@ pub enum EdgeKind {
179
179
180
180
/// A predicate to allow visiting only sub-sets of the whole IR graph by
181
181
/// excluding certain edges from being followed by the traversal.
182
- pub trait TraversalPredicate {
183
- /// Should the traversal follow this edge, and visit everything that is
184
- /// reachable through it?
185
- fn should_follow ( & self , ctx : & BindgenContext , edge : Edge ) -> bool ;
186
- }
187
-
188
- impl TraversalPredicate for for <' a > fn ( & ' a BindgenContext , Edge ) -> bool {
189
- fn should_follow ( & self , ctx : & BindgenContext , edge : Edge ) -> bool {
190
- ( * self ) ( ctx, edge)
191
- }
192
- }
182
+ ///
183
+ /// The predicate must return true if the traversal should follow this edge
184
+ /// and visit everything that is reachable through it.
185
+ pub type TraversalPredicate = for <' a > fn ( & ' a BindgenContext , Edge ) -> bool ;
193
186
194
187
/// A `TraversalPredicate` implementation that follows all edges, and therefore
195
188
/// traversals using this predicate will see the whole IR graph reachable from
@@ -378,11 +371,10 @@ pub trait Trace {
378
371
/// An graph traversal of the transitive closure of references between items.
379
372
///
380
373
/// See `BindgenContext::allowlisted_items` for more information.
381
- pub struct ItemTraversal < ' ctx , Storage , Queue , Predicate >
374
+ pub struct ItemTraversal < ' ctx , Storage , Queue >
382
375
where
383
376
Storage : TraversalStorage < ' ctx > ,
384
377
Queue : TraversalQueue ,
385
- Predicate : TraversalPredicate ,
386
378
{
387
379
ctx : & ' ctx BindgenContext ,
388
380
@@ -393,25 +385,23 @@ where
393
385
queue : Queue ,
394
386
395
387
/// The predicate that determines which edges this traversal will follow.
396
- predicate : Predicate ,
388
+ predicate : TraversalPredicate ,
397
389
398
390
/// The item we are currently traversing.
399
391
currently_traversing : Option < ItemId > ,
400
392
}
401
393
402
- impl < ' ctx , Storage , Queue , Predicate >
403
- ItemTraversal < ' ctx , Storage , Queue , Predicate >
394
+ impl < ' ctx , Storage , Queue > ItemTraversal < ' ctx , Storage , Queue >
404
395
where
405
396
Storage : TraversalStorage < ' ctx > ,
406
397
Queue : TraversalQueue ,
407
- Predicate : TraversalPredicate ,
408
398
{
409
399
/// Begin a new traversal, starting from the given roots.
410
400
pub fn new < R > (
411
401
ctx : & ' ctx BindgenContext ,
412
402
roots : R ,
413
- predicate : Predicate ,
414
- ) -> ItemTraversal < ' ctx , Storage , Queue , Predicate >
403
+ predicate : TraversalPredicate ,
404
+ ) -> ItemTraversal < ' ctx , Storage , Queue >
415
405
where
416
406
R : IntoIterator < Item = ItemId > ,
417
407
{
@@ -433,16 +423,14 @@ where
433
423
}
434
424
}
435
425
436
- impl < ' ctx , Storage , Queue , Predicate > Tracer
437
- for ItemTraversal < ' ctx , Storage , Queue , Predicate >
426
+ impl < ' ctx , Storage , Queue > Tracer for ItemTraversal < ' ctx , Storage , Queue >
438
427
where
439
428
Storage : TraversalStorage < ' ctx > ,
440
429
Queue : TraversalQueue ,
441
- Predicate : TraversalPredicate ,
442
430
{
443
431
fn visit_kind ( & mut self , item : ItemId , kind : EdgeKind ) {
444
432
let edge = Edge :: new ( item, kind) ;
445
- if !self . predicate . should_follow ( self . ctx , edge) {
433
+ if !( self . predicate ) ( self . ctx , edge) {
446
434
return ;
447
435
}
448
436
@@ -454,12 +442,10 @@ where
454
442
}
455
443
}
456
444
457
- impl < ' ctx , Storage , Queue , Predicate > Iterator
458
- for ItemTraversal < ' ctx , Storage , Queue , Predicate >
445
+ impl < ' ctx , Storage , Queue > Iterator for ItemTraversal < ' ctx , Storage , Queue >
459
446
where
460
447
Storage : TraversalStorage < ' ctx > ,
461
448
Queue : TraversalQueue ,
462
- Predicate : TraversalPredicate ,
463
449
{
464
450
type Item = ItemId ;
465
451
@@ -488,21 +474,5 @@ where
488
474
///
489
475
/// See `BindgenContext::assert_no_dangling_item_traversal` for more
490
476
/// information.
491
- pub type AssertNoDanglingItemsTraversal < ' ctx > = ItemTraversal <
492
- ' ctx ,
493
- Paths < ' ctx > ,
494
- VecDeque < ItemId > ,
495
- for <' a > fn ( & ' a BindgenContext , Edge ) -> bool ,
496
- > ;
497
-
498
- #[ cfg( test) ]
499
- mod tests {
500
- use super :: * ;
501
-
502
- #[ test]
503
- #[ allow( dead_code) ]
504
- fn traversal_predicate_is_object_safe ( ) {
505
- // This should compile only if TraversalPredicate is object safe.
506
- fn takes_by_trait_object ( _: & dyn TraversalPredicate ) { }
507
- }
508
- }
477
+ pub type AssertNoDanglingItemsTraversal < ' ctx > =
478
+ ItemTraversal < ' ctx , Paths < ' ctx > , VecDeque < ItemId > > ;
0 commit comments