@@ -30,6 +30,13 @@ pub struct Discr<'tcx> {
30
30
pub ty : Ty < ' tcx > ,
31
31
}
32
32
33
+ /// Used as an input to [`TyCtxt::uses_unique_generic_params`].
34
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
35
+ pub enum IgnoreRegions {
36
+ Yes ,
37
+ No ,
38
+ }
39
+
33
40
#[ derive( Copy , Clone , Debug ) ]
34
41
pub enum NotUniqueParam < ' tcx > {
35
42
DuplicateParam ( ty:: GenericArg < ' tcx > ) ,
@@ -461,20 +468,18 @@ impl<'tcx> TyCtxt<'tcx> {
461
468
pub fn uses_unique_generic_params (
462
469
self ,
463
470
substs : SubstsRef < ' tcx > ,
464
- ignore_regions : bool ,
471
+ ignore_regions : IgnoreRegions ,
465
472
) -> Result < ( ) , NotUniqueParam < ' tcx > > {
466
473
let mut seen = GrowableBitSet :: default ( ) ;
467
474
for arg in substs {
468
475
match arg. unpack ( ) {
469
476
GenericArgKind :: Lifetime ( lt) => {
470
- if !ignore_regions {
471
- match lt. kind ( ) {
472
- ty:: ReEarlyBound ( p) => {
473
- if !seen. insert ( p. index ) {
474
- return Err ( NotUniqueParam :: DuplicateParam ( lt. into ( ) ) ) ;
475
- }
476
- }
477
- _ => return Err ( NotUniqueParam :: NotParam ( lt. into ( ) ) ) ,
477
+ if ignore_regions == IgnoreRegions :: No {
478
+ let ty:: ReEarlyBound ( p) = lt. kind ( ) else {
479
+ return Err ( NotUniqueParam :: NotParam ( lt. into ( ) ) )
480
+ } ;
481
+ if !seen. insert ( p. index ) {
482
+ return Err ( NotUniqueParam :: DuplicateParam ( lt. into ( ) ) ) ;
478
483
}
479
484
}
480
485
}
0 commit comments