@@ -2582,28 +2582,25 @@ impl<'a, 'db> ArgumentTypeChecker<'a, 'db> {
25822582 }
25832583 }
25842584
2585- // Build the specialization once without type context.
2585+ // Build the specialization once without inferring the type context.
25862586 let isolated_specialization = builder. build ( generic_context, * self . call_expression_tcx ) ;
25872587 let isolated_return_ty = self
25882588 . return_ty
25892589 . apply_specialization ( self . db , isolated_specialization) ;
25902590
25912591 // TODO: Ideally we would infer the annotated type _before_ the arguments if this call is part of an
25922592 // annotated assignment, to closer match the order of any unions written in the type annotation.
2593- if let Some ( call_expression_tcx) = self . call_expression_tcx . annotation {
2594- match call_expression_tcx {
2595- // A type variable is not a useful type-context for expression inference, and applying it
2596- // to the return type can lead to confusing unions in nested generic calls.
2597- Type :: TypeVar ( _) => { }
2598-
2599- _ => {
2600- // Ignore any specialization errors here, because the type context is only used as a hint
2601- // to infer a more assignable return type.
2602- let _ = builder. infer ( self . return_ty , call_expression_tcx) ;
2603- }
2604- }
2593+ //
2594+ // A type variable is not a useful type-context for expression inference, and applying it
2595+ // to the return type can lead to confusing unions in nested generic calls.
2596+ if let Some ( call_expression_tcx) = self . call_expression_tcx . annotation
2597+ && !call_expression_tcx. is_type_var ( )
2598+ {
2599+ // Ignore any specialization errors here, because the type context is only used as a hint
2600+ // to infer a more assignable return type.
2601+ let _ = builder. infer ( self . return_ty , call_expression_tcx) ;
26052602
2606- // Build the specialization a second time with the type context.
2603+ // Build the specialization a second time after inferring the type context.
26072604 let specialization = builder. build ( generic_context, * self . call_expression_tcx ) ;
26082605 let return_ty = self . return_ty . apply_specialization ( self . db , specialization) ;
26092606
0 commit comments