Skip to content

Commit 5f98537

Browse files
committedJul 2, 2022
Auto merge of #98569 - nnethercote:finalize_resolutions_id, r=cjgillot
Avoid unnecessary work in `finalize_resolutions_in`. If `module.opt_def_id()` returns `None`, we can skip most of the work. r? `@lqd`
2 parents f2d9393 + 0e475b5 commit 5f98537

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed
 

‎compiler/rustc_resolve/src/imports.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -1090,31 +1090,31 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
10901090
// Since import resolution is finished, globs will not define any more names.
10911091
*module.globs.borrow_mut() = Vec::new();
10921092

1093-
let mut reexports = Vec::new();
1094-
1095-
module.for_each_child(self.r, |_, ident, _, binding| {
1096-
// FIXME: Consider changing the binding inserted by `#[macro_export] macro_rules`
1097-
// into the crate root to actual `NameBindingKind::Import`.
1098-
if binding.is_import()
1099-
|| matches!(binding.kind, NameBindingKind::Res(_, _is_macro_export @ true))
1100-
{
1101-
let res = binding.res().expect_non_local();
1102-
// Ambiguous imports are treated as errors at this point and are
1103-
// not exposed to other crates (see #36837 for more details).
1104-
if res != def::Res::Err && !binding.is_ambiguity() {
1105-
reexports.push(ModChild {
1106-
ident,
1107-
res,
1108-
vis: binding.vis,
1109-
span: binding.span,
1110-
macro_rules: false,
1111-
});
1093+
if let Some(def_id) = module.opt_def_id() {
1094+
let mut reexports = Vec::new();
1095+
1096+
module.for_each_child(self.r, |_, ident, _, binding| {
1097+
// FIXME: Consider changing the binding inserted by `#[macro_export] macro_rules`
1098+
// into the crate root to actual `NameBindingKind::Import`.
1099+
if binding.is_import()
1100+
|| matches!(binding.kind, NameBindingKind::Res(_, _is_macro_export @ true))
1101+
{
1102+
let res = binding.res().expect_non_local();
1103+
// Ambiguous imports are treated as errors at this point and are
1104+
// not exposed to other crates (see #36837 for more details).
1105+
if res != def::Res::Err && !binding.is_ambiguity() {
1106+
reexports.push(ModChild {
1107+
ident,
1108+
res,
1109+
vis: binding.vis,
1110+
span: binding.span,
1111+
macro_rules: false,
1112+
});
1113+
}
11121114
}
1113-
}
1114-
});
1115+
});
11151116

1116-
if !reexports.is_empty() {
1117-
if let Some(def_id) = module.opt_def_id() {
1117+
if !reexports.is_empty() {
11181118
// Call to `expect_local` should be fine because current
11191119
// code is only called for local modules.
11201120
self.r.reexport_map.insert(def_id.expect_local(), reexports);

0 commit comments

Comments
 (0)
Please sign in to comment.