From b6bce56ac718a6343e44b37110e6c273ab9b6189 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 24 Sep 2017 13:45:19 +0300 Subject: [PATCH] sort the list of inference errors by span this should produce more error stability --- src/librustc/infer/error_reporting/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index a88e90caee307..b24c9690a4618 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