Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Remove OpaqueTy #127276

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2748,10 +2748,9 @@ fn clean_maybe_renamed_item<'tcx>(
type_: clean_ty(ty, cx),
kind: ConstantKind::Local { body: body_id, def_id },
})),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
camelid marked this conversation as resolved.
Show resolved Hide resolved
bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
generics: clean_generics(ty.generics, cx),
}),
// clean_ty changes types which reference an OpaqueTy item to instead be
// an ImplTrait, so it's ok to return nothing here.
ItemKind::OpaqueTy(_) => return vec![],
ItemKind::TyAlias(hir_ty, generics) => {
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
let rustdoc_ty = clean_ty(hir_ty, cx);
Expand Down Expand Up @@ -2834,7 +2833,7 @@ fn clean_maybe_renamed_item<'tcx>(
ItemKind::Use(path, kind) => {
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
}
_ => unreachable!("not yet converted"),
_ => span_bug!(item.span, "not yet converted"),
};

vec![generate_item_with_correct_attrs(
Expand Down
9 changes: 0 additions & 9 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ pub(crate) enum ItemKind {
FunctionItem(Box<Function>),
ModuleItem(Module),
TypeAliasItem(Box<TypeAlias>),
OpaqueTyItem(OpaqueTy),
StaticItem(Static),
TraitItem(Box<Trait>),
TraitAliasItem(TraitAlias),
Expand Down Expand Up @@ -882,7 +881,6 @@ impl ItemKind {
| ImportItem(_)
| FunctionItem(_)
| TypeAliasItem(_)
| OpaqueTyItem(_)
| StaticItem(_)
| ConstantItem(_)
| TraitAliasItem(_)
Expand Down Expand Up @@ -916,7 +914,6 @@ impl ItemKind {
| ExternCrateItem { .. }
| FunctionItem(_)
| TypeAliasItem(_)
| OpaqueTyItem(_)
| StaticItem(_)
| ConstantItem(_)
| TraitAliasItem(_)
Expand Down Expand Up @@ -2339,12 +2336,6 @@ pub(crate) struct TypeAlias {
pub(crate) item_type: Option<Type>,
}

#[derive(Clone, Debug)]
pub(crate) struct OpaqueTy {
pub(crate) bounds: Vec<GenericBound>,
pub(crate) generics: Generics,
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct BareFunctionDecl {
pub(crate) safety: hir::Safety,
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub(crate) trait DocFolder: Sized {
ExternCrateItem { src: _ }
| ImportItem(_)
| FunctionItem(_)
| OpaqueTyItem(_)
| StaticItem(_)
| ConstantItem(..)
| TraitAliasItem(_)
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {

clean::ExternCrateItem { .. }
| clean::ImportItem(..)
| clean::OpaqueTyItem(..)
| clean::ImplItem(..)
| clean::TyMethodItem(..)
| clean::MethodItem(..)
Expand Down
4 changes: 1 addition & 3 deletions src/librustdoc/formats/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) enum ItemType {
AssocConst = 19,
Union = 20,
ForeignType = 21,
OpaqueTy = 22,
// OpaqueTy used to be here, but it was removed in #127276
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @notriddle, as this is part of the rustdoc-the-binary<->rustdoc-search boundry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine. The "existential" names aren't doing anything, and can probably be replaced with empty strings.

// This mapping table should match the discriminants of
// `rustdoc::formats::item_type::ItemType` type in Rust.
const itemTypes = [
"keyword",
"primitive",
"mod",
"externcrate",
"import",
"struct", // 5
"enum",
"fn",
"type",
"static",
"trait", // 10
"impl",
"tymethod",
"method",
"structfield",
"variant", // 15
"macro",
"associatedtype",
"constant",
"associatedconstant",
"union", // 20
"foreigntype",
"existential",
"attr",
"derive",
"traitalias", // 25
"generic",
];
const longItemTypes = [
"keyword",
"primitive type",
"module",
"extern crate",
"re-export",
"struct",
"enum",
"function",
"type alias",
"static",
"trait",
"",
"trait method",
"method",
"struct field",
"enum variant",
"macro",
"assoc type",
"constant",
"assoc const",
"union",
"foreign type",
"existential type",
"attribute macro",
"derive macro",
"trait alias",
];

ProcAttribute = 23,
ProcDerive = 24,
TraitAlias = 25,
Expand Down Expand Up @@ -84,7 +84,6 @@ impl<'a> From<&'a clean::Item> for ItemType {
clean::EnumItem(..) => ItemType::Enum,
clean::FunctionItem(..) => ItemType::Function,
clean::TypeAliasItem(..) => ItemType::TypeAlias,
clean::OpaqueTyItem(..) => ItemType::OpaqueTy,
clean::StaticItem(..) => ItemType::Static,
clean::ConstantItem(..) => ItemType::Constant,
clean::TraitItem(..) => ItemType::Trait,
Expand Down Expand Up @@ -191,7 +190,6 @@ impl ItemType {
ItemType::AssocConst => "associatedconstant",
ItemType::ForeignType => "foreigntype",
ItemType::Keyword => "keyword",
ItemType::OpaqueTy => "opaque",
ItemType::ProcAttribute => "attr",
ItemType::ProcDerive => "derive",
ItemType::TraitAlias => "traitalias",
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ impl AllTypes {
ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)),
ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)),
ItemType::TypeAlias => self.type_aliases.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 => {
Expand Down Expand Up @@ -2299,7 +2298,6 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
ItemType::AssocConst => ItemSection::AssociatedConstants,
ItemType::ForeignType => ItemSection::ForeignTypes,
ItemType::Keyword => ItemSection::Keywords,
ItemType::OpaqueTy => ItemSection::OpaqueTypes,
ItemType::ProcAttribute => ItemSection::AttributeMacros,
ItemType::ProcDerive => ItemSection::DeriveMacros,
ItemType::TraitAlias => ItemSection::TraitAliases,
Expand Down
31 changes: 0 additions & 31 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
clean::ConstantItem(..) => "Constant ",
clean::ForeignTypeItem => "Foreign Type ",
clean::KeywordItem => "Keyword ",
clean::OpaqueTyItem(..) => "Opaque Type ",
clean::TraitAliasItem(..) => "Trait Alias ",
_ => {
// We don't generate pages for any other type.
Expand Down Expand Up @@ -270,7 +269,6 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
clean::ConstantItem(ci) => item_constant(buf, cx, item, &ci.generics, &ci.type_, &ci.kind),
clean::ForeignTypeItem => item_foreign_type(buf, cx, item),
clean::KeywordItem => item_keyword(buf, cx, item),
clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e),
clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta),
_ => {
// We don't generate pages for any other type.
Expand Down Expand Up @@ -1197,35 +1195,6 @@ fn item_trait_alias(
.unwrap();
}

fn item_opaque_ty(
w: &mut impl fmt::Write,
cx: &mut Context<'_>,
it: &clean::Item,
t: &clean::OpaqueTy,
) {
wrap_item(w, |w| {
write!(
w,
"{attrs}type {name}{generics}{where_clause} = impl {bounds};",
attrs = render_attributes_in_pre(it, "", cx),
name = it.name.unwrap(),
generics = t.generics.print(cx),
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
bounds = bounds(&t.bounds, false, cx),
)
.unwrap();
});

write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap();

// 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.
write!(w, "{}", render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All))
.unwrap();
}

fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
wrap_item(w, |w| {
write!(
Expand Down
8 changes: 0 additions & 8 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
ForeignStaticItem(s, _) => ItemEnum::Static(s.into_tcx(tcx)),
ForeignTypeItem => ItemEnum::ForeignType,
TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_tcx(tcx)),
OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)),
// FIXME(generic_const_items): Add support for generic free consts
ConstantItem(ci) => {
ItemEnum::Constant { type_: ci.type_.into_tcx(tcx), const_: ci.kind.into_tcx(tcx) }
Expand Down Expand Up @@ -830,12 +829,6 @@ impl FromWithTcx<Box<clean::TypeAlias>> for TypeAlias {
}
}

impl FromWithTcx<clean::OpaqueTy> for OpaqueTy {
fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
OpaqueTy { bounds: opaque.bounds.into_tcx(tcx), generics: opaque.generics.into_tcx(tcx) }
}
}

impl FromWithTcx<clean::Static> for Static {
fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self {
Static {
Expand Down Expand Up @@ -867,7 +860,6 @@ impl FromWithTcx<ItemType> for ItemKind {
Enum => ItemKind::Enum,
Function | TyMethod | Method => ItemKind::Function,
TypeAlias => ItemKind::TypeAlias,
OpaqueTy => ItemKind::OpaqueTy,
Static => ItemKind::Static,
Constant => ItemKind::Constant,
Trait => ItemKind::Trait,
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
| types::ItemEnum::TraitAlias(_)
| types::ItemEnum::Impl(_)
| types::ItemEnum::TypeAlias(_)
| types::ItemEnum::OpaqueTy(_)
| types::ItemEnum::Constant { .. }
| types::ItemEnum::Static(_)
| types::ItemEnum::ForeignType
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
return Some(ret);
}
// These items can all get re-exported
clean::OpaqueTyItem(..)
| clean::TypeAliasItem(..)
clean::TypeAliasItem(..)
| clean::StaticItem(..)
| clean::StructItem(..)
| clean::EnumItem(..)
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub(crate) trait DocVisitor: Sized {
| ImportItem(_)
| FunctionItem(_)
| TypeAliasItem(_)
| OpaqueTyItem(_)
| StaticItem(_)
| ConstantItem(..)
| TraitAliasItem(_)
Expand Down
10 changes: 1 addition & 9 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 32;
pub const FORMAT_VERSION: u32 = 33;

/// The root of the emitted JSON blob.
///
Expand Down Expand Up @@ -326,7 +326,6 @@ pub enum ItemKind {
Function,
/// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
TypeAlias,
OpaqueTy,
/// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
Constant,
/// A `trait` declaration.
Expand Down Expand Up @@ -414,7 +413,6 @@ pub enum ItemEnum {

/// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
TypeAlias(TypeAlias),
OpaqueTy(OpaqueTy),
/// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
Constant {
/// The type of the constant.
Expand Down Expand Up @@ -1200,12 +1198,6 @@ pub struct TypeAlias {
pub generics: Generics,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct OpaqueTy {
pub bounds: Vec<GenericBound>,
pub generics: Generics,
}

/// A `static` declaration.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Static {
Expand Down
5 changes: 0 additions & 5 deletions src/tools/jsondoclint/src/item_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub(crate) enum Kind {
Variant,
Function,
TypeAlias,
OpaqueTy,
Constant,
Trait,
TraitAlias,
Expand Down Expand Up @@ -55,7 +54,6 @@ impl Kind {

// FIXME(adotinthevoid): I'm not sure if these are correct
Keyword => false,
OpaqueTy => false,
ProcAttribute => false,
ProcDerive => false,

Expand Down Expand Up @@ -99,7 +97,6 @@ impl Kind {
Kind::Enum => false,
Kind::Variant => false,
Kind::TypeAlias => false,
Kind::OpaqueTy => false,
Kind::Constant => false,
Kind::Trait => false,
Kind::TraitAlias => false,
Expand Down Expand Up @@ -149,7 +146,6 @@ impl Kind {
ItemEnum::TraitAlias(_) => TraitAlias,
ItemEnum::Impl(_) => Impl,
ItemEnum::TypeAlias(_) => TypeAlias,
ItemEnum::OpaqueTy(_) => OpaqueTy,
ItemEnum::Constant { .. } => Constant,
ItemEnum::Static(_) => Static,
ItemEnum::Macro(_) => Macro,
Expand Down Expand Up @@ -177,7 +173,6 @@ impl Kind {
ItemKind::Keyword => Keyword,
ItemKind::Macro => Macro,
ItemKind::Module => Module,
ItemKind::OpaqueTy => OpaqueTy,
ItemKind::Primitive => Primitive,
ItemKind::ProcAttribute => ProcAttribute,
ItemKind::ProcDerive => ProcDerive,
Expand Down
12 changes: 3 additions & 9 deletions src/tools/jsondoclint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::hash::Hash;

use rustdoc_json_types::{
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, ItemSummary, Module,
OpaqueTy, Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias,
Type, TypeAlias, TypeBinding, TypeBindingKind, Union, Variant, VariantKind, WherePredicate,
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, ItemSummary, Module, Path,
Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeAlias,
TypeBinding, TypeBindingKind, Union, Variant, VariantKind, WherePredicate,
};
use serde_json::Value;

Expand Down Expand Up @@ -101,7 +101,6 @@ impl<'a> Validator<'a> {
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
ItemEnum::Impl(x) => self.check_impl(x, id),
ItemEnum::TypeAlias(x) => self.check_type_alias(x),
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x),
ItemEnum::Constant { type_, const_ } => {
self.check_type(type_);
self.check_constant(const_);
Expand Down Expand Up @@ -230,11 +229,6 @@ impl<'a> Validator<'a> {
self.check_type(&x.type_);
}

fn check_opaque_ty(&mut self, x: &'a OpaqueTy) {
x.bounds.iter().for_each(|b| self.check_generic_bound(b));
self.check_generics(&x.generics);
}

fn check_constant(&mut self, _x: &'a Constant) {
// nop
}
Expand Down
29 changes: 29 additions & 0 deletions tests/rustdoc-json/impl-trait-in-assoc-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ignore-tidy-linelength
#![feature(impl_trait_in_assoc_type)]

pub struct AlwaysTrue;

/// impl IntoIterator
impl IntoIterator for AlwaysTrue {
//@ set Item = '$.index[*][?(@.docs=="type Item")].id'
/// type Item
type Item = bool;

//@ count '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[*]' 1
//@ is '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.name' '"Iterator"'
//@ count '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.args.angle_bracketed.bindings[*]' 1
//@ is '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.args.angle_bracketed.bindings[0].name' '"Item"'
//@ is '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.args.angle_bracketed.bindings[0].binding.equality.type.primitive' '"bool"'

//@ set IntoIter = '$.index[*][?(@.docs=="type IntoIter")].id'
/// type IntoIter
type IntoIter = impl Iterator<Item = bool>;

//@ set into_iter = '$.index[*][?(@.docs=="fn into_iter")].id'
/// fn into_iter
fn into_iter(self) -> Self::IntoIter {
std::iter::repeat(true)
}
}

//@ ismany '$.index[*][?(@.docs=="impl IntoIterator")].inner.impl.items[*]' $Item $IntoIter $into_iter
17 changes: 17 additions & 0 deletions tests/rustdoc/type-alias/impl_trait_in_assoc_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(impl_trait_in_assoc_type)]

pub struct AlwaysTrue;

//@ has impl_trait_in_assoc_type/struct.AlwaysTrue.html

impl IntoIterator for AlwaysTrue {
type Item = bool;

//@ has - '//*[@id="associatedtype.IntoIter"]//h4[@class="code-header"]' \
// 'type IntoIter = impl Iterator<Item = bool>'
type IntoIter = impl Iterator<Item = bool>;

fn into_iter(self) -> Self::IntoIter {
std::iter::repeat(true)
}
}
Loading