Auto merge of #63180 - varkor:trait-alias-impl-trait, r=Centril

Change opaque type syntax from `existential type` to type alias `impl Trait`

This implements a new feature gate `type_alias_impl_trait` (this is slightly different from the originally proposed feature name, but matches what has been used in discussion since), deprecating the old `existential_types` feature.

The syntax for opaque types has been changed. In addition, the "existential" terminology has been replaced with "opaque", as per previous discussion and the RFC.

This makes partial progress towards implementing https://github.com/rust-lang/rust/issues/63063.

r? @Centril
This commit is contained in:
bors 2019-08-03 02:21:23 +00:00
commit d7270712cb
202 changed files with 1050 additions and 1033 deletions

View file

@ -538,7 +538,7 @@ pub enum ItemEnum {
FunctionItem(Function),
ModuleItem(Module),
TypedefItem(Typedef, bool /* is associated type */),
ExistentialItem(Existential, bool /* is associated type */),
OpaqueTyItem(OpaqueTy, bool /* is associated type */),
StaticItem(Static),
ConstantItem(Constant),
TraitItem(Trait),
@ -574,7 +574,7 @@ impl ItemEnum {
ItemEnum::EnumItem(ref e) => &e.generics,
ItemEnum::FunctionItem(ref f) => &f.generics,
ItemEnum::TypedefItem(ref t, _) => &t.generics,
ItemEnum::ExistentialItem(ref t, _) => &t.generics,
ItemEnum::OpaqueTyItem(ref t, _) => &t.generics,
ItemEnum::TraitItem(ref t) => &t.generics,
ItemEnum::ImplItem(ref i) => &i.generics,
ItemEnum::TyMethodItem(ref i) => &i.generics,
@ -623,7 +623,7 @@ impl Clean<Item> for doctree::Module<'_> {
items.extend(self.foreigns.iter().map(|x| x.clean(cx)));
items.extend(self.mods.iter().map(|x| x.clean(cx)));
items.extend(self.typedefs.iter().map(|x| x.clean(cx)));
items.extend(self.existentials.iter().map(|x| x.clean(cx)));
items.extend(self.opaque_tys.iter().map(|x| x.clean(cx)));
items.extend(self.statics.iter().map(|x| x.clean(cx)));
items.extend(self.constants.iter().map(|x| x.clean(cx)));
items.extend(self.traits.iter().map(|x| x.clean(cx)));
@ -2257,7 +2257,7 @@ impl Clean<Item> for hir::ImplItem {
type_: ty.clean(cx),
generics: Generics::default(),
}, true),
hir::ImplItemKind::Existential(ref bounds) => ExistentialItem(Existential {
hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(OpaqueTy {
bounds: bounds.clean(cx),
generics: Generics::default(),
}, true),
@ -2415,7 +2415,7 @@ impl Clean<Item> for ty::AssocItem {
}, true)
}
}
ty::AssocKind::Existential => unimplemented!(),
ty::AssocKind::OpaqueTy => unimplemented!(),
};
let visibility = match self.container {
@ -2776,7 +2776,7 @@ impl Clean<Type> for hir::Ty {
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::Def(item_id, _) => {
let item = cx.tcx.hir().expect_item(item_id.id);
if let hir::ItemKind::Existential(ref ty) = item.node {
if let hir::ItemKind::OpaqueTy(ref ty) = item.node {
ImplTrait(ty.bounds.clean(cx))
} else {
unreachable!()
@ -3648,12 +3648,12 @@ impl Clean<Item> for doctree::Typedef<'_> {
}
#[derive(Clone, Debug)]
pub struct Existential {
pub struct OpaqueTy {
pub bounds: Vec<GenericBound>,
pub generics: Generics,
}
impl Clean<Item> for doctree::Existential<'_> {
impl Clean<Item> for doctree::OpaqueTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
Item {
name: Some(self.name.clean(cx)),
@ -3663,9 +3663,9 @@ impl Clean<Item> for doctree::Existential<'_> {
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: ExistentialItem(Existential {
bounds: self.exist_ty.bounds.clean(cx),
generics: self.exist_ty.generics.clean(cx),
inner: OpaqueTyItem(OpaqueTy {
bounds: self.opaque_ty.bounds.clean(cx),
generics: self.opaque_ty.generics.clean(cx),
}, false),
}
}

View file

@ -26,7 +26,7 @@ pub struct Module<'hir> {
pub mods: Vec<Module<'hir>>,
pub id: NodeId,
pub typedefs: Vec<Typedef<'hir>>,
pub existentials: Vec<Existential<'hir>>,
pub opaque_tys: Vec<OpaqueTy<'hir>>,
pub statics: Vec<Static<'hir>>,
pub constants: Vec<Constant<'hir>>,
pub traits: Vec<Trait<'hir>>,
@ -64,7 +64,7 @@ impl Module<'hir> {
fns : Vec::new(),
mods : Vec::new(),
typedefs : Vec::new(),
existentials: Vec::new(),
opaque_tys : Vec::new(),
statics : Vec::new(),
constants : Vec::new(),
traits : Vec::new(),
@ -162,8 +162,8 @@ pub struct Typedef<'hir> {
pub depr: Option<attr::Deprecation>,
}
pub struct Existential<'hir> {
pub exist_ty: &'hir hir::ExistTy,
pub struct OpaqueTy<'hir> {
pub opaque_ty: &'hir hir::OpaqueTy,
pub name: Name,
pub id: hir::HirId,
pub attrs: &'hir hir::HirVec<ast::Attribute>,

View file

@ -39,7 +39,7 @@ pub enum ItemType {
Union = 19,
ForeignType = 20,
Keyword = 21,
Existential = 22,
OpaqueTy = 22,
ProcAttribute = 23,
ProcDerive = 24,
TraitAlias = 25,
@ -70,7 +70,7 @@ impl<'a> From<&'a clean::Item> for ItemType {
clean::EnumItem(..) => ItemType::Enum,
clean::FunctionItem(..) => ItemType::Function,
clean::TypedefItem(..) => ItemType::Typedef,
clean::ExistentialItem(..) => ItemType::Existential,
clean::OpaqueTyItem(..) => ItemType::OpaqueTy,
clean::StaticItem(..) => ItemType::Static,
clean::ConstantItem(..) => ItemType::Constant,
clean::TraitItem(..) => ItemType::Trait,
@ -144,7 +144,7 @@ impl ItemType {
ItemType::AssocConst => "associatedconstant",
ItemType::ForeignType => "foreigntype",
ItemType::Keyword => "keyword",
ItemType::Existential => "existential",
ItemType::OpaqueTy => "opaque",
ItemType::ProcAttribute => "attr",
ItemType::ProcDerive => "derive",
ItemType::TraitAlias => "traitalias",
@ -161,7 +161,7 @@ impl ItemType {
ItemType::Trait |
ItemType::Primitive |
ItemType::AssocType |
ItemType::Existential |
ItemType::OpaqueTy |
ItemType::TraitAlias |
ItemType::ForeignType => NameSpace::Type,

View file

@ -1886,7 +1886,7 @@ struct AllTypes {
macros: FxHashSet<ItemEntry>,
functions: FxHashSet<ItemEntry>,
typedefs: FxHashSet<ItemEntry>,
existentials: FxHashSet<ItemEntry>,
opaque_tys: FxHashSet<ItemEntry>,
statics: FxHashSet<ItemEntry>,
constants: FxHashSet<ItemEntry>,
keywords: FxHashSet<ItemEntry>,
@ -1907,7 +1907,7 @@ impl AllTypes {
macros: new_set(100),
functions: new_set(100),
typedefs: new_set(100),
existentials: new_set(100),
opaque_tys: new_set(100),
statics: new_set(100),
constants: new_set(100),
keywords: new_set(100),
@ -1932,7 +1932,7 @@ impl AllTypes {
ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)),
ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)),
ItemType::Typedef => self.typedefs.insert(ItemEntry::new(new_url, name)),
ItemType::Existential => self.existentials.insert(ItemEntry::new(new_url, name)),
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)),
@ -1982,7 +1982,7 @@ impl fmt::Display for AllTypes {
print_entries(f, &self.functions, "Functions", "functions")?;
print_entries(f, &self.typedefs, "Typedefs", "typedefs")?;
print_entries(f, &self.trait_aliases, "Trait Aliases", "trait-aliases")?;
print_entries(f, &self.existentials, "Existentials", "existentials")?;
print_entries(f, &self.opaque_tys, "Opaque Types", "opaque-types")?;
print_entries(f, &self.statics, "Statics", "statics")?;
print_entries(f, &self.constants, "Constants", "constants")
}
@ -2480,7 +2480,7 @@ impl<'a> fmt::Display for Item<'a> {
clean::ConstantItem(..) => write!(fmt, "Constant ")?,
clean::ForeignTypeItem => write!(fmt, "Foreign Type ")?,
clean::KeywordItem(..) => write!(fmt, "Keyword ")?,
clean::ExistentialItem(..) => write!(fmt, "Existential Type ")?,
clean::OpaqueTyItem(..) => write!(fmt, "Opaque Type ")?,
clean::TraitAliasItem(..) => write!(fmt, "Trait Alias ")?,
_ => {
// We don't generate pages for any other type.
@ -2519,7 +2519,7 @@ impl<'a> fmt::Display for Item<'a> {
clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c),
clean::ForeignTypeItem => item_foreign_type(fmt, self.cx, self.item),
clean::KeywordItem(ref k) => item_keyword(fmt, self.cx, self.item, k),
clean::ExistentialItem(ref e, _) => item_existential(fmt, self.cx, self.item, e),
clean::OpaqueTyItem(ref e, _) => item_opaque_ty(fmt, self.cx, self.item, e),
clean::TraitAliasItem(ref ta) => item_trait_alias(fmt, self.cx, self.item, ta),
_ => {
// We don't generate pages for any other type.
@ -4390,15 +4390,15 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
Ok(())
}
fn item_existential(
fn item_opaque_ty(
w: &mut fmt::Formatter<'_>,
cx: &Context,
it: &clean::Item,
t: &clean::Existential,
t: &clean::OpaqueTy,
) -> fmt::Result {
write!(w, "<pre class='rust existential'>")?;
write!(w, "<pre class='rust opaque'>")?;
render_attributes(w, it, false)?;
write!(w, "existential type {}{}{where_clause}: {bounds};</pre>",
write!(w, "type {}{}{where_clause} = impl {bounds};</pre>",
it.name.as_ref().unwrap(),
t.generics,
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
@ -4986,7 +4986,7 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) {
ItemType::AssocConst => ("associated-consts", "Associated Constants"),
ItemType::ForeignType => ("foreign-types", "Foreign Types"),
ItemType::Keyword => ("keywords", "Keywords"),
ItemType::Existential => ("existentials", "Existentials"),
ItemType::OpaqueTy => ("opaque-types", "Opaque Types"),
ItemType::ProcAttribute => ("attributes", "Attribute Macros"),
ItemType::ProcDerive => ("derives", "Derive Macros"),
ItemType::TraitAlias => ("trait-aliases", "Trait aliases"),

View file

@ -159,7 +159,7 @@ impl<'a> DocFolder for Stripper<'a> {
return ret;
}
// These items can all get re-exported
clean::ExistentialItem(..)
clean::OpaqueTyItem(..)
| clean::TypedefItem(..)
| clean::StaticItem(..)
| clean::StructItem(..)

View file

@ -472,9 +472,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
};
om.typedefs.push(t);
},
hir::ItemKind::Existential(ref exist_ty) => {
let t = Existential {
exist_ty,
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
let t = OpaqueTy {
opaque_ty,
name: ident.name,
id: item.hir_id,
attrs: &item.attrs,
@ -483,7 +483,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
stab: self.stability(item.hir_id),
depr: self.deprecation(item.hir_id),
};
om.existentials.push(t);
om.opaque_tys.push(t);
},
hir::ItemKind::Static(ref type_, mutability, expr) => {
let s = Static {