Skip to content

Commit c31b9fa

Browse files
committed
mv build_reduced_graph_for_external_crate_res into Resolver
1 parent c6db1ca commit c31b9fa

File tree

1 file changed

+71
-68
lines changed

1 file changed

+71
-68
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

+71-68
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,77 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
197197
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
198198
for child in self.tcx.module_children(module.def_id()) {
199199
let parent_scope = ParentScope::module(module, self);
200-
BuildReducedGraphVisitor { r: self, parent_scope }
201-
.build_reduced_graph_for_external_crate_res(child);
200+
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
201+
}
202+
}
203+
204+
/// Builds the reduced graph for a single item in an external crate.
205+
fn build_reduced_graph_for_external_crate_res(
206+
&mut self,
207+
child: &ModChild,
208+
parent_scope: ParentScope<'a>,
209+
) {
210+
let parent = parent_scope.module;
211+
let ModChild { ident, res, vis, ref reexport_chain } = *child;
212+
let span = self.def_span(
213+
reexport_chain
214+
.first()
215+
.and_then(|reexport| reexport.id())
216+
.unwrap_or_else(|| res.def_id()),
217+
);
218+
let res = res.expect_non_local();
219+
let expansion = parent_scope.expansion;
220+
// Record primary definitions.
221+
match res {
222+
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, def_id) => {
223+
let module = self.expect_module(def_id);
224+
self.define(parent, ident, TypeNS, (module, vis, span, expansion));
225+
}
226+
Res::Def(
227+
DefKind::Struct
228+
| DefKind::Union
229+
| DefKind::Variant
230+
| DefKind::TyAlias
231+
| DefKind::ForeignTy
232+
| DefKind::OpaqueTy
233+
| DefKind::TraitAlias
234+
| DefKind::AssocTy,
235+
_,
236+
)
237+
| Res::PrimTy(..)
238+
| Res::ToolMod => self.define(parent, ident, TypeNS, (res, vis, span, expansion)),
239+
Res::Def(
240+
DefKind::Fn
241+
| DefKind::AssocFn
242+
| DefKind::Static { .. }
243+
| DefKind::Const
244+
| DefKind::AssocConst
245+
| DefKind::Ctor(..),
246+
_,
247+
) => self.define(parent, ident, ValueNS, (res, vis, span, expansion)),
248+
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
249+
self.define(parent, ident, MacroNS, (res, vis, span, expansion))
250+
}
251+
Res::Def(
252+
DefKind::TyParam
253+
| DefKind::ConstParam
254+
| DefKind::ExternCrate
255+
| DefKind::Use
256+
| DefKind::ForeignMod
257+
| DefKind::AnonConst
258+
| DefKind::InlineConst
259+
| DefKind::Field
260+
| DefKind::LifetimeParam
261+
| DefKind::GlobalAsm
262+
| DefKind::Closure
263+
| DefKind::Impl { .. },
264+
_,
265+
)
266+
| Res::Local(..)
267+
| Res::SelfTyParam { .. }
268+
| Res::SelfTyAlias { .. }
269+
| Res::SelfCtor(..)
270+
| Res::Err => bug!("unexpected resolution: {:?}", res),
202271
}
203272
}
204273
}
@@ -967,72 +1036,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
9671036
}
9681037
}
9691038

970-
/// Builds the reduced graph for a single item in an external crate.
971-
fn build_reduced_graph_for_external_crate_res(&mut self, child: &ModChild) {
972-
let parent = self.parent_scope.module;
973-
let ModChild { ident, res, vis, ref reexport_chain } = *child;
974-
let span = self.r.def_span(
975-
reexport_chain
976-
.first()
977-
.and_then(|reexport| reexport.id())
978-
.unwrap_or_else(|| res.def_id()),
979-
);
980-
let res = res.expect_non_local();
981-
let expansion = self.parent_scope.expansion;
982-
// Record primary definitions.
983-
match res {
984-
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, def_id) => {
985-
let module = self.r.expect_module(def_id);
986-
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
987-
}
988-
Res::Def(
989-
DefKind::Struct
990-
| DefKind::Union
991-
| DefKind::Variant
992-
| DefKind::TyAlias
993-
| DefKind::ForeignTy
994-
| DefKind::OpaqueTy
995-
| DefKind::TraitAlias
996-
| DefKind::AssocTy,
997-
_,
998-
)
999-
| Res::PrimTy(..)
1000-
| Res::ToolMod => self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
1001-
Res::Def(
1002-
DefKind::Fn
1003-
| DefKind::AssocFn
1004-
| DefKind::Static { .. }
1005-
| DefKind::Const
1006-
| DefKind::AssocConst
1007-
| DefKind::Ctor(..),
1008-
_,
1009-
) => self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
1010-
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
1011-
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
1012-
}
1013-
Res::Def(
1014-
DefKind::TyParam
1015-
| DefKind::ConstParam
1016-
| DefKind::ExternCrate
1017-
| DefKind::Use
1018-
| DefKind::ForeignMod
1019-
| DefKind::AnonConst
1020-
| DefKind::InlineConst
1021-
| DefKind::Field
1022-
| DefKind::LifetimeParam
1023-
| DefKind::GlobalAsm
1024-
| DefKind::Closure
1025-
| DefKind::Impl { .. },
1026-
_,
1027-
)
1028-
| Res::Local(..)
1029-
| Res::SelfTyParam { .. }
1030-
| Res::SelfTyAlias { .. }
1031-
| Res::SelfCtor(..)
1032-
| Res::Err => bug!("unexpected resolution: {:?}", res),
1033-
}
1034-
}
1035-
10361039
fn add_macro_use_binding(
10371040
&mut self,
10381041
name: Symbol,

0 commit comments

Comments
 (0)