1
Fork 0

Generate DefIds for impl Trait in the def_collector

This commit is contained in:
Oliver Schneider 2018-06-20 10:59:24 +02:00
parent f8e83a6062
commit 013fca8698
5 changed files with 17 additions and 29 deletions

View file

@ -1179,14 +1179,11 @@ impl<'a> LoweringContext<'a> {
ImplTraitContext::Universal(def_id) => { ImplTraitContext::Universal(def_id) => {
self.lower_node_id(def_node_id); self.lower_node_id(def_node_id);
// Add a definition for the in-band TyParam // Add a definition for the in-band TyParam
let def_index = self.resolver.definitions().create_def_with_parent( let def_index = self
def_id.index, .resolver
def_node_id, .definitions()
DefPathData::UniversalImplTrait, .opt_def_index(def_node_id)
DefIndexAddressSpace::High, .unwrap();
Mark::root(),
span,
);
let hir_bounds = self.lower_param_bounds(bounds, itctx); let hir_bounds = self.lower_param_bounds(bounds, itctx);
// Set the name to `impl Bound1 + Bound2` // Set the name to `impl Bound1 + Bound2`
@ -1254,18 +1251,12 @@ impl<'a> LoweringContext<'a> {
span, span,
); );
// Pull a new definition from the ether
let exist_ty_def_index = self let exist_ty_def_index = self
.resolver .resolver
.definitions() .definitions()
.create_def_with_parent( .opt_def_index(exist_ty_node_id)
fn_def_id.index, .unwrap();
exist_ty_node_id,
DefPathData::ExistentialImplTrait,
DefIndexAddressSpace::High,
Mark::root(),
exist_ty_span,
);
self.allocate_hir_id_counter(exist_ty_node_id, &"existential impl trait"); self.allocate_hir_id_counter(exist_ty_node_id, &"existential impl trait");

View file

@ -302,6 +302,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_ty(&mut self, ty: &'a Ty) { fn visit_ty(&mut self, ty: &'a Ty) {
match ty.node { match ty.node {
TyKind::Mac(..) => return self.visit_macro_invoc(ty.id), TyKind::Mac(..) => return self.visit_macro_invoc(ty.id),
TyKind::ImplTrait(node_id, _) => {
self.create_def(node_id, DefPathData::ImplTrait, REGULAR_SPACE, ty.span);
}
_ => {} _ => {}
} }
visit::walk_ty(self, ty); visit::walk_ty(self, ty);

View file

@ -374,10 +374,8 @@ pub enum DefPathData {
StructCtor, StructCtor,
/// A constant expression (see {ast,hir}::AnonConst). /// A constant expression (see {ast,hir}::AnonConst).
AnonConst, AnonConst,
/// An `impl Trait` type node in argument position. /// An `impl Trait` type node
UniversalImplTrait, ImplTrait,
/// An `impl Trait` type node in return position.
ExistentialImplTrait,
/// GlobalMetaData identifies a piece of crate metadata that is global to /// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components /// a whole crate (as opposed to just one item). GlobalMetaData components
@ -641,8 +639,7 @@ impl DefPathData {
ClosureExpr | ClosureExpr |
StructCtor | StructCtor |
AnonConst | AnonConst |
ExistentialImplTrait | ImplTrait => None
UniversalImplTrait => None
} }
} }
@ -672,8 +669,7 @@ impl DefPathData {
ClosureExpr => "{{closure}}", ClosureExpr => "{{closure}}",
StructCtor => "{{constructor}}", StructCtor => "{{constructor}}",
AnonConst => "{{constant}}", AnonConst => "{{constant}}",
ExistentialImplTrait => "{{exist-impl-Trait}}", ImplTrait => "{{impl-Trait}}",
UniversalImplTrait => "{{univ-impl-Trait}}",
}; };
Symbol::intern(s).as_interned_str() Symbol::intern(s).as_interned_str()

View file

@ -221,8 +221,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
data @ DefPathData::AnonConst | data @ DefPathData::AnonConst |
data @ DefPathData::MacroDef(..) | data @ DefPathData::MacroDef(..) |
data @ DefPathData::ClosureExpr | data @ DefPathData::ClosureExpr |
data @ DefPathData::ExistentialImplTrait | data @ DefPathData::ImplTrait |
data @ DefPathData::UniversalImplTrait |
data @ DefPathData::GlobalMetaData(..) => { data @ DefPathData::GlobalMetaData(..) => {
let parent_def_id = self.parent_def_id(def_id).unwrap(); let parent_def_id = self.parent_def_id(def_id).unwrap();
self.push_item_path(buffer, parent_def_id); self.push_item_path(buffer, parent_def_id);

View file

@ -291,8 +291,7 @@ impl PrintContext {
DefPathData::Field(_) | DefPathData::Field(_) |
DefPathData::StructCtor | DefPathData::StructCtor |
DefPathData::AnonConst | DefPathData::AnonConst |
DefPathData::ExistentialImplTrait | DefPathData::ImplTrait |
DefPathData::UniversalImplTrait |
DefPathData::GlobalMetaData(_) => { DefPathData::GlobalMetaData(_) => {
// if we're making a symbol for something, there ought // if we're making a symbol for something, there ought
// to be a value or type-def or something in there // to be a value or type-def or something in there