Skip to content

Commit 88ca341

Browse files
committed
Switched from FxHashMap to BTreeMap to preserve ordering when iterating.
1 parent 783bad4 commit 88ca341

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/librustc_mir/borrow_check/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ use rustc::ty::{self, ParamEnv, TyCtxt, Ty};
2727

2828
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
2929
use rustc_data_structures::bit_set::BitSet;
30-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
30+
use rustc_data_structures::fx::FxHashSet;
3131
use rustc_data_structures::graph::dominators::Dominators;
3232
use rustc_data_structures::indexed_vec::Idx;
3333
use smallvec::SmallVec;
3434

3535
use std::rc::Rc;
36+
use std::collections::BTreeMap;
3637

3738
use syntax_pos::Span;
3839

@@ -256,7 +257,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
256257
locals_are_invalidated_at_exit,
257258
access_place_error_reported: FxHashSet(),
258259
reservation_error_reported: FxHashSet(),
259-
move_error_reported: FxHashMap(),
260+
move_error_reported: BTreeMap::new(),
260261
uninitialized_error_reported: FxHashSet(),
261262
errors_buffer,
262263
nonlexical_regioncx: regioncx,
@@ -336,7 +337,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
336337
}
337338

338339
// Buffer any move errors that we collected and de-duplicated.
339-
for (_, (_, diag)) in mbcx.move_error_reported.drain() {
340+
for (_, (_, diag)) in mbcx.move_error_reported {
340341
diag.buffer(&mut mbcx.errors_buffer);
341342
}
342343

@@ -425,7 +426,11 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
425426
/// `Place` of the previous most diagnostic. This happens instead of buffering the error. Once
426427
/// all move errors have been reported, any diagnostics in this map are added to the buffer
427428
/// to be emitted.
428-
move_error_reported: FxHashMap<Vec<MoveOutIndex>, (Place<'tcx>, DiagnosticBuilder<'cx>)>,
429+
///
430+
/// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
431+
/// when errors in the map are being re-added to the error buffer so that errors with the
432+
/// same primary span come out in a consistent order.
433+
move_error_reported: BTreeMap<Vec<MoveOutIndex>, (Place<'tcx>, DiagnosticBuilder<'cx>)>,
429434
/// This field keeps track of errors reported in the checking of uninitialized variables,
430435
/// so that we don't report seemingly duplicate errors.
431436
uninitialized_error_reported: FxHashSet<Place<'tcx>>,

src/test/ui/borrowck/borrowck-multiple-captures.nll.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@ LL | drop(x2); //~ ERROR cannot move `x2` into closure because it is bor
2626
LL | borrow(&*p2);
2727
| ---- borrow later used here
2828

29-
error[E0382]: use of moved value: `x2`
29+
error[E0382]: use of moved value: `x1`
3030
--> $DIR/borrowck-multiple-captures.rs:35:19
3131
|
32-
LL | drop(x2);
32+
LL | drop(x1);
3333
| -- value moved here
34+
...
3435
LL | thread::spawn(move|| {
3536
| ^^^^^^ value used here after move
3637
LL | drop(x1); //~ ERROR capture of moved value: `x1`
37-
LL | drop(x2); //~ ERROR capture of moved value: `x2`
3838
| -- use occurs due to use in closure
3939
|
40-
= note: move occurs because `x2` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
40+
= note: move occurs because `x1` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
4141

42-
error[E0382]: use of moved value: `x1`
42+
error[E0382]: use of moved value: `x2`
4343
--> $DIR/borrowck-multiple-captures.rs:35:19
4444
|
45-
LL | drop(x1);
45+
LL | drop(x2);
4646
| -- value moved here
47-
...
4847
LL | thread::spawn(move|| {
4948
| ^^^^^^ value used here after move
5049
LL | drop(x1); //~ ERROR capture of moved value: `x1`
50+
LL | drop(x2); //~ ERROR capture of moved value: `x2`
5151
| -- use occurs due to use in closure
5252
|
53-
= note: move occurs because `x1` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
53+
= note: move occurs because `x2` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
5454

5555
error[E0382]: use of moved value: `x`
5656
--> $DIR/borrowck-multiple-captures.rs:46:14

0 commit comments

Comments
 (0)