Make list_files deterministic (Closes #1141) (#1393)

- Use BTreeMap instead
This commit is contained in:
Robert Gawdzik 2017-03-21 16:00:33 -04:00 committed by Nick Cameron
parent d4c5d572c8
commit bfb1c277a8

View File

@ -11,7 +11,7 @@
use utils;
use std::path::{Path, PathBuf};
use std::collections::HashMap;
use std::collections::BTreeMap;
use syntax::ast;
use syntax::codemap;
@ -22,8 +22,8 @@ use syntax::parse::parser;
/// If a file is used twice in a crate, it appears only once.
pub fn list_files<'a>(krate: &'a ast::Crate,
codemap: &codemap::CodeMap)
-> HashMap<PathBuf, &'a ast::Mod> {
let mut result = HashMap::new();
-> BTreeMap<PathBuf, &'a ast::Mod> {
let mut result = BTreeMap::new(); // Enforce file order determinism
let root_filename: PathBuf = codemap.span_to_filename(krate.span).into();
list_submodules(&krate.module,
root_filename.parent().unwrap(),
@ -37,7 +37,7 @@ pub fn list_files<'a>(krate: &'a ast::Crate,
fn list_submodules<'a>(module: &'a ast::Mod,
search_dir: &Path,
codemap: &codemap::CodeMap,
result: &mut HashMap<PathBuf, &'a ast::Mod>) {
result: &mut BTreeMap<PathBuf, &'a ast::Mod>) {
debug!("list_submodules: search_dir: {:?}", search_dir);
for item in &module.items {
if let ast::ItemKind::Mod(ref sub_mod) = item.node {