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