1
Fork 0

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 e436260d7a
commit 4e1a302efc
4 changed files with 33 additions and 34 deletions

View file

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

View file

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

View file

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

View file

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