@@ -12,6 +12,7 @@ use rustc_middle::mir::interpret::Scalar;
12
12
use rustc_middle:: mir:: { self , Const } ;
13
13
use rustc_middle:: thir:: { FieldPat , Pat , PatKind , PatRange , PatRangeBoundary } ;
14
14
use rustc_middle:: ty:: layout:: IntegerExt ;
15
+ use rustc_middle:: ty:: TypeVisitableExt ;
15
16
use rustc_middle:: ty:: { self , OpaqueTypeKey , Ty , TyCtxt , VariantDef } ;
16
17
use rustc_span:: ErrorGuaranteed ;
17
18
use rustc_span:: { Span , DUMMY_SP } ;
@@ -303,7 +304,10 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
303
304
///
304
305
/// See [`crate::constructor`] for considerations of emptiness.
305
306
#[ instrument( level = "debug" , skip( self ) , ret) ]
306
- pub fn ctors_for_ty ( & self , ty : RevealedTy < ' tcx > ) -> ConstructorSet < ' p , ' tcx > {
307
+ pub fn ctors_for_ty (
308
+ & self ,
309
+ ty : RevealedTy < ' tcx > ,
310
+ ) -> Result < ConstructorSet < ' p , ' tcx > , ErrorGuaranteed > {
307
311
let cx = self ;
308
312
let make_uint_range = |start, end| {
309
313
IntRange :: from_range (
@@ -312,9 +316,11 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
312
316
RangeEnd :: Included ,
313
317
)
314
318
} ;
319
+ // Abort on type error.
320
+ ty. error_reported ( ) ?;
315
321
// This determines the set of all possible constructors for the type `ty`. For numbers,
316
322
// arrays and slices we use ranges and variable-length slices when appropriate.
317
- match ty. kind ( ) {
323
+ Ok ( match ty. kind ( ) {
318
324
ty:: Bool => ConstructorSet :: Bool ,
319
325
ty:: Char => {
320
326
// The valid Unicode Scalar Value ranges.
@@ -424,7 +430,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
424
430
ty:: CoroutineWitness ( _, _) | ty:: Bound ( _, _) | ty:: Placeholder ( _) | ty:: Infer ( _) => {
425
431
bug ! ( "Encountered unexpected type in `ConstructorSet::for_ty`: {ty:?}" )
426
432
}
427
- }
433
+ } )
428
434
}
429
435
430
436
pub ( crate ) fn lower_pat_range_bdy (
@@ -965,7 +971,10 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
965
971
) -> & [ Self :: Ty ] {
966
972
self . ctor_sub_tys ( ctor, ty)
967
973
}
968
- fn ctors_for_ty ( & self , ty : Self :: Ty ) -> crate :: constructor:: ConstructorSet < Self > {
974
+ fn ctors_for_ty (
975
+ & self ,
976
+ ty : Self :: Ty ,
977
+ ) -> Result < crate :: constructor:: ConstructorSet < Self > , Self :: Error > {
969
978
self . ctors_for_ty ( ty)
970
979
}
971
980
0 commit comments