Skip to content

Commit

Permalink
Switched from FxHashMap to BTreeMap to preserve ordering when iterating.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtwco committed Sep 18, 2018
1 parent 783bad4 commit 88ca341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ use rustc::ty::{self, ParamEnv, TyCtxt, Ty};

use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::indexed_vec::Idx;
use smallvec::SmallVec;

use std::rc::Rc;
use std::collections::BTreeMap;

use syntax_pos::Span;

Expand Down Expand Up @@ -256,7 +257,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
locals_are_invalidated_at_exit,
access_place_error_reported: FxHashSet(),
reservation_error_reported: FxHashSet(),
move_error_reported: FxHashMap(),
move_error_reported: BTreeMap::new(),
uninitialized_error_reported: FxHashSet(),
errors_buffer,
nonlexical_regioncx: regioncx,
Expand Down Expand Up @@ -336,7 +337,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
}

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

Expand Down Expand Up @@ -425,7 +426,11 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
/// `Place` of the previous most diagnostic. This happens instead of buffering the error. Once
/// all move errors have been reported, any diagnostics in this map are added to the buffer
/// to be emitted.
move_error_reported: FxHashMap<Vec<MoveOutIndex>, (Place<'tcx>, DiagnosticBuilder<'cx>)>,
///
/// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
/// when errors in the map are being re-added to the error buffer so that errors with the
/// same primary span come out in a consistent order.
move_error_reported: BTreeMap<Vec<MoveOutIndex>, (Place<'tcx>, DiagnosticBuilder<'cx>)>,
/// This field keeps track of errors reported in the checking of uninitialized variables,
/// so that we don't report seemingly duplicate errors.
uninitialized_error_reported: FxHashSet<Place<'tcx>>,
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/borrowck/borrowck-multiple-captures.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ LL | drop(x2); //~ ERROR cannot move `x2` into closure because it is bor
LL | borrow(&*p2);
| ---- borrow later used here

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

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

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

0 comments on commit 88ca341

Please sign in to comment.