@@ -30,6 +30,13 @@ pub struct Discr<'tcx> {
3030 pub ty : Ty < ' tcx > ,
3131}
3232
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+
3340#[ derive( Copy , Clone , Debug ) ]
3441pub enum NotUniqueParam < ' tcx > {
3542 DuplicateParam ( ty:: GenericArg < ' tcx > ) ,
@@ -461,20 +468,18 @@ impl<'tcx> TyCtxt<'tcx> {
461468 pub fn uses_unique_generic_params (
462469 self ,
463470 substs : SubstsRef < ' tcx > ,
464- ignore_regions : bool ,
471+ ignore_regions : IgnoreRegions ,
465472 ) -> Result < ( ) , NotUniqueParam < ' tcx > > {
466473 let mut seen = GrowableBitSet :: default ( ) ;
467474 for arg in substs {
468475 match arg. unpack ( ) {
469476 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 ( ) ) ) ;
478483 }
479484 }
480485 }
0 commit comments