Rollup merge of #129597 - bvanjoi:resolve, r=petrochenkov
mv `build_reduced_graph_for_external_crate_res` into Resolver `build_reduced_graph_for_external_crate_res` is only related to `Resolver`, so move it there. r? `@petrochenkov`
This commit is contained in:
commit
1d58ac0ff7
@ -197,8 +197,77 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
||||||
for child in self.tcx.module_children(module.def_id()) {
|
for child in self.tcx.module_children(module.def_id()) {
|
||||||
let parent_scope = ParentScope::module(module, self);
|
let parent_scope = ParentScope::module(module, self);
|
||||||
BuildReducedGraphVisitor { r: self, parent_scope }
|
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
|
||||||
.build_reduced_graph_for_external_crate_res(child);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds the reduced graph for a single item in an external crate.
|
||||||
|
fn build_reduced_graph_for_external_crate_res(
|
||||||
|
&mut self,
|
||||||
|
child: &ModChild,
|
||||||
|
parent_scope: ParentScope<'a>,
|
||||||
|
) {
|
||||||
|
let parent = parent_scope.module;
|
||||||
|
let ModChild { ident, res, vis, ref reexport_chain } = *child;
|
||||||
|
let span = self.def_span(
|
||||||
|
reexport_chain
|
||||||
|
.first()
|
||||||
|
.and_then(|reexport| reexport.id())
|
||||||
|
.unwrap_or_else(|| res.def_id()),
|
||||||
|
);
|
||||||
|
let res = res.expect_non_local();
|
||||||
|
let expansion = parent_scope.expansion;
|
||||||
|
// Record primary definitions.
|
||||||
|
match res {
|
||||||
|
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, def_id) => {
|
||||||
|
let module = self.expect_module(def_id);
|
||||||
|
self.define(parent, ident, TypeNS, (module, vis, span, expansion));
|
||||||
|
}
|
||||||
|
Res::Def(
|
||||||
|
DefKind::Struct
|
||||||
|
| DefKind::Union
|
||||||
|
| DefKind::Variant
|
||||||
|
| DefKind::TyAlias
|
||||||
|
| DefKind::ForeignTy
|
||||||
|
| DefKind::OpaqueTy
|
||||||
|
| DefKind::TraitAlias
|
||||||
|
| DefKind::AssocTy,
|
||||||
|
_,
|
||||||
|
)
|
||||||
|
| Res::PrimTy(..)
|
||||||
|
| Res::ToolMod => self.define(parent, ident, TypeNS, (res, vis, span, expansion)),
|
||||||
|
Res::Def(
|
||||||
|
DefKind::Fn
|
||||||
|
| DefKind::AssocFn
|
||||||
|
| DefKind::Static { .. }
|
||||||
|
| DefKind::Const
|
||||||
|
| DefKind::AssocConst
|
||||||
|
| DefKind::Ctor(..),
|
||||||
|
_,
|
||||||
|
) => self.define(parent, ident, ValueNS, (res, vis, span, expansion)),
|
||||||
|
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
|
||||||
|
self.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
||||||
|
}
|
||||||
|
Res::Def(
|
||||||
|
DefKind::TyParam
|
||||||
|
| DefKind::ConstParam
|
||||||
|
| DefKind::ExternCrate
|
||||||
|
| DefKind::Use
|
||||||
|
| DefKind::ForeignMod
|
||||||
|
| DefKind::AnonConst
|
||||||
|
| DefKind::InlineConst
|
||||||
|
| DefKind::Field
|
||||||
|
| DefKind::LifetimeParam
|
||||||
|
| DefKind::GlobalAsm
|
||||||
|
| DefKind::Closure
|
||||||
|
| DefKind::Impl { .. },
|
||||||
|
_,
|
||||||
|
)
|
||||||
|
| Res::Local(..)
|
||||||
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
|
| Res::SelfCtor(..)
|
||||||
|
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -967,72 +1036,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the reduced graph for a single item in an external crate.
|
|
||||||
fn build_reduced_graph_for_external_crate_res(&mut self, child: &ModChild) {
|
|
||||||
let parent = self.parent_scope.module;
|
|
||||||
let ModChild { ident, res, vis, ref reexport_chain } = *child;
|
|
||||||
let span = self.r.def_span(
|
|
||||||
reexport_chain
|
|
||||||
.first()
|
|
||||||
.and_then(|reexport| reexport.id())
|
|
||||||
.unwrap_or_else(|| res.def_id()),
|
|
||||||
);
|
|
||||||
let res = res.expect_non_local();
|
|
||||||
let expansion = self.parent_scope.expansion;
|
|
||||||
// Record primary definitions.
|
|
||||||
match res {
|
|
||||||
Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, def_id) => {
|
|
||||||
let module = self.r.expect_module(def_id);
|
|
||||||
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
|
|
||||||
}
|
|
||||||
Res::Def(
|
|
||||||
DefKind::Struct
|
|
||||||
| DefKind::Union
|
|
||||||
| DefKind::Variant
|
|
||||||
| DefKind::TyAlias
|
|
||||||
| DefKind::ForeignTy
|
|
||||||
| DefKind::OpaqueTy
|
|
||||||
| DefKind::TraitAlias
|
|
||||||
| DefKind::AssocTy,
|
|
||||||
_,
|
|
||||||
)
|
|
||||||
| Res::PrimTy(..)
|
|
||||||
| Res::ToolMod => self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
|
|
||||||
Res::Def(
|
|
||||||
DefKind::Fn
|
|
||||||
| DefKind::AssocFn
|
|
||||||
| DefKind::Static { .. }
|
|
||||||
| DefKind::Const
|
|
||||||
| DefKind::AssocConst
|
|
||||||
| DefKind::Ctor(..),
|
|
||||||
_,
|
|
||||||
) => self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
|
|
||||||
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
|
|
||||||
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
|
||||||
}
|
|
||||||
Res::Def(
|
|
||||||
DefKind::TyParam
|
|
||||||
| DefKind::ConstParam
|
|
||||||
| DefKind::ExternCrate
|
|
||||||
| DefKind::Use
|
|
||||||
| DefKind::ForeignMod
|
|
||||||
| DefKind::AnonConst
|
|
||||||
| DefKind::InlineConst
|
|
||||||
| DefKind::Field
|
|
||||||
| DefKind::LifetimeParam
|
|
||||||
| DefKind::GlobalAsm
|
|
||||||
| DefKind::Closure
|
|
||||||
| DefKind::Impl { .. },
|
|
||||||
_,
|
|
||||||
)
|
|
||||||
| Res::Local(..)
|
|
||||||
| Res::SelfTyParam { .. }
|
|
||||||
| Res::SelfTyAlias { .. }
|
|
||||||
| Res::SelfCtor(..)
|
|
||||||
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_macro_use_binding(
|
fn add_macro_use_binding(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user