Sort in DefMap::dump, since HashMap iteration order isn't defined

This commit is contained in:
Amos Wenger 2022-07-24 16:04:20 +02:00
parent ff317858c1
commit d8c0d88e4f
4 changed files with 33 additions and 34 deletions

View file

@ -48,8 +48,8 @@
//! the result
pub mod attr_resolution;
pub mod diagnostics;
mod collector;
pub mod diagnostics;
mod mod_resolution;
mod path_resolution;
mod proc_macro;
@ -57,10 +57,11 @@ mod proc_macro;
#[cfg(test)]
mod tests;
use std::sync::Arc;
use std::{cmp::Ord, sync::Arc};
use base_db::{CrateId, Edition, FileId};
use hir_expand::{name::Name, InFile, MacroDefId};
use itertools::Itertools;
use la_arena::Arena;
use profile::Count;
use rustc_hash::FxHashMap;
@ -333,11 +334,7 @@ impl DefMap {
pub(crate) fn crate_root(&self, db: &dyn DefDatabase) -> ModuleId {
self.with_ancestor_maps(db, self.root, &mut |def_map, _module| {
if def_map.block.is_none() {
Some(def_map.module_id(def_map.root))
} else {
None
}
if def_map.block.is_none() { Some(def_map.module_id(def_map.root)) } else { None }
})
.expect("DefMap chain without root")
}
@ -431,7 +428,9 @@ impl DefMap {
map.modules[module].scope.dump(buf);
for (name, child) in map.modules[module].children.iter() {
for (name, child) in
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
{
let path = format!("{}::{}", path, name);
buf.push('\n');
go(buf, map, &path, *child);

View file

@ -648,11 +648,11 @@ mod b {
a: t
b: t
crate::b
T: v
crate::a
T: t v
crate::b
T: v
"#]],
);
}
@ -704,13 +704,13 @@ use crate::reex::*;
reex: t
tr: t
crate::tr
PrivTr: t
PubTr: t
crate::reex
_: t
_: t
crate::tr
PrivTr: t
PubTr: t
"#]],
);
}
@ -920,14 +920,14 @@ use some_module::unknown_func;
some_module: t
unknown_func: v
crate::some_module
unknown_func: v
crate::other_module
some_submodule: t
crate::other_module::some_submodule
unknown_func: v
crate::some_module
unknown_func: v
"#]],
)
}

View file

@ -315,8 +315,13 @@ mod d {
c: t
d: t
crate::d
Y: t v
crate::a
foo: t
crate::a::foo
X: t v
crate::b
foo: t
crate::c
@ -325,14 +330,9 @@ mod d {
crate::c::foo
Y: t v
crate::b
crate::d
Y: t v
foo: t
crate::a
foo: t
crate::a::foo
X: t v
"#]],
);
}

View file

@ -439,15 +439,8 @@ macro_rules! baz {
m7: t
ok_double_macro_use_shadow: v
crate::m7
crate::m1
crate::m5
m6: t
crate::m5::m6
crate::m2
crate::m3
@ -462,6 +455,13 @@ macro_rules! baz {
ok_shadow_deep: v
crate::m3::m5
crate::m5
m6: t
crate::m5::m6
crate::m7
"#]],
);
// FIXME: should not see `NotFoundBefore`