Auto merge of #52024 - oli-obk:existential_parse, r=nikomatsakis
Implement existential types (not for associated types yet) r? @nikomatsakis cc @Centril @varkor @alexreg
This commit is contained in:
@@ -1570,6 +1570,7 @@ struct AllTypes {
|
||||
macros: HashSet<ItemEntry>,
|
||||
functions: HashSet<ItemEntry>,
|
||||
typedefs: HashSet<ItemEntry>,
|
||||
existentials: HashSet<ItemEntry>,
|
||||
statics: HashSet<ItemEntry>,
|
||||
constants: HashSet<ItemEntry>,
|
||||
keywords: HashSet<ItemEntry>,
|
||||
@@ -1586,6 +1587,7 @@ impl AllTypes {
|
||||
macros: HashSet::with_capacity(100),
|
||||
functions: HashSet::with_capacity(100),
|
||||
typedefs: HashSet::with_capacity(100),
|
||||
existentials: HashSet::with_capacity(100),
|
||||
statics: HashSet::with_capacity(100),
|
||||
constants: HashSet::with_capacity(100),
|
||||
keywords: HashSet::with_capacity(100),
|
||||
@@ -1607,6 +1609,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::Static => self.statics.insert(ItemEntry::new(new_url, name)),
|
||||
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
|
||||
_ => true,
|
||||
@@ -1650,6 +1653,7 @@ impl fmt::Display for AllTypes {
|
||||
print_entries(f, &self.macros, "Macros", "macros")?;
|
||||
print_entries(f, &self.functions, "Functions", "functions")?;
|
||||
print_entries(f, &self.typedefs, "Typedefs", "typedefs")?;
|
||||
print_entries(f, &self.existentials, "Existentials", "existentials")?;
|
||||
print_entries(f, &self.statics, "Statics", "statics")?;
|
||||
print_entries(f, &self.constants, "Constants", "constants")
|
||||
}
|
||||
@@ -2098,6 +2102,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 ")?,
|
||||
_ => {
|
||||
// We don't generate pages for any other type.
|
||||
unreachable!();
|
||||
@@ -2162,6 +2167,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),
|
||||
_ => {
|
||||
// We don't generate pages for any other type.
|
||||
unreachable!();
|
||||
@@ -2711,18 +2717,17 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter,
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
t: &clean::Trait) -> fmt::Result {
|
||||
fn bounds(t_bounds: &[clean::GenericBound]) -> String {
|
||||
let mut bounds = String::new();
|
||||
let mut bounds_plain = String::new();
|
||||
if !t.bounds.is_empty() {
|
||||
if !t_bounds.is_empty() {
|
||||
if !bounds.is_empty() {
|
||||
bounds.push(' ');
|
||||
bounds_plain.push(' ');
|
||||
}
|
||||
bounds.push_str(": ");
|
||||
bounds_plain.push_str(": ");
|
||||
for (i, p) in t.bounds.iter().enumerate() {
|
||||
for (i, p) in t_bounds.iter().enumerate() {
|
||||
if i > 0 {
|
||||
bounds.push_str(" + ");
|
||||
bounds_plain.push_str(" + ");
|
||||
@@ -2731,7 +2736,16 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
bounds_plain.push_str(&format!("{:#}", *p));
|
||||
}
|
||||
}
|
||||
bounds
|
||||
}
|
||||
|
||||
fn item_trait(
|
||||
w: &mut fmt::Formatter,
|
||||
cx: &Context,
|
||||
it: &clean::Item,
|
||||
t: &clean::Trait,
|
||||
) -> fmt::Result {
|
||||
let bounds = bounds(&t.bounds);
|
||||
let types = t.items.iter().filter(|m| m.is_associated_type()).collect::<Vec<_>>();
|
||||
let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::<Vec<_>>();
|
||||
let required = t.items.iter().filter(|m| m.is_ty_method()).collect::<Vec<_>>();
|
||||
@@ -3936,6 +3950,29 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn item_existential(
|
||||
w: &mut fmt::Formatter,
|
||||
cx: &Context,
|
||||
it: &clean::Item,
|
||||
t: &clean::Existential,
|
||||
) -> fmt::Result {
|
||||
write!(w, "<pre class='rust existential'>")?;
|
||||
render_attributes(w, it)?;
|
||||
write!(w, "existential type {}{}{where_clause}: {bounds};</pre>",
|
||||
it.name.as_ref().unwrap(),
|
||||
t.generics,
|
||||
where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true },
|
||||
bounds = bounds(&t.bounds))?;
|
||||
|
||||
document(w, cx, it)?;
|
||||
|
||||
// Render any items associated directly to this alias, as otherwise they
|
||||
// won't be visible anywhere in the docs. It would be nice to also show
|
||||
// associated items from the aliased type (see discussion in #32077), but
|
||||
// we need #14072 to make sense of the generics.
|
||||
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
|
||||
}
|
||||
|
||||
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
t: &clean::Typedef) -> fmt::Result {
|
||||
write!(w, "<pre class='rust typedef'>")?;
|
||||
@@ -4435,6 +4472,7 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) {
|
||||
ItemType::AssociatedConst => ("associated-consts", "Associated Constants"),
|
||||
ItemType::ForeignType => ("foreign-types", "Foreign Types"),
|
||||
ItemType::Keyword => ("keywords", "Keywords"),
|
||||
ItemType::Existential => ("existentials", "Existentials"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user