@@ -913,29 +913,34 @@ impl<'db> Inference<'db> {
913
913
let concrete_trait_id = self . rewrite ( concrete_trait_id) . no_err ( ) ;
914
914
enrich_lookup_context ( self . db , concrete_trait_id, & mut lookup_context) ;
915
915
916
- // Don't try to resolve impls if the first generic param is a variable.
917
- let generic_args = concrete_trait_id. generic_args ( self . db ) ;
918
- match generic_args. first ( ) {
919
- Some ( GenericArgumentId :: Type ( ty) ) => {
920
- if let TypeLongId :: Var ( _) = ty. lookup_intern ( self . db ) {
921
- // Don't try to infer such impls.
922
- return Ok ( SolutionSet :: Ambiguous ( Ambiguity :: WillNotInfer ( concrete_trait_id) ) ) ;
916
+ // If has any type assignments, we can try to resolve it, even if first generic arg is a
917
+ // var.
918
+ if !impl_var_trait_item_mappings
919
+ . types
920
+ . iter ( )
921
+ . any ( |( _, ty) | ty. is_var_free ( self . db ) && !ty. is_missing ( self . db ) )
922
+ {
923
+ // Don't try to resolve impls if the first generic param is a variable.
924
+ let dont_infer = Ok ( SolutionSet :: Ambiguous ( Ambiguity :: WillNotInfer ( concrete_trait_id) ) ) ;
925
+ match concrete_trait_id. generic_args ( self . db ) . first ( ) {
926
+ Some ( GenericArgumentId :: Type ( ty) )
927
+ if matches ! ( ty. lookup_intern( self . db) , TypeLongId :: Var ( _) ) =>
928
+ {
929
+ return dont_infer;
923
930
}
924
- }
925
- Some ( GenericArgumentId :: Impl ( imp) ) => {
926
- // Don't try to infer such impls.
927
- if let ImplLongId :: ImplVar ( _) = imp. lookup_intern ( self . db ) {
928
- return Ok ( SolutionSet :: Ambiguous ( Ambiguity :: WillNotInfer ( concrete_trait_id) ) ) ;
931
+ Some ( GenericArgumentId :: Impl ( imp) )
932
+ if matches ! ( imp. lookup_intern( self . db) , ImplLongId :: ImplVar ( _) ) =>
933
+ {
934
+ return dont_infer;
929
935
}
930
- }
931
- Some ( GenericArgumentId :: Constant ( const_value) ) => {
932
- if let ConstValue :: Var ( _, _) = const_value. lookup_intern ( self . db ) {
933
- // Don't try to infer such impls.
934
- return Ok ( SolutionSet :: Ambiguous ( Ambiguity :: WillNotInfer ( concrete_trait_id) ) ) ;
936
+ Some ( GenericArgumentId :: Constant ( const_value) )
937
+ if matches ! ( const_value. lookup_intern( self . db) , ConstValue :: Var ( _, _) ) =>
938
+ {
939
+ return dont_infer;
935
940
}
941
+ _ => { }
936
942
}
937
- _ => { }
938
- } ;
943
+ }
939
944
let ( canonical_trait, canonicalizer) = CanonicalTrait :: canonicalize (
940
945
self . db ,
941
946
self . inference_id ,
0 commit comments