@@ -2635,49 +2635,47 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2635
2635
// This shouldn't be common unless manually implementing one of the
2636
2636
// traits manually, but don't make it more confusing when it does
2637
2637
// happen.
2638
- Ok (
2639
- if Some ( expected_trait_ref. def_id ) != self . tcx . lang_items ( ) . coroutine_trait ( )
2640
- && not_tupled
2641
- {
2642
- self . report_and_explain_type_error (
2643
- TypeTrace :: trait_refs (
2644
- & obligation. cause ,
2645
- true ,
2646
- expected_trait_ref,
2647
- found_trait_ref,
2648
- ) ,
2649
- ty:: error:: TypeError :: Mismatch ,
2650
- )
2651
- } else if found. len ( ) == expected. len ( ) {
2652
- self . report_closure_arg_mismatch (
2653
- span,
2654
- found_span,
2655
- found_trait_ref,
2656
- expected_trait_ref,
2657
- obligation. cause . code ( ) ,
2658
- found_node,
2659
- obligation. param_env ,
2660
- )
2661
- } else {
2662
- let ( closure_span, closure_arg_span, found) = found_did
2663
- . and_then ( |did| {
2664
- let node = self . tcx . hir ( ) . get_if_local ( did) ?;
2665
- let ( found_span, closure_arg_span, found) =
2666
- self . get_fn_like_arguments ( node) ?;
2667
- Some ( ( Some ( found_span) , closure_arg_span, found) )
2668
- } )
2669
- . unwrap_or ( ( found_span, None , found) ) ;
2670
-
2671
- self . report_arg_count_mismatch (
2638
+ if Some ( expected_trait_ref. def_id ) != self . tcx . lang_items ( ) . coroutine_trait ( ) && not_tupled
2639
+ {
2640
+ return Ok ( self . report_and_explain_type_error (
2641
+ TypeTrace :: trait_refs ( & obligation. cause , true , expected_trait_ref, found_trait_ref) ,
2642
+ ty:: error:: TypeError :: Mismatch ,
2643
+ ) ) ;
2644
+ }
2645
+ if found. len ( ) != expected. len ( ) {
2646
+ let ( closure_span, closure_arg_span, found) = found_did
2647
+ . and_then ( |did| {
2648
+ let node = self . tcx . hir ( ) . get_if_local ( did) ?;
2649
+ let ( found_span, closure_arg_span, found) = self . get_fn_like_arguments ( node) ?;
2650
+ Some ( ( Some ( found_span) , closure_arg_span, found) )
2651
+ } )
2652
+ . unwrap_or ( ( found_span, None , found) ) ;
2653
+
2654
+ // If the coroutine take a single () as its argument,
2655
+ // the trait argument would found the coroutine take 0 arguments,
2656
+ // but get_fn_like_arguments would give 1 argument.
2657
+ // This would result in "Expected to take 1 argument, but it takes 1 argument".
2658
+ // Check again to avoid this.
2659
+ if found. len ( ) != expected. len ( ) {
2660
+ return Ok ( self . report_arg_count_mismatch (
2672
2661
span,
2673
2662
closure_span,
2674
2663
expected,
2675
2664
found,
2676
2665
found_trait_ty. is_closure ( ) ,
2677
2666
closure_arg_span,
2678
- )
2679
- } ,
2680
- )
2667
+ ) ) ;
2668
+ }
2669
+ }
2670
+ Ok ( self . report_closure_arg_mismatch (
2671
+ span,
2672
+ found_span,
2673
+ found_trait_ref,
2674
+ expected_trait_ref,
2675
+ obligation. cause . code ( ) ,
2676
+ found_node,
2677
+ obligation. param_env ,
2678
+ ) )
2681
2679
}
2682
2680
2683
2681
/// Given some node representing a fn-like thing in the HIR map,
0 commit comments