about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-09-24 13:45:19 +0300
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-09-24 13:45:19 +0300
commitb6bce56ac718a6343e44b37110e6c273ab9b6189 (patch)
treee6313097fe8f620abd0b13a0dd80b3b2a49dba62 /src
parent9d6b9d62ba67fd2ff5d97ae958c954ad2c45d04d (diff)
sort the list of inference errors by span
this should produce more error stability
Diffstat (limited to 'src')
-rw-r--r--src/librustc/infer/error_reporting/mod.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs
index a88e90caee3..b24c9690a46 100644
--- a/src/librustc/infer/error_reporting/mod.rs
+++ b/src/librustc/infer/error_reporting/mod.rs
@@ -333,11 +333,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
             GenericBoundFailure(..) => true,
         };
 
-        if errors.iter().all(|e| is_bound_failure(e)) {
+
+        let mut errors = if errors.iter().all(|e| is_bound_failure(e)) {
             errors.clone()
         } else {
             errors.iter().filter(|&e| !is_bound_failure(e)).cloned().collect()
-        }
+        };
+
+        // sort the errors by span, for better error message stability.
+        errors.sort_by_key(|u| match *u {
+            ConcreteFailure(ref sro, _, _) => sro.span(),
+            GenericBoundFailure(ref sro, _, _) => sro.span(),
+            SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
+        });
+        errors
     }
 
     /// Adds a note if the types come from similarly named crates