@@ -754,88 +754,6 @@ impl<'tcx> TyCtxt<'tcx> {
754754 }
755755}
756756
757- pub struct BoundVarsCollector < ' tcx > {
758- binder_index : ty:: DebruijnIndex ,
759- vars : BTreeMap < u32 , ty:: BoundVariableKind > ,
760- // We may encounter the same variable at different levels of binding, so
761- // this can't just be `Ty`
762- visited : SsoHashSet < ( ty:: DebruijnIndex , Ty < ' tcx > ) > ,
763- }
764-
765- impl < ' tcx > BoundVarsCollector < ' tcx > {
766- pub fn new ( ) -> Self {
767- BoundVarsCollector {
768- binder_index : ty:: INNERMOST ,
769- vars : BTreeMap :: new ( ) ,
770- visited : SsoHashSet :: default ( ) ,
771- }
772- }
773-
774- pub fn into_vars ( self , tcx : TyCtxt < ' tcx > ) -> & ' tcx ty:: List < ty:: BoundVariableKind > {
775- let max = self . vars . iter ( ) . map ( |( k, _) | * k) . max ( ) . unwrap_or_else ( || 0 ) ;
776- for i in 0 ..max {
777- if let None = self . vars . get ( & i) {
778- panic ! ( "Unknown variable: {:?}" , i) ;
779- }
780- }
781-
782- tcx. mk_bound_variable_kinds ( self . vars . into_iter ( ) . map ( |( _, v) | v) )
783- }
784- }
785-
786- impl < ' tcx > TypeVisitor < ' tcx > for BoundVarsCollector < ' tcx > {
787- type BreakTy = ( ) ;
788-
789- fn visit_binder < T : TypeFoldable < ' tcx > > (
790- & mut self ,
791- t : & Binder < ' tcx , T > ,
792- ) -> ControlFlow < Self :: BreakTy > {
793- self . binder_index . shift_in ( 1 ) ;
794- let result = t. super_visit_with ( self ) ;
795- self . binder_index . shift_out ( 1 ) ;
796- result
797- }
798-
799- fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
800- if t. outer_exclusive_binder < self . binder_index
801- || !self . visited . insert ( ( self . binder_index , t) )
802- {
803- return ControlFlow :: CONTINUE ;
804- }
805- use std:: collections:: btree_map:: Entry ;
806- match * t. kind ( ) {
807- ty:: Bound ( debruijn, bound_ty) if debruijn == self . binder_index => {
808- match self . vars . entry ( bound_ty. var . as_u32 ( ) ) {
809- Entry :: Vacant ( entry) => {
810- entry. insert ( ty:: BoundVariableKind :: Ty ( bound_ty. kind ) ) ;
811- }
812- Entry :: Occupied ( entry) => match entry. get ( ) {
813- ty:: BoundVariableKind :: Ty ( _) => { }
814- _ => bug ! ( "Conflicting bound vars" ) ,
815- } ,
816- }
817- }
818-
819- _ => ( ) ,
820- } ;
821-
822- t. super_visit_with ( self )
823- }
824-
825- fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
826- match r {
827- ty:: ReLateBound ( index, _br) if * index == self . binder_index => {
828- // If you hit this, you should be using `Binder::bind_with_vars` or `Binder::rebind`
829- bug ! ( "Trying to collect bound vars with a bound region: {:?} {:?}" , index, _br)
830- }
831-
832- _ => ( ) ,
833- } ;
834-
835- r. super_visit_with ( self )
836- }
837- }
838-
839757pub struct ValidateBoundVars < ' tcx > {
840758 bound_vars : & ' tcx ty:: List < ty:: BoundVariableKind > ,
841759 binder_index : ty:: DebruijnIndex ,
0 commit comments