@@ -294,8 +294,8 @@ pub fn const_eval_raw_provider<'tcx>(
294
294
) ;
295
295
296
296
let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
297
- res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, & body) )
298
- . map_err ( | error| {
297
+ match res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, & body) ) {
298
+ Err ( error) => {
299
299
let err = ConstEvalErr :: new ( & ecx, error, None ) ;
300
300
// errors in statics are always emitted as fatal errors
301
301
if is_static {
@@ -317,7 +317,7 @@ pub fn const_eval_raw_provider<'tcx>(
317
317
) ;
318
318
}
319
319
320
- v
320
+ Err ( v )
321
321
} else if let Some ( def) = def. as_local ( ) {
322
322
// constant defined in this crate, we can figure out a lint level!
323
323
match tcx. def_kind ( def. did . to_def_id ( ) ) {
@@ -331,12 +331,12 @@ pub fn const_eval_raw_provider<'tcx>(
331
331
// compatibility hazard
332
332
DefKind :: Const | DefKind :: AssocConst => {
333
333
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
334
- err. report_as_lint (
334
+ Err ( err. report_as_lint (
335
335
tcx. at ( tcx. def_span ( def. did ) ) ,
336
336
"any use of this value will cause an error" ,
337
337
hir_id,
338
338
Some ( err. span ) ,
339
- )
339
+ ) )
340
340
}
341
341
// promoting runtime code is only allowed to error if it references broken
342
342
// constants any other kind of error will be reported to the user as a
@@ -345,34 +345,34 @@ pub fn const_eval_raw_provider<'tcx>(
345
345
if let Some ( p) = cid. promoted {
346
346
let span = tcx. promoted_mir_of_opt_const_arg ( def. to_global ( ) ) [ p] . span ;
347
347
if let err_inval ! ( ReferencedConstant ) = err. error {
348
- err. report_as_error (
348
+ Err ( err. report_as_error (
349
349
tcx. at ( span) ,
350
350
"evaluation of constant expression failed" ,
351
- )
351
+ ) )
352
352
} else {
353
- err. report_as_lint (
353
+ Err ( err. report_as_lint (
354
354
tcx. at ( span) ,
355
355
"reaching this expression at runtime will panic or abort" ,
356
356
tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ,
357
357
Some ( err. span ) ,
358
- )
358
+ ) )
359
359
}
360
360
// anything else (array lengths, enum initializers, constant patterns) are
361
361
// reported as hard errors
362
362
} else {
363
- err. report_as_error (
363
+ Err ( err. report_as_error (
364
364
ecx. tcx . at ( ecx. cur_span ( ) ) ,
365
365
"evaluation of constant value failed" ,
366
- )
366
+ ) )
367
367
}
368
368
}
369
369
}
370
370
} else {
371
371
// use of broken constant from other crate
372
- err. report_as_error ( ecx. tcx . at ( ecx. cur_span ( ) ) , "could not evaluate constant" )
372
+ Err ( err. report_as_error ( ecx. tcx . at ( ecx. cur_span ( ) ) , "could not evaluate constant" ) )
373
373
}
374
- } )
375
- . and_then ( | mplace| {
374
+ }
375
+ Ok ( mplace) => {
376
376
// Since evaluation had no errors, valiate the resulting constant:
377
377
let validation = try {
378
378
// FIXME do not validate promoteds until a decision on
@@ -404,5 +404,6 @@ pub fn const_eval_raw_provider<'tcx>(
404
404
// Convert to raw constant
405
405
Ok ( RawConst { alloc_id : mplace. ptr . assert_ptr ( ) . alloc_id , ty : mplace. layout . ty } )
406
406
}
407
- } )
407
+ }
408
+ }
408
409
}
0 commit comments