Skip to content

Commit 08c6167

Browse files
committed
Ensure deterministic ordering for diagnostics
1 parent 8cbeaf7 commit 08c6167

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type MigrationNeededForCapture = (Option<hir::HirId>, String, String);
9696

9797
/// Intermediate format to store the hir id of the root variable and a HashSet containing
9898
/// information on why the root variable should be fully captured
99-
type MigrationDiagnosticInfo = (hir::HirId, FxHashSet<MigrationNeededForCapture>);
99+
type MigrationDiagnosticInfo = (hir::HirId, Vec<MigrationNeededForCapture>);
100100

101101
struct InferBorrowKindVisitor<'a, 'tcx> {
102102
fcx: &'a FnCtxt<'a, 'tcx>,
@@ -861,7 +861,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
861861

862862
// Perform auto-trait analysis
863863
for (&var_hir_id, _) in upvars.iter() {
864-
let mut responsible_captured_hir_ids = FxHashSet::default();
864+
let mut responsible_captured_hir_ids = Vec::new();
865865

866866
let auto_trait_diagnostic = if let Some(diagnostics_info) =
867867
self.compute_2229_migrations_for_trait(min_captures, var_hir_id, closure_clause)
@@ -891,6 +891,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
891891
capture_diagnostic.insert(key.clone());
892892
}
893893

894+
let mut capture_diagnostic = capture_diagnostic.into_iter().collect::<Vec<_>>();
895+
capture_diagnostic.sort();
894896
for captured_info in capture_diagnostic.iter() {
895897
// Get the auto trait reasons of why migration is needed because of that capture, if there are any
896898
let capture_trait_reasons =
@@ -907,7 +909,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
907909
// auto trait implementation issues
908910
auto_trait_migration_reasons.extend(capture_trait_reasons.clone());
909911

910-
responsible_captured_hir_ids.insert((
912+
responsible_captured_hir_ids.push((
911913
captured_info.0,
912914
captured_info.1.clone(),
913915
self.compute_2229_migrations_reasons(

src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ LL | let _f_1 = f1.1;
9090
LL | }
9191
| -
9292
| |
93-
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.1` would be dropped here alongside the closure
9493
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.0` would be dropped here alongside the closure
94+
| in Rust 2018, `f1` would be dropped here, but in Rust 2021, only `f1.1` would be dropped here alongside the closure
9595
|
9696
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
9797
help: add a dummy let to cause `f1` to be fully captured

src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ LL | let _x = u.1.0;
4444
LL | }
4545
| -
4646
| |
47-
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
4847
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.0` would be dropped here alongside the closure
48+
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.0.1` would be dropped here alongside the closure
4949
| in Rust 2018, `u` would be dropped here, but in Rust 2021, only `u.1.0` would be dropped here alongside the closure
5050
|
5151
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>

0 commit comments

Comments
 (0)