Skip to content

Commit 416dad5

Browse files
committed
rustc_mir_build: Make non-exhaustive non-empty match diagnotics deterministic
1 parent 5b8bc56 commit 416dad5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::errors::*;
99

1010
use rustc_arena::TypedArena;
1111
use rustc_ast::Mutability;
12-
use rustc_data_structures::fx::FxHashSet;
12+
use rustc_data_structures::fx::FxIndexSet;
1313
use rustc_data_structures::stack::ensure_sufficient_stack;
1414
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
1515
use rustc_hir as hir;
@@ -948,10 +948,13 @@ fn report_non_exhaustive_match<'p, 'tcx>(
948948
err.note(format!("the matched value is of type `{}`", scrut_ty));
949949

950950
if !is_empty_match {
951-
let mut non_exhaustive_tys = FxHashSet::default();
951+
let mut non_exhaustive_tys = FxIndexSet::default();
952952
// Look at the first witness.
953953
collect_non_exhaustive_tys(cx, &witnesses[0], &mut non_exhaustive_tys);
954954

955+
// Make order of diagnostics deterministic.
956+
non_exhaustive_tys.sort();
957+
955958
for ty in non_exhaustive_tys {
956959
if ty.is_ptr_sized_integral() {
957960
if ty == cx.tcx.types.usize {
@@ -1104,7 +1107,7 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11041107
fn collect_non_exhaustive_tys<'tcx>(
11051108
cx: &MatchCheckCtxt<'_, 'tcx>,
11061109
pat: &WitnessPat<'tcx>,
1107-
non_exhaustive_tys: &mut FxHashSet<Ty<'tcx>>,
1110+
non_exhaustive_tys: &mut FxIndexSet<Ty<'tcx>>,
11081111
) {
11091112
if matches!(pat.ctor(), Constructor::NonExhaustive) {
11101113
non_exhaustive_tys.insert(pat.ty());

0 commit comments

Comments
 (0)