@@ -15,6 +15,7 @@ use super::{
1515 Obligation ,
1616 ObligationCause ,
1717 ObligationCauseCode ,
18+ ParameterCountMismatch ,
1819 OutputTypeParameterMismatch ,
1920 TraitNotObjectSafe ,
2021 PredicateObligation ,
@@ -54,11 +55,11 @@ pub struct TraitErrorKey<'tcx> {
5455impl < ' a , ' gcx , ' tcx > TraitErrorKey < ' tcx > {
5556 fn from_error ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
5657 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) ;
5960 TraitErrorKey {
6061 span : e. obligation . cause . span ,
61- predicate : infcx . tcx . erase_regions ( & predicate)
62+ predicate : predicate,
6263 }
6364 }
6465}
@@ -523,6 +524,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
523524 {
524525 let span = obligation. cause . span ;
525526
527+ if !self . reported_selection_errors . borrow_mut ( ) . insert ( ( span, error. clone ( ) ) ) {
528+ debug ! ( "report_selection_error: skipping duplicate {:?}" , error) ;
529+ return ;
530+ }
531+
526532 let mut err = match * error {
527533 SelectionError :: Unimplemented => {
528534 if let ObligationCauseCode :: CompareImplMethodObligation {
@@ -657,6 +663,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
657663 }
658664 }
659665
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+ }
660674 OutputTypeParameterMismatch ( ref expected_trait_ref, ref actual_trait_ref, ref e) => {
661675 let expected_trait_ref = self . resolve_type_vars_if_possible ( & * expected_trait_ref) ;
662676 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> {
668682 self . tcx . hir . span_if_local ( did)
669683 } ) ;
670684
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)
714691 }
715692
716693 TraitNotObjectSafe ( did) => {
0 commit comments