1
Fork 0

Avoid unnecessary work in finalize_resolutions_in.

If `module.opt_def_id()` returns `None`, we can skip most of the work.
This commit is contained in:
Nicholas Nethercote 2022-06-27 16:29:56 +10:00
parent 788ddedb0d
commit 0e475b5d5e

View file

@ -1090,31 +1090,31 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
// Since import resolution is finished, globs will not define any more names. // Since import resolution is finished, globs will not define any more names.
*module.globs.borrow_mut() = Vec::new(); *module.globs.borrow_mut() = Vec::new();
let mut reexports = Vec::new(); if let Some(def_id) = module.opt_def_id() {
let mut reexports = Vec::new();
module.for_each_child(self.r, |_, ident, _, binding| { module.for_each_child(self.r, |_, ident, _, binding| {
// FIXME: Consider changing the binding inserted by `#[macro_export] macro_rules` // FIXME: Consider changing the binding inserted by `#[macro_export] macro_rules`
// into the crate root to actual `NameBindingKind::Import`. // into the crate root to actual `NameBindingKind::Import`.
if binding.is_import() if binding.is_import()
|| matches!(binding.kind, NameBindingKind::Res(_, _is_macro_export @ true)) || matches!(binding.kind, NameBindingKind::Res(_, _is_macro_export @ true))
{ {
let res = binding.res().expect_non_local(); let res = binding.res().expect_non_local();
// Ambiguous imports are treated as errors at this point and are // Ambiguous imports are treated as errors at this point and are
// not exposed to other crates (see #36837 for more details). // not exposed to other crates (see #36837 for more details).
if res != def::Res::Err && !binding.is_ambiguity() { if res != def::Res::Err && !binding.is_ambiguity() {
reexports.push(ModChild { reexports.push(ModChild {
ident, ident,
res, res,
vis: binding.vis, vis: binding.vis,
span: binding.span, span: binding.span,
macro_rules: false, macro_rules: false,
}); });
}
} }
} });
});
if !reexports.is_empty() { if !reexports.is_empty() {
if let Some(def_id) = module.opt_def_id() {
// Call to `expect_local` should be fine because current // Call to `expect_local` should be fine because current
// code is only called for local modules. // code is only called for local modules.
self.r.reexport_map.insert(def_id.expect_local(), reexports); self.r.reexport_map.insert(def_id.expect_local(), reexports);