@@ -241,32 +241,16 @@ pub(super) fn check_fn<'a, 'tcx>(
241
241
// we saw and assigning it to the expected return type. This isn't
242
242
// really expected to fail, since the coercions would have failed
243
243
// earlier when trying to find a LUB.
244
- //
245
- // However, the behavior around `!` is sort of complex. In the
246
- // event that the `actual_return_ty` comes back as `!`, that
247
- // indicates that the fn either does not return or "returns" only
248
- // values of type `!`. In this case, if there is an expected
249
- // return type that is *not* `!`, that should be ok. But if the
250
- // return type is being inferred, we want to "fallback" to `!`:
251
- //
252
- // let x = move || panic!();
253
- //
254
- // To allow for that, I am creating a type variable with diverging
255
- // fallback. This was deemed ever so slightly better than unifying
256
- // the return value with `!` because it allows for the caller to
257
- // make more assumptions about the return type (e.g., they could do
258
- //
259
- // let y: Option<u32> = Some(x());
260
- //
261
- // which would then cause this return type to become `u32`, not
262
- // `!`).
263
244
let coercion = fcx. ret_coercion . take ( ) . unwrap ( ) . into_inner ( ) ;
264
245
let mut actual_return_ty = coercion. complete ( & fcx) ;
265
- if actual_return_ty. is_never ( ) {
266
- actual_return_ty = fcx. next_diverging_ty_var ( TypeVariableOrigin {
267
- kind : TypeVariableOriginKind :: DivergingFn ,
268
- span,
269
- } ) ;
246
+ debug ! ( "actual_return_ty = {:?}" , actual_return_ty) ;
247
+ if let ty:: Dynamic ( ..) = declared_ret_ty. kind ( ) {
248
+ // We have special-cased the case where the function is declared
249
+ // `-> dyn Foo` and we don't actually relate it to the
250
+ // `fcx.ret_coercion`, so just substitute a type variable.
251
+ actual_return_ty =
252
+ fcx. next_ty_var ( TypeVariableOrigin { kind : TypeVariableOriginKind :: DynReturnFn , span } ) ;
253
+ debug ! ( "actual_return_ty replaced with {:?}" , actual_return_ty) ;
270
254
}
271
255
fcx. demand_suptype ( span, revealed_ret_ty, actual_return_ty) ;
272
256
0 commit comments