@@ -25,7 +25,7 @@ use rustc::mir::{
25
25
use rustc:: ty:: { self , RegionVid , Ty , TyCtxt , TypeFoldable } ;
26
26
use rustc:: util:: common;
27
27
use rustc_data_structures:: bit_set:: BitSet ;
28
- use rustc_data_structures:: fx:: FxHashMap ;
28
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
29
29
use rustc_data_structures:: graph:: scc:: Sccs ;
30
30
use rustc_data_structures:: indexed_vec:: IndexVec ;
31
31
use rustc_errors:: { Diagnostic , DiagnosticBuilder } ;
@@ -580,6 +580,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
580
580
) {
581
581
let tcx = infcx. tcx ;
582
582
583
+ // Sometimes we register equivalent type-tests that would
584
+ // result in basically the exact same error being reported to
585
+ // the user. Avoid that.
586
+ let mut deduplicate_errors = FxHashSet :: default ( ) ;
587
+
583
588
for type_test in & self . type_tests {
584
589
debug ! ( "check_type_test: {:?}" , type_test) ;
585
590
@@ -605,11 +610,29 @@ impl<'tcx> RegionInferenceContext<'tcx> {
605
610
}
606
611
}
607
612
608
- // Oh the humanity. Obviously we will do better than this error eventually.
613
+ // Type-test failed. Report the error.
614
+
615
+ // Try to convert the lower-bound region into something named we can print for the user.
609
616
let lower_bound_region = self . to_error_region ( type_test. lower_bound ) ;
617
+
618
+ // Skip duplicate-ish errors.
619
+ let type_test_span = type_test. locations . span ( mir) ;
620
+ let erased_generic_kind = tcx. erase_regions ( & type_test. generic_kind ) ;
621
+ if !deduplicate_errors. insert ( ( erased_generic_kind, lower_bound_region, type_test. locations ) ) {
622
+ continue ;
623
+ } else {
624
+ debug ! (
625
+ "check_type_test: reporting error for erased_generic_kind={:?}, \
626
+ lower_bound_region={:?}, \
627
+ type_test.locations={:?}",
628
+ erased_generic_kind,
629
+ lower_bound_region,
630
+ type_test. locations,
631
+ ) ;
632
+ }
633
+
610
634
if let Some ( lower_bound_region) = lower_bound_region {
611
635
let region_scope_tree = & tcx. region_scope_tree ( mir_def_id) ;
612
- let type_test_span = type_test. locations . span ( mir) ;
613
636
infcx
614
637
. construct_generic_bound_failure (
615
638
region_scope_tree,
@@ -629,7 +652,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
629
652
// to report it; we could probably handle it by
630
653
// iterating over the universal regions and reporting
631
654
// an error that multiple bounds are required.
632
- let type_test_span = type_test. locations . span ( mir) ;
633
655
tcx. sess
634
656
. struct_span_err (
635
657
type_test_span,
0 commit comments