@@ -81,6 +81,7 @@ struct Coerce<'a, 'tcx> {
8181     /// See #47489 and #48598 
8282     /// See docs on the "AllowTwoPhase" type for a more detailed discussion 
8383     allow_two_phase :  AllowTwoPhase , 
84+     coerce_never :  bool , 
8485} 
8586
8687impl < ' a ,  ' tcx >  Deref  for  Coerce < ' a ,  ' tcx >  { 
@@ -124,8 +125,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
124125        fcx :  & ' f  FnCtxt < ' f ,  ' tcx > , 
125126        cause :  ObligationCause < ' tcx > , 
126127        allow_two_phase :  AllowTwoPhase , 
128+         coerce_never :  bool , 
127129    )  -> Self  { 
128-         Coerce  {  fcx,  cause,  allow_two_phase,  use_lub :  false  } 
130+         Coerce  {  fcx,  cause,  allow_two_phase,  use_lub :  false ,  coerce_never  } 
129131    } 
130132
131133    fn  unify ( & self ,  a :  Ty < ' tcx > ,  b :  Ty < ' tcx > )  -> InferResult < ' tcx ,  Ty < ' tcx > >  { 
@@ -176,7 +178,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
176178
177179        // Coercing from `!` to any type is allowed: 
178180        if  a. is_never ( )  { 
179-             return  success ( simple ( Adjust :: NeverToAny ) ( b) ,  b,  vec ! [ ] ) ; 
181+             if  self . coerce_never  { 
182+                 return  success ( simple ( Adjust :: NeverToAny ) ( b) ,  b,  vec ! [ ] ) ; 
183+             }  else  { 
184+                 return  self . unify_and ( a,  b,  identity) ; 
185+             } 
180186        } 
181187
182188        // Coercing *from* an unresolved inference variable means that 
@@ -978,7 +984,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
978984     /// The expressions *must not* have any preexisting adjustments. 
979985     pub  fn  coerce ( 
980986        & self , 
981-         expr :  & hir:: Expr < ' _ > , 
987+         expr :  & ' tcx   hir:: Expr < ' tcx > , 
982988        expr_ty :  Ty < ' tcx > , 
983989        mut  target :  Ty < ' tcx > , 
984990        allow_two_phase :  AllowTwoPhase , 
@@ -995,7 +1001,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9951001
9961002        let  cause =
9971003            cause. unwrap_or_else ( || self . cause ( expr. span ,  ObligationCauseCode :: ExprAssignable ) ) ; 
998-         let  coerce = Coerce :: new ( self ,  cause,  allow_two_phase) ; 
1004+         let  coerce =
1005+             Coerce :: new ( self ,  cause,  allow_two_phase,  self . expr_is_rvalue_for_divergence ( expr) ) ; 
9991006        let  ok = self . commit_if_ok ( |_| coerce. coerce ( source,  target) ) ?; 
10001007
10011008        let  ( adjustments,  _)  = self . register_infer_ok_obligations ( ok) ; 
@@ -1018,7 +1025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10181025
10191026        let  cause = self . cause ( DUMMY_SP ,  ObligationCauseCode :: ExprAssignable ) ; 
10201027        // We don't ever need two-phase here since we throw out the result of the coercion 
1021-         let  coerce = Coerce :: new ( self ,  cause,  AllowTwoPhase :: No ) ; 
1028+         let  coerce = Coerce :: new ( self ,  cause,  AllowTwoPhase :: No ,   true ) ; 
10221029        self . probe ( |_| { 
10231030            let  Ok ( ok)  = coerce. coerce ( source,  target)  else  { 
10241031                return  false ; 
@@ -1035,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10351042     pub  fn  deref_steps ( & self ,  expr_ty :  Ty < ' tcx > ,  target :  Ty < ' tcx > )  -> Option < usize >  { 
10361043        let  cause = self . cause ( DUMMY_SP ,  ObligationCauseCode :: ExprAssignable ) ; 
10371044        // We don't ever need two-phase here since we throw out the result of the coercion 
1038-         let  coerce = Coerce :: new ( self ,  cause,  AllowTwoPhase :: No ) ; 
1045+         let  coerce = Coerce :: new ( self ,  cause,  AllowTwoPhase :: No ,   true ) ; 
10391046        coerce
10401047            . autoderef ( DUMMY_SP ,  expr_ty) 
10411048            . find_map ( |( ty,  steps) | self . probe ( |_| coerce. unify ( ty,  target) ) . ok ( ) . map ( |_| steps) ) 
@@ -1192,7 +1199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921199        // probably aren't processing function arguments here and even if we were, 
11931200        // they're going to get autorefed again anyway and we can apply 2-phase borrows 
11941201        // at that time. 
1195-         let  mut  coerce = Coerce :: new ( self ,  cause. clone ( ) ,  AllowTwoPhase :: No ) ; 
1202+         let  mut  coerce = Coerce :: new ( self ,  cause. clone ( ) ,  AllowTwoPhase :: No ,   true ) ; 
11961203        coerce. use_lub  = true ; 
11971204
11981205        // First try to coerce the new expression to the type of the previous ones, 
0 commit comments