@@ -15,6 +15,7 @@ use super::{
15
15
Obligation ,
16
16
ObligationCause ,
17
17
ObligationCauseCode ,
18
+ ParameterCountMismatch ,
18
19
OutputTypeParameterMismatch ,
19
20
TraitNotObjectSafe ,
20
21
PredicateObligation ,
@@ -54,11 +55,11 @@ pub struct TraitErrorKey<'tcx> {
54
55
impl < ' a , ' gcx , ' tcx > TraitErrorKey < ' tcx > {
55
56
fn from_error ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
56
57
e : & FulfillmentError < ' tcx > ) -> Self {
57
- let predicate =
58
- infcx. resolve_type_vars_if_possible ( & e . obligation . predicate ) ;
58
+ let predicate = infcx . resolve_type_vars_if_possible ( & e . obligation . predicate ) ;
59
+ let predicate = infcx. tcx . erase_regions ( & predicate) ;
59
60
TraitErrorKey {
60
61
span : e. obligation . cause . span ,
61
- predicate : infcx . tcx . erase_regions ( & predicate)
62
+ predicate : predicate,
62
63
}
63
64
}
64
65
}
@@ -523,6 +524,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
523
524
{
524
525
let span = obligation. cause . span ;
525
526
527
+ if !self . reported_selection_errors . borrow_mut ( ) . insert ( ( span, error. clone ( ) ) ) {
528
+ debug ! ( "report_selection_error: skipping duplicate {:?}" , error) ;
529
+ return ;
530
+ }
531
+
526
532
let mut err = match * error {
527
533
SelectionError :: Unimplemented => {
528
534
if let ObligationCauseCode :: CompareImplMethodObligation {
@@ -657,6 +663,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
657
663
}
658
664
}
659
665
666
+ ParameterCountMismatch ( expected_found, ty, def_id) => {
667
+ let found_span = self . tcx . hir . span_if_local ( def_id) ;
668
+ self . report_arg_count_mismatch ( span,
669
+ found_span,
670
+ expected_found. expected ,
671
+ expected_found. found ,
672
+ ty. is_closure ( ) )
673
+ }
660
674
OutputTypeParameterMismatch ( ref expected_trait_ref, ref actual_trait_ref, ref e) => {
661
675
let expected_trait_ref = self . resolve_type_vars_if_possible ( & * expected_trait_ref) ;
662
676
let actual_trait_ref = self . resolve_type_vars_if_possible ( & * actual_trait_ref) ;
@@ -668,49 +682,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
668
682
self . tcx . hir . span_if_local ( did)
669
683
} ) ;
670
684
671
- if let & TypeError :: TupleSize ( ref expected_found) = e {
672
- // Expected `|x| { }`, found `|x, y| { }`
673
- self . report_arg_count_mismatch ( span,
674
- found_span,
675
- expected_found. expected ,
676
- expected_found. found ,
677
- expected_trait_ty. is_closure ( ) )
678
- } else if let & TypeError :: Sorts ( ref expected_found) = e {
679
- let expected = if let ty:: TyTuple ( tys, _) = expected_found. expected . sty {
680
- tys. len ( )
681
- } else {
682
- 1
683
- } ;
684
- let found = if let ty:: TyTuple ( tys, _) = expected_found. found . sty {
685
- tys. len ( )
686
- } else {
687
- 1
688
- } ;
689
-
690
- if expected != found {
691
- // Expected `|| { }`, found `|x, y| { }`
692
- // Expected `fn(x) -> ()`, found `|| { }`
693
- self . report_arg_count_mismatch ( span,
694
- found_span,
695
- expected,
696
- found,
697
- expected_trait_ty. is_closure ( ) )
698
- } else {
699
- self . report_type_argument_mismatch ( span,
700
- found_span,
701
- expected_trait_ty,
702
- expected_trait_ref,
703
- actual_trait_ref,
704
- e)
705
- }
706
- } else {
707
- self . report_type_argument_mismatch ( span,
708
- found_span,
709
- expected_trait_ty,
710
- expected_trait_ref,
711
- actual_trait_ref,
712
- e)
713
- }
685
+ self . report_type_argument_mismatch ( span,
686
+ found_span,
687
+ expected_trait_ty,
688
+ expected_trait_ref,
689
+ actual_trait_ref,
690
+ e)
714
691
}
715
692
716
693
TraitNotObjectSafe ( did) => {
0 commit comments