@@ -9,7 +9,6 @@ use crate::ty::subst::{Kind, UnpackedKind, SubstsRef};
9
9
use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
10
10
use crate :: ty:: error:: { ExpectedFound , TypeError } ;
11
11
use crate :: mir:: interpret:: { GlobalId , ConstValue , Scalar } ;
12
- use crate :: util:: common:: ErrorReported ;
13
12
use syntax_pos:: DUMMY_SP ;
14
13
use std:: rc:: Rc ;
15
14
use std:: iter;
@@ -474,8 +473,9 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
474
473
( & ty:: Array ( a_t, sz_a) , & ty:: Array ( b_t, sz_b) ) =>
475
474
{
476
475
let t = relation. relate ( & a_t, & b_t) ?;
477
- let to_u64 = |x : ty:: Const < ' tcx > | -> Result < u64 , ErrorReported > {
478
- match x. val {
476
+
477
+ let to_u64 = |ct : & ' tcx ty:: Const < ' tcx > | -> Option < u64 > {
478
+ match ct. val {
479
479
// FIXME(const_generics): this doesn't work right now,
480
480
// because it tries to relate an `Infer` to a `Param`.
481
481
ConstValue :: Unevaluated ( def_id, substs) => {
@@ -493,36 +493,32 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
493
493
instance,
494
494
promoted : None ,
495
495
} ;
496
- if let Some ( s) = tcx. const_eval ( param_env. and ( cid) )
497
- . ok ( )
498
- . map ( |c| c. unwrap_usize ( tcx) ) {
499
- return Ok ( s)
500
- }
496
+ return tcx. const_eval ( param_env. and ( cid) )
497
+ . ok ( )
498
+ . map ( |c| c. unwrap_usize ( tcx) ) ;
501
499
}
502
500
}
503
- tcx. sess . delay_span_bug ( tcx. def_span ( def_id) ,
504
- "array length could not be evaluated" ) ;
505
- Err ( ErrorReported )
501
+ None
506
502
}
507
- _ => x. assert_usize ( tcx) . ok_or_else ( || {
508
- tcx. sess . delay_span_bug ( DUMMY_SP ,
509
- "array length could not be evaluated" ) ;
510
- ErrorReported
511
- } )
503
+ _ => ct. assert_usize ( tcx) ,
512
504
}
513
505
} ;
514
- match ( to_u64 ( * sz_a) , to_u64 ( * sz_b) ) {
515
- ( Ok ( sz_a_u64) , Ok ( sz_b_u64) ) => {
506
+ match ( to_u64 ( sz_a) , to_u64 ( sz_b) ) {
507
+ ( Some ( sz_a_u64) , Some ( sz_b_u64) ) => {
516
508
if sz_a_u64 == sz_b_u64 {
517
509
Ok ( tcx. mk_ty ( ty:: Array ( t, sz_a) ) )
518
510
} else {
519
511
Err ( TypeError :: FixedArraySize (
520
512
expected_found ( relation, & sz_a_u64, & sz_b_u64) ) )
521
513
}
522
514
}
523
- // We reported an error or will ICE, so we can return Error.
524
- ( Err ( ErrorReported ) , _) | ( _, Err ( ErrorReported ) ) => {
525
- Ok ( tcx. types . err )
515
+ _ => {
516
+ if let Ok ( sz) = relation. relate ( & sz_a, & sz_b) {
517
+ Ok ( tcx. mk_ty ( ty:: Array ( t, sz) ) )
518
+ } else {
519
+ tcx. sess . delay_span_bug ( DUMMY_SP , "array length could not be evaluated" ) ;
520
+ Ok ( tcx. types . err )
521
+ }
526
522
}
527
523
}
528
524
}
0 commit comments