@@ -389,65 +389,49 @@ impl<'a, 'tcx> CastCheck<'tcx> {
389
389
if let ty:: Ref ( reg, cast_ty, mutbl) = * self . cast_ty . kind ( ) {
390
390
if let ty:: RawPtr ( TypeAndMut { ty : expr_ty, .. } ) = * self . expr_ty . kind ( )
391
391
&& fcx
392
- . try_coerce (
393
- self . expr ,
392
+ . can_coerce (
394
393
Ty :: new_ref ( fcx. tcx ,
395
394
fcx. tcx . lifetimes . re_erased ,
396
395
TypeAndMut { ty : expr_ty, mutbl } ,
397
396
) ,
398
397
self . cast_ty ,
399
- AllowTwoPhase :: No ,
400
- None ,
401
398
)
402
- . is_ok ( )
403
399
{
404
400
sugg = Some ( ( format ! ( "&{}*" , mutbl. prefix_str( ) ) , cast_ty == expr_ty) ) ;
405
401
} else if let ty:: Ref ( expr_reg, expr_ty, expr_mutbl) = * self . expr_ty . kind ( )
406
402
&& expr_mutbl == Mutability :: Not
407
403
&& mutbl == Mutability :: Mut
408
404
&& fcx
409
- . try_coerce (
410
- self . expr ,
405
+ . can_coerce (
411
406
Ty :: new_ref ( fcx. tcx ,
412
407
expr_reg,
413
408
TypeAndMut { ty : expr_ty, mutbl : Mutability :: Mut } ,
414
409
) ,
415
410
self . cast_ty ,
416
- AllowTwoPhase :: No ,
417
- None ,
418
411
)
419
- . is_ok ( )
420
412
{
421
413
sugg_mutref = true ;
422
414
}
423
415
424
416
if !sugg_mutref
425
417
&& sugg == None
426
418
&& fcx
427
- . try_coerce (
428
- self . expr ,
419
+ . can_coerce (
429
420
Ty :: new_ref ( fcx. tcx , reg, TypeAndMut { ty : self . expr_ty , mutbl } ) ,
430
421
self . cast_ty ,
431
- AllowTwoPhase :: No ,
432
- None ,
433
422
)
434
- . is_ok ( )
435
423
{
436
424
sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
437
425
}
438
426
} else if let ty:: RawPtr ( TypeAndMut { mutbl, .. } ) = * self . cast_ty . kind ( )
439
427
&& fcx
440
- . try_coerce (
441
- self . expr ,
428
+ . can_coerce (
442
429
Ty :: new_ref ( fcx. tcx ,
443
430
fcx. tcx . lifetimes . re_erased ,
444
431
TypeAndMut { ty : self . expr_ty , mutbl } ,
445
432
) ,
446
433
self . cast_ty ,
447
- AllowTwoPhase :: No ,
448
- None ,
449
434
)
450
- . is_ok ( )
451
435
{
452
436
sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
453
437
}
@@ -760,7 +744,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
760
744
ty:: FnDef ( ..) => {
761
745
// Attempt a coercion to a fn pointer type.
762
746
let f = fcx. normalize ( self . expr_span , self . expr_ty . fn_sig ( fcx. tcx ) ) ;
763
- let res = fcx. try_coerce (
747
+ let res = fcx. coerce (
764
748
self . expr ,
765
749
self . expr_ty ,
766
750
Ty :: new_fn_ptr ( fcx. tcx , f) ,
@@ -860,7 +844,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
860
844
861
845
( _, DynStar ) => {
862
846
if fcx. tcx . features ( ) . dyn_star {
863
- bug ! ( "should be handled by `try_coerce `" )
847
+ bug ! ( "should be handled by `coerce `" )
864
848
} else {
865
849
Err ( CastError :: IllegalCast )
866
850
}
@@ -956,7 +940,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
956
940
957
941
// Coerce to a raw pointer so that we generate AddressOf in MIR.
958
942
let array_ptr_type = Ty :: new_ptr ( fcx. tcx , m_expr) ;
959
- fcx. try_coerce ( self . expr , self . expr_ty , array_ptr_type, AllowTwoPhase :: No , None )
943
+ fcx. coerce ( self . expr , self . expr_ty , array_ptr_type, AllowTwoPhase :: No , None )
960
944
. unwrap_or_else ( |_| {
961
945
bug ! (
962
946
"could not cast from reference to array to pointer to array ({:?} to {:?})" ,
@@ -992,7 +976,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
992
976
}
993
977
994
978
fn try_coercion_cast ( & self , fcx : & FnCtxt < ' a , ' tcx > ) -> Result < ( ) , ty:: error:: TypeError < ' tcx > > {
995
- match fcx. try_coerce ( self . expr , self . expr_ty , self . cast_ty , AllowTwoPhase :: No , None ) {
979
+ match fcx. coerce ( self . expr , self . expr_ty , self . cast_ty , AllowTwoPhase :: No , None ) {
996
980
Ok ( _) => Ok ( ( ) ) ,
997
981
Err ( err) => Err ( err) ,
998
982
}
0 commit comments