@@ -389,65 +389,49 @@ impl<'a, 'tcx> CastCheck<'tcx> {
389389 if let ty:: Ref ( reg, cast_ty, mutbl) = * self . cast_ty . kind ( ) {
390390 if let ty:: RawPtr ( TypeAndMut { ty : expr_ty, .. } ) = * self . expr_ty . kind ( )
391391 && fcx
392- . try_coerce (
393- self . expr ,
392+ . can_coerce (
394393 Ty :: new_ref ( fcx. tcx ,
395394 fcx. tcx . lifetimes . re_erased ,
396395 TypeAndMut { ty : expr_ty, mutbl } ,
397396 ) ,
398397 self . cast_ty ,
399- AllowTwoPhase :: No ,
400- None ,
401398 )
402- . is_ok ( )
403399 {
404400 sugg = Some ( ( format ! ( "&{}*" , mutbl. prefix_str( ) ) , cast_ty == expr_ty) ) ;
405401 } else if let ty:: Ref ( expr_reg, expr_ty, expr_mutbl) = * self . expr_ty . kind ( )
406402 && expr_mutbl == Mutability :: Not
407403 && mutbl == Mutability :: Mut
408404 && fcx
409- . try_coerce (
410- self . expr ,
405+ . can_coerce (
411406 Ty :: new_ref ( fcx. tcx ,
412407 expr_reg,
413408 TypeAndMut { ty : expr_ty, mutbl : Mutability :: Mut } ,
414409 ) ,
415410 self . cast_ty ,
416- AllowTwoPhase :: No ,
417- None ,
418411 )
419- . is_ok ( )
420412 {
421413 sugg_mutref = true ;
422414 }
423415
424416 if !sugg_mutref
425417 && sugg == None
426418 && fcx
427- . try_coerce (
428- self . expr ,
419+ . can_coerce (
429420 Ty :: new_ref ( fcx. tcx , reg, TypeAndMut { ty : self . expr_ty , mutbl } ) ,
430421 self . cast_ty ,
431- AllowTwoPhase :: No ,
432- None ,
433422 )
434- . is_ok ( )
435423 {
436424 sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
437425 }
438426 } else if let ty:: RawPtr ( TypeAndMut { mutbl, .. } ) = * self . cast_ty . kind ( )
439427 && fcx
440- . try_coerce (
441- self . expr ,
428+ . can_coerce (
442429 Ty :: new_ref ( fcx. tcx ,
443430 fcx. tcx . lifetimes . re_erased ,
444431 TypeAndMut { ty : self . expr_ty , mutbl } ,
445432 ) ,
446433 self . cast_ty ,
447- AllowTwoPhase :: No ,
448- None ,
449434 )
450- . is_ok ( )
451435 {
452436 sugg = Some ( ( format ! ( "&{}" , mutbl. prefix_str( ) ) , false ) ) ;
453437 }
@@ -760,7 +744,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
760744 ty:: FnDef ( ..) => {
761745 // Attempt a coercion to a fn pointer type.
762746 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 (
764748 self . expr ,
765749 self . expr_ty ,
766750 Ty :: new_fn_ptr ( fcx. tcx , f) ,
@@ -860,7 +844,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
860844
861845 ( _, DynStar ) => {
862846 if fcx. tcx . features ( ) . dyn_star {
863- bug ! ( "should be handled by `try_coerce `" )
847+ bug ! ( "should be handled by `coerce `" )
864848 } else {
865849 Err ( CastError :: IllegalCast )
866850 }
@@ -956,7 +940,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
956940
957941 // Coerce to a raw pointer so that we generate AddressOf in MIR.
958942 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 )
960944 . unwrap_or_else ( |_| {
961945 bug ! (
962946 "could not cast from reference to array to pointer to array ({:?} to {:?})" ,
@@ -992,7 +976,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
992976 }
993977
994978 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 ) {
996980 Ok ( _) => Ok ( ( ) ) ,
997981 Err ( err) => Err ( err) ,
998982 }
0 commit comments