@@ -211,34 +211,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211
211
// We use this to guide coercion inference; it's output is "fudged" which means
212
212
// any remaining type variables are assigned to new, unrelated variables. This
213
213
// is because the inference guidance here is only speculative.
214
- let expected_input_tys: Option < Vec < _ > > = expectation
215
- . only_has_type ( self )
216
- . and_then ( |expected_output| {
217
- self . fudge_inference_if_ok ( || {
218
- let ocx = ObligationCtxt :: new ( self ) ;
219
-
220
- // Attempt to apply a subtyping relationship between the formal
221
- // return type (likely containing type variables if the function
222
- // is polymorphic) and the expected return type.
223
- // No argument expectations are produced if unification fails.
224
- let origin = self . misc ( call_span) ;
225
- ocx. sup ( & origin, self . param_env , expected_output, formal_output) ?;
226
- if !ocx. select_where_possible ( ) . is_empty ( ) {
227
- return Err ( TypeError :: Mismatch ) ;
228
- }
214
+ //
215
+ // We only do this if the formals have non-region infer vars, since this is only
216
+ // meant to guide inference.
217
+ let expected_input_tys: Option < Vec < _ > > = if formal_input_tys. has_non_region_infer ( ) {
218
+ expectation
219
+ . only_has_type ( self )
220
+ . and_then ( |expected_output| {
221
+ self . fudge_inference_if_ok ( || {
222
+ let ocx = ObligationCtxt :: new ( self ) ;
223
+
224
+ // Attempt to apply a subtyping relationship between the formal
225
+ // return type (likely containing type variables if the function
226
+ // is polymorphic) and the expected return type.
227
+ // No argument expectations are produced if unification fails.
228
+ let origin = self . misc ( call_span) ;
229
+ ocx. sup ( & origin, self . param_env , expected_output, formal_output) ?;
230
+ if !ocx. select_where_possible ( ) . is_empty ( ) {
231
+ return Err ( TypeError :: Mismatch ) ;
232
+ }
229
233
230
- // Record all the argument types, with the args
231
- // produced from the above subtyping unification.
232
- Ok ( Some (
233
- formal_input_tys
234
- . iter ( )
235
- . map ( |& ty| self . resolve_vars_if_possible ( ty) )
236
- . collect ( ) ,
237
- ) )
234
+ // Record all the argument types, with the args
235
+ // produced from the above subtyping unification.
236
+ Ok ( Some (
237
+ formal_input_tys
238
+ . iter ( )
239
+ . map ( |& ty| self . resolve_vars_if_possible ( ty) )
240
+ . collect ( ) ,
241
+ ) )
242
+ } )
243
+ . ok ( )
238
244
} )
239
- . ok ( )
240
- } )
241
- . unwrap_or_default ( ) ;
245
+ . unwrap_or_default ( )
246
+ } else {
247
+ None
248
+ } ;
242
249
243
250
let mut err_code = E0061 ;
244
251
0 commit comments