@@ -737,14 +737,27 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
737
737
F : FnOnce ( Ty < ' tcx > ) -> Vec < Adjustment < ' tcx > > ,
738
738
G : FnOnce ( Ty < ' tcx > ) -> Vec < Adjustment < ' tcx > > ,
739
739
{
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
+ } )
748
761
}
749
762
750
763
fn coerce_from_fn_pointer (
@@ -1133,8 +1146,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1133
1146
let ( adjustments, target) = self . register_infer_ok_obligations ( ok) ;
1134
1147
self . apply_adjustments ( new, adjustments) ;
1135
1148
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
1138
1151
) ;
1139
1152
return Ok ( target) ;
1140
1153
}
@@ -1190,15 +1203,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1190
1203
}
1191
1204
}
1192
1205
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
- ) ;
1197
1206
let ( adjustments, target) = self . register_infer_ok_obligations ( ok) ;
1198
1207
for expr in exprs {
1199
1208
let expr = expr. as_coercion_site ( ) ;
1200
1209
self . apply_adjustments ( expr, adjustments. clone ( ) ) ;
1201
1210
}
1211
+ debug ! (
1212
+ "coercion::try_find_coercion_lub: was able to coerce previous type {:?} to new type {:?} ({:?})" ,
1213
+ prev_ty, new_ty, target
1214
+ ) ;
1202
1215
Ok ( target)
1203
1216
}
1204
1217
}
@@ -1430,6 +1443,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1430
1443
} )
1431
1444
} ;
1432
1445
1446
+ debug ! ( ?result) ;
1433
1447
match result {
1434
1448
Ok ( v) => {
1435
1449
self . final_ty = Some ( v) ;
@@ -1520,7 +1534,10 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1520
1534
augment_error ( & mut err) ;
1521
1535
}
1522
1536
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 {
1524
1541
fcx. emit_coerce_suggestions (
1525
1542
& mut err,
1526
1543
expr,
0 commit comments