@@ -2,6 +2,7 @@ use core::ops::ControlFlow;
22use  std:: borrow:: Cow ; 
33use  std:: path:: PathBuf ; 
44
5+ use  rustc_abi:: ExternAbi ; 
56use  rustc_ast:: TraitObjectSyntax ; 
67use  rustc_data_structures:: fx:: FxHashMap ; 
78use  rustc_data_structures:: unord:: UnordSet ; 
@@ -2799,32 +2800,57 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27992800        } 
28002801
28012802        // Note any argument mismatches 
2802-         let  given_ty = params. skip_binder ( ) ; 
2803+         let  ty:: Tuple ( given)  = * params. skip_binder ( ) . kind ( )  else  { 
2804+             return ; 
2805+         } ; 
2806+ 
28032807        let  expected_ty = trait_pred. skip_binder ( ) . trait_ref . args . type_at ( 1 ) ; 
2804-         if  let  ty:: Tuple ( given)  = given_ty. kind ( ) 
2805-             && let  ty:: Tuple ( expected)  = expected_ty. kind ( ) 
2806-         { 
2807-             if  expected. len ( )  != given. len ( )  { 
2808-                 // Note number of types that were expected and given 
2809-                 err. note ( 
2810-                     format ! ( 
2811-                         "expected a closure taking {} argument{}, but one taking {} argument{} was given" , 
2812-                         given. len( ) , 
2813-                         pluralize!( given. len( ) ) , 
2814-                         expected. len( ) , 
2815-                         pluralize!( expected. len( ) ) , 
2816-                     ) 
2817-                 ) ; 
2818-             }  else  if  !self . same_type_modulo_infer ( given_ty,  expected_ty)  { 
2819-                 // Print type mismatch 
2820-                 let  ( expected_args,  given_args)  = self . cmp ( given_ty,  expected_ty) ; 
2821-                 err. note_expected_found ( 
2822-                     & "a closure with arguments" , 
2823-                     expected_args, 
2824-                     & "a closure with arguments" , 
2825-                     given_args, 
2826-                 ) ; 
2827-             } 
2808+         let  ty:: Tuple ( expected)  = * expected_ty. kind ( )  else  { 
2809+             return ; 
2810+         } ; 
2811+ 
2812+         if  expected. len ( )  != given. len ( )  { 
2813+             // Note number of types that were expected and given 
2814+             err. note ( format ! ( 
2815+                 "expected a closure taking {} argument{}, but one taking {} argument{} was given" , 
2816+                 given. len( ) , 
2817+                 pluralize!( given. len( ) ) , 
2818+                 expected. len( ) , 
2819+                 pluralize!( expected. len( ) ) , 
2820+             ) ) ; 
2821+             return ; 
2822+         } 
2823+ 
2824+         let  given_ty = Ty :: new_fn_ptr ( 
2825+             self . tcx , 
2826+             params. rebind ( self . tcx . mk_fn_sig ( 
2827+                 given, 
2828+                 self . tcx . types . unit , 
2829+                 false , 
2830+                 hir:: Safety :: Safe , 
2831+                 ExternAbi :: Rust , 
2832+             ) ) , 
2833+         ) ; 
2834+         let  expected_ty = Ty :: new_fn_ptr ( 
2835+             self . tcx , 
2836+             trait_pred. rebind ( self . tcx . mk_fn_sig ( 
2837+                 expected, 
2838+                 self . tcx . types . unit , 
2839+                 false , 
2840+                 hir:: Safety :: Safe , 
2841+                 ExternAbi :: Rust , 
2842+             ) ) , 
2843+         ) ; 
2844+ 
2845+         if  !self . same_type_modulo_infer ( given_ty,  expected_ty)  { 
2846+             // Print type mismatch 
2847+             let  ( expected_args,  given_args)  = self . cmp ( expected_ty,  given_ty) ; 
2848+             err. note_expected_found ( 
2849+                 "a closure with signature" , 
2850+                 expected_args, 
2851+                 "a closure with signature" , 
2852+                 given_args, 
2853+             ) ; 
28282854        } 
28292855    } 
28302856
0 commit comments