add trait aliases to HIR
This commit is contained in:
parent
1b6ad1e647
commit
2eefc9db15
13 changed files with 59 additions and 8 deletions
|
|
@ -37,6 +37,7 @@ pub enum Def {
|
|||
Trait(DefId),
|
||||
TyAlias(DefId),
|
||||
TyForeign(DefId),
|
||||
TraitAlias(DefId),
|
||||
AssociatedTy(DefId),
|
||||
PrimTy(hir::PrimTy),
|
||||
TyParam(DefId),
|
||||
|
|
@ -155,7 +156,8 @@ impl Def {
|
|||
pub fn def_id(&self) -> DefId {
|
||||
match *self {
|
||||
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
|
||||
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
|
||||
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) |
|
||||
Def::TyAlias(id) | Def::TraitAlias(id) |
|
||||
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
|
||||
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
|
||||
Def::AssociatedConst(id) | Def::Macro(id, ..) |
|
||||
|
|
@ -186,6 +188,7 @@ impl Def {
|
|||
Def::VariantCtor(.., CtorKind::Fictive) => "struct variant",
|
||||
Def::Enum(..) => "enum",
|
||||
Def::TyAlias(..) => "type alias",
|
||||
Def::TraitAlias(..) => "trait alias",
|
||||
Def::AssociatedTy(..) => "associated type",
|
||||
Def::Struct(..) => "struct",
|
||||
Def::StructCtor(.., CtorKind::Fn) => "tuple struct",
|
||||
|
|
|
|||
|
|
@ -526,6 +526,11 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
|||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
|
||||
}
|
||||
ItemTraitAlias(ref generics, ref bounds) => {
|
||||
visitor.visit_id(item.id);
|
||||
visitor.visit_generics(generics);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
}
|
||||
}
|
||||
walk_list!(visitor, visit_attribute, &item.attrs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1924,9 +1924,11 @@ impl<'a> LoweringContext<'a> {
|
|||
bounds,
|
||||
items)
|
||||
}
|
||||
ItemKind::MacroDef(..) | ItemKind::Mac(..) => {
|
||||
panic!("Shouldn't still be around")
|
||||
ItemKind::TraitAlias(ref generics, ref bounds) => {
|
||||
hir::ItemTraitAlias(self.lower_generics(generics),
|
||||
self.lower_bounds(bounds, ImplTraitContext::Disallowed))
|
||||
}
|
||||
ItemKind::MacroDef(..) | ItemKind::Mac(..) => panic!("Shouldn't still be around"),
|
||||
}
|
||||
|
||||
// [1] `defaultness.has_value()` is never called for an `impl`, always `true` in order to
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
let def_data = match i.node {
|
||||
ItemKind::AutoImpl(..) | ItemKind::Impl(..) =>
|
||||
DefPathData::Impl,
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
|
||||
ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
||||
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
|
||||
DefPathData::TypeNs(i.ident.name.as_str()),
|
||||
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
|
||||
|
|
|
|||
|
|
@ -1185,6 +1185,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
|
|||
ItemStruct(..) => "struct",
|
||||
ItemUnion(..) => "union",
|
||||
ItemTrait(..) => "trait",
|
||||
ItemTraitAlias(..) => "trait alias",
|
||||
ItemImpl(..) => "impl",
|
||||
ItemAutoImpl(..) => "default impl",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1888,6 +1888,8 @@ pub enum Item_ {
|
|||
ItemUnion(VariantData, Generics),
|
||||
/// Represents a Trait Declaration
|
||||
ItemTrait(IsAuto, Unsafety, Generics, TyParamBounds, HirVec<TraitItemRef>),
|
||||
/// Represents a Trait Alias Declaration
|
||||
ItemTraitAlias(Generics, TyParamBounds),
|
||||
|
||||
/// Auto trait implementations
|
||||
///
|
||||
|
|
@ -1919,6 +1921,7 @@ impl Item_ {
|
|||
ItemStruct(..) => "struct",
|
||||
ItemUnion(..) => "union",
|
||||
ItemTrait(..) => "trait",
|
||||
ItemTraitAlias(..) => "trait alias",
|
||||
ItemImpl(..) |
|
||||
ItemAutoImpl(..) => "item",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -747,6 +747,27 @@ impl<'a> State<'a> {
|
|||
}
|
||||
self.bclose(item.span)?;
|
||||
}
|
||||
hir::ItemTraitAlias(ref generics, ref bounds) => {
|
||||
self.head("")?;
|
||||
self.print_visibility(&item.vis)?;
|
||||
self.word_nbsp("trait")?;
|
||||
self.print_name(item.name)?;
|
||||
self.print_generics(generics)?;
|
||||
let mut real_bounds = Vec::with_capacity(bounds.len());
|
||||
// FIXME(durka) this seems to be some quite outdated syntax
|
||||
for b in bounds.iter() {
|
||||
if let TraitTyParamBound(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
|
||||
self.s.space()?;
|
||||
self.word_space("for ?")?;
|
||||
self.print_trait_ref(&ptr.trait_ref)?;
|
||||
} else {
|
||||
real_bounds.push(b.clone());
|
||||
}
|
||||
}
|
||||
self.print_bounds(" = ", &real_bounds[..])?;
|
||||
self.print_where_clause(&generics.where_clause)?;
|
||||
self.s.word(";")?;
|
||||
}
|
||||
}
|
||||
self.ann.post(self, NodeItem(item))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -848,6 +848,7 @@ impl_stable_hash_for!(enum hir::Item_ {
|
|||
ItemStruct(variant_data, generics),
|
||||
ItemUnion(variant_data, generics),
|
||||
ItemTrait(is_auto, unsafety, generics, bounds, item_refs),
|
||||
ItemTraitAlias(generics, bounds),
|
||||
ItemAutoImpl(unsafety, trait_ref),
|
||||
ItemImpl(unsafety, impl_polarity, impl_defaultness, generics, trait_ref, ty, impl_item_refs)
|
||||
});
|
||||
|
|
@ -1004,6 +1005,7 @@ impl_stable_hash_for!(enum hir::def::Def {
|
|||
Variant(def_id),
|
||||
Trait(def_id),
|
||||
TyAlias(def_id),
|
||||
TraitAlias(def_id),
|
||||
AssociatedTy(def_id),
|
||||
PrimTy(prim_ty),
|
||||
TyParam(def_id),
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||
hir::ItemExternCrate(_) | hir::ItemUse(..) |
|
||||
hir::ItemTy(..) | hir::ItemStatic(..) |
|
||||
hir::ItemMod(..) | hir::ItemForeignMod(..) |
|
||||
hir::ItemImpl(..) | hir::ItemTrait(..) |
|
||||
hir::ItemImpl(..) | hir::ItemTrait(..) | hir::ItemTraitAlias(..) |
|
||||
hir::ItemStruct(..) | hir::ItemEnum(..) |
|
||||
hir::ItemUnion(..) | hir::ItemAutoImpl(..) |
|
||||
hir::ItemGlobalAsm(..) => {}
|
||||
|
|
|
|||
|
|
@ -469,6 +469,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
| hir::ItemStruct(_, ref generics)
|
||||
| hir::ItemUnion(_, ref generics)
|
||||
| hir::ItemTrait(_, _, ref generics, ..)
|
||||
| hir::ItemTraitAlias(ref generics, ..)
|
||||
| hir::ItemImpl(_, _, _, ref generics, ..) => {
|
||||
// These kinds of items have only early bound lifetime parameters.
|
||||
let mut index = if let hir::ItemTrait(..) = item.node {
|
||||
|
|
|
|||
|
|
@ -979,6 +979,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
EntryKind::Trait(self.lazy(&data))
|
||||
}
|
||||
hir::ItemExternCrate(_) |
|
||||
hir::ItemTraitAlias(..) |
|
||||
hir::ItemUse(..) => bug!("cannot encode info for item {:?}", item),
|
||||
};
|
||||
|
||||
|
|
@ -1526,7 +1527,8 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
|
|||
hir::ItemExternCrate(..) |
|
||||
hir::ItemUse(..) |
|
||||
hir::ItemAutoImpl(..) |
|
||||
hir::ItemTy(..) => {
|
||||
hir::ItemTy(..) |
|
||||
hir::ItemTraitAlias(..) => {
|
||||
// no sub-item recording needed in these cases
|
||||
}
|
||||
hir::ItemEnum(..) => {
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
|||
// Other `pub` items inherit levels from parents
|
||||
hir::ItemConst(..) | hir::ItemEnum(..) | hir::ItemExternCrate(..) |
|
||||
hir::ItemGlobalAsm(..) | hir::ItemFn(..) | hir::ItemMod(..) |
|
||||
hir::ItemStatic(..) | hir::ItemStruct(..) | hir::ItemTrait(..) |
|
||||
hir::ItemStatic(..) | hir::ItemStruct(..) |
|
||||
hir::ItemTrait(..) | hir::ItemTraitAlias(..) |
|
||||
hir::ItemTy(..) | hir::ItemUnion(..) | hir::ItemUse(..) => {
|
||||
if item.vis == hir::Public { self.prev_level } else { None }
|
||||
}
|
||||
|
|
@ -212,7 +213,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
hir::ItemUse(..) | hir::ItemStatic(..) | hir::ItemConst(..) |
|
||||
hir::ItemGlobalAsm(..) | hir::ItemTy(..) | hir::ItemMod(..) |
|
||||
hir::ItemGlobalAsm(..) | hir::ItemTy(..) | hir::ItemMod(..) | hir::ItemTraitAlias(..) |
|
||||
hir::ItemFn(..) | hir::ItemExternCrate(..) | hir::ItemAutoImpl(..) => {}
|
||||
}
|
||||
|
||||
|
|
@ -252,6 +253,11 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
hir::ItemTraitAlias(..) => {
|
||||
if item_level.is_some() {
|
||||
self.reach(item.id).generics().predicates();
|
||||
}
|
||||
}
|
||||
// Visit everything except for private impl items
|
||||
hir::ItemImpl(.., ref trait_ref, _, ref impl_item_refs) => {
|
||||
if item_level.is_some() {
|
||||
|
|
@ -1498,6 +1504,9 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
|
|||
}
|
||||
}
|
||||
}
|
||||
hir::ItemTraitAlias(..) => {
|
||||
self.check(item.id, item_visibility).generics().predicates();
|
||||
}
|
||||
hir::ItemEnum(ref def, _) => {
|
||||
self.check(item.id, item_visibility).generics().predicates();
|
||||
|
||||
|
|
|
|||
|
|
@ -894,6 +894,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
|
|||
hir::ItemTy(..) |
|
||||
hir::ItemAutoImpl(..) |
|
||||
hir::ItemTrait(..) |
|
||||
hir::ItemTraitAlias(..) |
|
||||
hir::ItemMod(..) => {
|
||||
// Nothing to do, just keep recursing...
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue