@@ -737,14 +737,27 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
737737 F : FnOnce ( Ty < ' tcx > ) -> Vec < Adjustment < ' tcx > > ,
738738 G : FnOnce ( Ty < ' tcx > ) -> Vec < Adjustment < ' tcx > > ,
739739 {
740- if let ty:: FnPtr ( fn_ty_b) = b. kind ( )
741- && let ( hir:: Unsafety :: Normal , hir:: Unsafety :: Unsafe ) =
742- ( fn_ty_a. unsafety ( ) , fn_ty_b. unsafety ( ) )
743- {
744- let unsafe_a = self . tcx . safe_to_unsafe_fn_ty ( fn_ty_a) ;
745- return self . unify_and ( unsafe_a, b, to_unsafe) ;
746- }
747- self . unify_and ( a, b, normal)
740+ self . commit_unconditionally ( |snapshot| {
741+ let result = if let ty:: FnPtr ( fn_ty_b) = b. kind ( )
742+ && let ( hir:: Unsafety :: Normal , hir:: Unsafety :: Unsafe ) =
743+ ( fn_ty_a. unsafety ( ) , fn_ty_b. unsafety ( ) )
744+ {
745+ let unsafe_a = self . tcx . safe_to_unsafe_fn_ty ( fn_ty_a) ;
746+ self . unify_and ( unsafe_a, b, to_unsafe)
747+ } else {
748+ self . unify_and ( a, b, normal)
749+ } ;
750+
751+ // FIXME(#73154): This is a hack. Currently LUB can generate
752+ // unsolvable constraints. Additionally, it returns `a`
753+ // unconditionally, even when the "LUB" is `b`. In the future, we
754+ // want the coerced type to be the actual supertype of these two,
755+ // but for now, we want to just error to ensure we don't lock
756+ // ourselves into a specific behavior with NLL.
757+ self . leak_check ( false , snapshot) ?;
758+
759+ result
760+ } )
748761 }
749762
750763 fn coerce_from_fn_pointer (
@@ -1133,8 +1146,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11331146 let ( adjustments, target) = self . register_infer_ok_obligations ( ok) ;
11341147 self . apply_adjustments ( new, adjustments) ;
11351148 debug ! (
1136- "coercion::try_find_coercion_lub: was able to coerce from previous type {:?} to new type {:?}" ,
1137- prev_ty , new_ty ,
1149+ "coercion::try_find_coercion_lub: was able to coerce from new type {:?} to previous type {:?} ({:?}) " ,
1150+ new_ty , prev_ty , target
11381151 ) ;
11391152 return Ok ( target) ;
11401153 }
@@ -1190,15 +1203,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11901203 }
11911204 }
11921205 Ok ( ok) => {
1193- debug ! (
1194- "coercion::try_find_coercion_lub: was able to coerce previous type {:?} to new type {:?}" ,
1195- prev_ty, new_ty,
1196- ) ;
11971206 let ( adjustments, target) = self . register_infer_ok_obligations ( ok) ;
11981207 for expr in exprs {
11991208 let expr = expr. as_coercion_site ( ) ;
12001209 self . apply_adjustments ( expr, adjustments. clone ( ) ) ;
12011210 }
1211+ debug ! (
1212+ "coercion::try_find_coercion_lub: was able to coerce previous type {:?} to new type {:?} ({:?})" ,
1213+ prev_ty, new_ty, target
1214+ ) ;
12021215 Ok ( target)
12031216 }
12041217 }
@@ -1430,6 +1443,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14301443 } )
14311444 } ;
14321445
1446+ debug ! ( ?result) ;
14331447 match result {
14341448 Ok ( v) => {
14351449 self . final_ty = Some ( v) ;
@@ -1520,7 +1534,10 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15201534 augment_error ( & mut err) ;
15211535 }
15221536
1523- if let Some ( expr) = expression {
1537+ let is_insufficiently_polymorphic =
1538+ matches ! ( coercion_error, TypeError :: RegionsInsufficientlyPolymorphic ( ..) ) ;
1539+
1540+ if !is_insufficiently_polymorphic && let Some ( expr) = expression {
15241541 fcx. emit_coerce_suggestions (
15251542 & mut err,
15261543 expr,
0 commit comments