@@ -123,6 +123,11 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
123123 self . kind . universe ( )
124124 }
125125
126+ #[ must_use]
127+ pub fn with_updated_universe ( self , ui : ty:: UniverseIndex ) -> CanonicalVarInfo < ' tcx > {
128+ CanonicalVarInfo { kind : self . kind . with_updated_universe ( ui) }
129+ }
130+
126131 pub fn is_existential ( & self ) -> bool {
127132 match self . kind {
128133 CanonicalVarKind :: Ty ( _) => true ,
@@ -133,6 +138,28 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
133138 CanonicalVarKind :: PlaceholderConst ( _, _) => false ,
134139 }
135140 }
141+
142+ pub fn is_region ( & self ) -> bool {
143+ match self . kind {
144+ CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
145+ CanonicalVarKind :: Ty ( _)
146+ | CanonicalVarKind :: PlaceholderTy ( _)
147+ | CanonicalVarKind :: Const ( _, _)
148+ | CanonicalVarKind :: PlaceholderConst ( _, _) => false ,
149+ }
150+ }
151+
152+ pub fn expect_anon_placeholder ( self ) -> u32 {
153+ match self . kind {
154+ CanonicalVarKind :: Ty ( _)
155+ | CanonicalVarKind :: Region ( _)
156+ | CanonicalVarKind :: Const ( _, _) => bug ! ( "expected placeholder: {self:?}" ) ,
157+
158+ CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. name . expect_anon ( ) ,
159+ CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. name . expect_anon ( ) ,
160+ CanonicalVarKind :: PlaceholderConst ( placeholder, _) => placeholder. name . as_u32 ( ) ,
161+ }
162+ }
136163}
137164
138165/// Describes the "kind" of the canonical variable. This is a "kind"
@@ -177,6 +204,38 @@ impl<'tcx> CanonicalVarKind<'tcx> {
177204 CanonicalVarKind :: PlaceholderConst ( placeholder, _) => placeholder. universe ,
178205 }
179206 }
207+
208+ /// Replaces the universe of this canonical variable with `ui`.
209+ ///
210+ /// In case this is a float or int variable, this causes an ICE if
211+ /// the updated universe is not the root.
212+ pub fn with_updated_universe ( self , ui : ty:: UniverseIndex ) -> CanonicalVarKind < ' tcx > {
213+ match self {
214+ CanonicalVarKind :: Ty ( kind) => match kind {
215+ CanonicalTyVarKind :: General ( _) => {
216+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
217+ }
218+ CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float => {
219+ assert_eq ! ( ui, ty:: UniverseIndex :: ROOT ) ;
220+ CanonicalVarKind :: Ty ( kind)
221+ }
222+ } ,
223+ CanonicalVarKind :: PlaceholderTy ( placeholder) => {
224+ CanonicalVarKind :: PlaceholderTy ( ty:: Placeholder { universe : ui, ..placeholder } )
225+ }
226+ CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
227+ CanonicalVarKind :: PlaceholderRegion ( placeholder) => {
228+ CanonicalVarKind :: PlaceholderRegion ( ty:: Placeholder { universe : ui, ..placeholder } )
229+ }
230+ CanonicalVarKind :: Const ( _, ty) => CanonicalVarKind :: Const ( ui, ty) ,
231+ CanonicalVarKind :: PlaceholderConst ( placeholder, ty) => {
232+ CanonicalVarKind :: PlaceholderConst (
233+ ty:: Placeholder { universe : ui, ..placeholder } ,
234+ ty,
235+ )
236+ }
237+ }
238+ }
180239}
181240
182241/// Rust actually has more than one category of type variables;
@@ -213,7 +272,8 @@ pub struct QueryResponse<'tcx, R> {
213272 pub value : R ,
214273}
215274
216- #[ derive( Clone , Debug , Default , HashStable , TypeFoldable , TypeVisitable , Lift ) ]
275+ #[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
276+ #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
217277pub struct QueryRegionConstraints < ' tcx > {
218278 pub outlives : Vec < QueryOutlivesConstraint < ' tcx > > ,
219279 pub member_constraints : Vec < MemberConstraint < ' tcx > > ,
0 commit comments