@@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Symbol};
2222use rustc_span:: { Span , DUMMY_SP } ;
2323use rustc_target:: abi:: { FieldIdx , VariantIdx , FIRST_VARIANT } ;
2424use rustc_target:: spec:: abi:: { self , Abi } ;
25- use std:: assert_matches:: { assert_matches , debug_assert_matches} ;
25+ use std:: assert_matches:: debug_assert_matches;
2626use std:: borrow:: Cow ;
2727use std:: iter;
2828use std:: ops:: { ControlFlow , Deref , Range } ;
@@ -1137,8 +1137,8 @@ pub struct AliasTerm<'tcx> {
11371137 /// aka. `tcx.parent(def_id)`.
11381138 pub def_id : DefId ,
11391139
1140- /// This field exists to prevent the creation of `AliasTy ` without using
1141- /// [AliasTy ::new].
1140+ /// This field exists to prevent the creation of `AliasTerm ` without using
1141+ /// [AliasTerm ::new].
11421142 _use_alias_term_new_instead : ( ) ,
11431143}
11441144
@@ -1202,13 +1202,15 @@ impl<'tcx> AliasTerm<'tcx> {
12021202 }
12031203
12041204 pub fn expect_ty ( self , tcx : TyCtxt < ' tcx > ) -> AliasTy < ' tcx > {
1205- assert_matches ! (
1206- self . kind( tcx) ,
1205+ match self . kind ( tcx) {
12071206 ty:: AliasTermKind :: ProjectionTy
1208- | ty:: AliasTermKind :: OpaqueTy
1209- | ty:: AliasTermKind :: WeakTy
1210- | ty:: AliasTermKind :: InherentTy
1211- ) ;
1207+ | ty:: AliasTermKind :: InherentTy
1208+ | ty:: AliasTermKind :: OpaqueTy
1209+ | ty:: AliasTermKind :: WeakTy => { }
1210+ ty:: AliasTermKind :: UnevaluatedConst | ty:: AliasTermKind :: ProjectionConst => {
1211+ bug ! ( "Cannot turn `UnevaluatedConst` into `AliasTy`" )
1212+ }
1213+ }
12121214 ty:: AliasTy { def_id : self . def_id , args : self . args , _use_alias_ty_new_instead : ( ) }
12131215 }
12141216
@@ -1223,13 +1225,14 @@ impl<'tcx> AliasTerm<'tcx> {
12231225 }
12241226 DefKind :: OpaqueTy => ty:: AliasTermKind :: OpaqueTy ,
12251227 DefKind :: TyAlias => ty:: AliasTermKind :: WeakTy ,
1226- DefKind :: AssocConst | DefKind :: AnonConst => ty:: AliasTermKind :: UnevaluatedConst ,
1228+ DefKind :: AnonConst => ty:: AliasTermKind :: UnevaluatedConst ,
1229+ DefKind :: AssocConst => ty:: AliasTermKind :: ProjectionConst ,
12271230 kind => bug ! ( "unexpected DefKind in AliasTy: {kind:?}" ) ,
12281231 }
12291232 }
12301233}
12311234
1232- /// The following methods work only with (trait) associated type projections.
1235+ /// The following methods work only with (trait) associated item projections.
12331236impl < ' tcx > AliasTerm < ' tcx > {
12341237 pub fn self_ty ( self ) -> Ty < ' tcx > {
12351238 self . args . type_at ( 0 )
@@ -1269,7 +1272,6 @@ impl<'tcx> AliasTerm<'tcx> {
12691272 self ,
12701273 tcx : TyCtxt < ' tcx > ,
12711274 ) -> ( ty:: TraitRef < ' tcx > , & ' tcx [ ty:: GenericArg < ' tcx > ] ) {
1272- debug_assert ! ( matches!( tcx. def_kind( self . def_id) , DefKind :: AssocTy | DefKind :: AssocConst ) ) ;
12731275 let trait_def_id = self . trait_def_id ( tcx) ;
12741276 let trait_generics = tcx. generics_of ( trait_def_id) ;
12751277 (
@@ -1304,12 +1306,14 @@ impl<'tcx> AliasTerm<'tcx> {
13041306 AliasTy { def_id : self . def_id , args : self . args , _use_alias_ty_new_instead : ( ) } ,
13051307 )
13061308 . into ( ) ,
1307- ty:: AliasTermKind :: UnevaluatedConst => ty:: Const :: new_unevaluated (
1308- tcx,
1309- ty:: UnevaluatedConst :: new ( self . def_id , self . args ) ,
1310- tcx. type_of ( self . def_id ) . instantiate ( tcx, self . args ) ,
1311- )
1312- . into ( ) ,
1309+ ty:: AliasTermKind :: UnevaluatedConst | ty:: AliasTermKind :: ProjectionConst => {
1310+ ty:: Const :: new_unevaluated (
1311+ tcx,
1312+ ty:: UnevaluatedConst :: new ( self . def_id , self . args ) ,
1313+ tcx. type_of ( self . def_id ) . instantiate ( tcx, self . args ) ,
1314+ )
1315+ . into ( )
1316+ }
13131317 }
13141318 }
13151319}
@@ -1358,7 +1362,7 @@ pub struct AliasTy<'tcx> {
13581362 /// aka. `tcx.parent(def_id)`.
13591363 pub def_id : DefId ,
13601364
1361- /// This field exists to prevent the creation of `AliasTy ` without using
1365+ /// This field exists to prevent the creation of `AliasT ` without using
13621366 /// [AliasTy::new].
13631367 _use_alias_ty_new_instead : ( ) ,
13641368}
@@ -1422,7 +1426,6 @@ impl<'tcx> AliasTy<'tcx> {
14221426 self ,
14231427 tcx : TyCtxt < ' tcx > ,
14241428 ) -> ( ty:: TraitRef < ' tcx > , & ' tcx [ ty:: GenericArg < ' tcx > ] ) {
1425- debug_assert ! ( matches!( tcx. def_kind( self . def_id) , DefKind :: AssocTy | DefKind :: AssocConst ) ) ;
14261429 let trait_def_id = self . trait_def_id ( tcx) ;
14271430 let trait_generics = tcx. generics_of ( trait_def_id) ;
14281431 (
0 commit comments