Skip to content

Commit 8e86c95

Browse files
committed
Auto merge of #127276 - aDotInTheVoid:no-opaque, r=camelid
rustdoc: Remove OpaqueTy r? `@ghost` Apparently this works lol?!? try-job: aarch64-apple
2 parents a886938 + 73ac5e0 commit 8e86c95

File tree

16 files changed

+56
-87
lines changed

16 files changed

+56
-87
lines changed

src/librustdoc/clean/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2748,10 +2748,9 @@ fn clean_maybe_renamed_item<'tcx>(
27482748
type_: clean_ty(ty, cx),
27492749
kind: ConstantKind::Local { body: body_id, def_id },
27502750
})),
2751-
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
2752-
bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
2753-
generics: clean_generics(ty.generics, cx),
2754-
}),
2751+
// clean_ty changes types which reference an OpaqueTy item to instead be
2752+
// an ImplTrait, so it's ok to return nothing here.
2753+
ItemKind::OpaqueTy(_) => return vec![],
27552754
ItemKind::TyAlias(hir_ty, generics) => {
27562755
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
27572756
let rustdoc_ty = clean_ty(hir_ty, cx);
@@ -2834,7 +2833,7 @@ fn clean_maybe_renamed_item<'tcx>(
28342833
ItemKind::Use(path, kind) => {
28352834
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
28362835
}
2837-
_ => unreachable!("not yet converted"),
2836+
_ => span_bug!(item.span, "not yet converted"),
28382837
};
28392838

28402839
vec![generate_item_with_correct_attrs(

src/librustdoc/clean/types.rs

-9
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ pub(crate) enum ItemKind {
824824
FunctionItem(Box<Function>),
825825
ModuleItem(Module),
826826
TypeAliasItem(Box<TypeAlias>),
827-
OpaqueTyItem(OpaqueTy),
828827
StaticItem(Static),
829828
TraitItem(Box<Trait>),
830829
TraitAliasItem(TraitAlias),
@@ -882,7 +881,6 @@ impl ItemKind {
882881
| ImportItem(_)
883882
| FunctionItem(_)
884883
| TypeAliasItem(_)
885-
| OpaqueTyItem(_)
886884
| StaticItem(_)
887885
| ConstantItem(_)
888886
| TraitAliasItem(_)
@@ -916,7 +914,6 @@ impl ItemKind {
916914
| ExternCrateItem { .. }
917915
| FunctionItem(_)
918916
| TypeAliasItem(_)
919-
| OpaqueTyItem(_)
920917
| StaticItem(_)
921918
| ConstantItem(_)
922919
| TraitAliasItem(_)
@@ -2339,12 +2336,6 @@ pub(crate) struct TypeAlias {
23392336
pub(crate) item_type: Option<Type>,
23402337
}
23412338

2342-
#[derive(Clone, Debug)]
2343-
pub(crate) struct OpaqueTy {
2344-
pub(crate) bounds: Vec<GenericBound>,
2345-
pub(crate) generics: Generics,
2346-
}
2347-
23482339
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
23492340
pub(crate) struct BareFunctionDecl {
23502341
pub(crate) safety: hir::Safety,

src/librustdoc/fold.rs

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub(crate) trait DocFolder: Sized {
7777
ExternCrateItem { src: _ }
7878
| ImportItem(_)
7979
| FunctionItem(_)
80-
| OpaqueTyItem(_)
8180
| StaticItem(_)
8281
| ConstantItem(..)
8382
| TraitAliasItem(_)

src/librustdoc/formats/cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
463463

464464
clean::ExternCrateItem { .. }
465465
| clean::ImportItem(..)
466-
| clean::OpaqueTyItem(..)
467466
| clean::ImplItem(..)
468467
| clean::TyMethodItem(..)
469468
| clean::MethodItem(..)

src/librustdoc/formats/item_type.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) enum ItemType {
5151
AssocConst = 19,
5252
Union = 20,
5353
ForeignType = 21,
54-
OpaqueTy = 22,
54+
// OpaqueTy used to be here, but it was removed in #127276
5555
ProcAttribute = 23,
5656
ProcDerive = 24,
5757
TraitAlias = 25,
@@ -84,7 +84,6 @@ impl<'a> From<&'a clean::Item> for ItemType {
8484
clean::EnumItem(..) => ItemType::Enum,
8585
clean::FunctionItem(..) => ItemType::Function,
8686
clean::TypeAliasItem(..) => ItemType::TypeAlias,
87-
clean::OpaqueTyItem(..) => ItemType::OpaqueTy,
8887
clean::StaticItem(..) => ItemType::Static,
8988
clean::ConstantItem(..) => ItemType::Constant,
9089
clean::TraitItem(..) => ItemType::Trait,
@@ -191,7 +190,6 @@ impl ItemType {
191190
ItemType::AssocConst => "associatedconstant",
192191
ItemType::ForeignType => "foreigntype",
193192
ItemType::Keyword => "keyword",
194-
ItemType::OpaqueTy => "opaque",
195193
ItemType::ProcAttribute => "attr",
196194
ItemType::ProcDerive => "derive",
197195
ItemType::TraitAlias => "traitalias",

src/librustdoc/html/render/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ impl AllTypes {
376376
ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)),
377377
ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)),
378378
ItemType::TypeAlias => self.type_aliases.insert(ItemEntry::new(new_url, name)),
379-
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
380379
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
381380
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
382381
ItemType::ProcAttribute => {
@@ -2299,7 +2298,6 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
22992298
ItemType::AssocConst => ItemSection::AssociatedConstants,
23002299
ItemType::ForeignType => ItemSection::ForeignTypes,
23012300
ItemType::Keyword => ItemSection::Keywords,
2302-
ItemType::OpaqueTy => ItemSection::OpaqueTypes,
23032301
ItemType::ProcAttribute => ItemSection::AttributeMacros,
23042302
ItemType::ProcDerive => ItemSection::DeriveMacros,
23052303
ItemType::TraitAlias => ItemSection::TraitAliases,

src/librustdoc/html/render/print_item.rs

-31
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
202202
clean::ConstantItem(..) => "Constant ",
203203
clean::ForeignTypeItem => "Foreign Type ",
204204
clean::KeywordItem => "Keyword ",
205-
clean::OpaqueTyItem(..) => "Opaque Type ",
206205
clean::TraitAliasItem(..) => "Trait Alias ",
207206
_ => {
208207
// We don't generate pages for any other type.
@@ -270,7 +269,6 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
270269
clean::ConstantItem(ci) => item_constant(buf, cx, item, &ci.generics, &ci.type_, &ci.kind),
271270
clean::ForeignTypeItem => item_foreign_type(buf, cx, item),
272271
clean::KeywordItem => item_keyword(buf, cx, item),
273-
clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e),
274272
clean::TraitAliasItem(ref ta) => item_trait_alias(buf, cx, item, ta),
275273
_ => {
276274
// We don't generate pages for any other type.
@@ -1197,35 +1195,6 @@ fn item_trait_alias(
11971195
.unwrap();
11981196
}
11991197

1200-
fn item_opaque_ty(
1201-
w: &mut impl fmt::Write,
1202-
cx: &mut Context<'_>,
1203-
it: &clean::Item,
1204-
t: &clean::OpaqueTy,
1205-
) {
1206-
wrap_item(w, |w| {
1207-
write!(
1208-
w,
1209-
"{attrs}type {name}{generics}{where_clause} = impl {bounds};",
1210-
attrs = render_attributes_in_pre(it, "", cx),
1211-
name = it.name.unwrap(),
1212-
generics = t.generics.print(cx),
1213-
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
1214-
bounds = bounds(&t.bounds, false, cx),
1215-
)
1216-
.unwrap();
1217-
});
1218-
1219-
write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap();
1220-
1221-
// Render any items associated directly to this alias, as otherwise they
1222-
// won't be visible anywhere in the docs. It would be nice to also show
1223-
// associated items from the aliased type (see discussion in #32077), but
1224-
// we need #14072 to make sense of the generics.
1225-
write!(w, "{}", render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All))
1226-
.unwrap();
1227-
}
1228-
12291198
fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
12301199
wrap_item(w, |w| {
12311200
write!(

src/librustdoc/json/conversions.rs

-8
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
333333
ForeignStaticItem(s, _) => ItemEnum::Static(s.into_tcx(tcx)),
334334
ForeignTypeItem => ItemEnum::ForeignType,
335335
TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_tcx(tcx)),
336-
OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)),
337336
// FIXME(generic_const_items): Add support for generic free consts
338337
ConstantItem(ci) => {
339338
ItemEnum::Constant { type_: ci.type_.into_tcx(tcx), const_: ci.kind.into_tcx(tcx) }
@@ -830,12 +829,6 @@ impl FromWithTcx<Box<clean::TypeAlias>> for TypeAlias {
830829
}
831830
}
832831

833-
impl FromWithTcx<clean::OpaqueTy> for OpaqueTy {
834-
fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
835-
OpaqueTy { bounds: opaque.bounds.into_tcx(tcx), generics: opaque.generics.into_tcx(tcx) }
836-
}
837-
}
838-
839832
impl FromWithTcx<clean::Static> for Static {
840833
fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self {
841834
Static {
@@ -867,7 +860,6 @@ impl FromWithTcx<ItemType> for ItemKind {
867860
Enum => ItemKind::Enum,
868861
Function | TyMethod | Method => ItemKind::Function,
869862
TypeAlias => ItemKind::TypeAlias,
870-
OpaqueTy => ItemKind::OpaqueTy,
871863
Static => ItemKind::Static,
872864
Constant => ItemKind::Constant,
873865
Trait => ItemKind::Trait,

src/librustdoc/json/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
184184
| types::ItemEnum::TraitAlias(_)
185185
| types::ItemEnum::Impl(_)
186186
| types::ItemEnum::TypeAlias(_)
187-
| types::ItemEnum::OpaqueTy(_)
188187
| types::ItemEnum::Constant { .. }
189188
| types::ItemEnum::Static(_)
190189
| types::ItemEnum::ForeignType

src/librustdoc/passes/stripper.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
5050
return Some(ret);
5151
}
5252
// These items can all get re-exported
53-
clean::OpaqueTyItem(..)
54-
| clean::TypeAliasItem(..)
53+
clean::TypeAliasItem(..)
5554
| clean::StaticItem(..)
5655
| clean::StructItem(..)
5756
| clean::EnumItem(..)

src/librustdoc/visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub(crate) trait DocVisitor: Sized {
2626
| ImportItem(_)
2727
| FunctionItem(_)
2828
| TypeAliasItem(_)
29-
| OpaqueTyItem(_)
3029
| StaticItem(_)
3130
| ConstantItem(..)
3231
| TraitAliasItem(_)

src/rustdoc-json-types/lib.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
1313
/// This integer is incremented with every breaking change to the API,
1414
/// and is returned along with the JSON blob as [`Crate::format_version`].
1515
/// Consuming code should assert that this value matches the format version(s) that it supports.
16-
pub const FORMAT_VERSION: u32 = 32;
16+
pub const FORMAT_VERSION: u32 = 33;
1717

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

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

1203-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1204-
pub struct OpaqueTy {
1205-
pub bounds: Vec<GenericBound>,
1206-
pub generics: Generics,
1207-
}
1208-
12091201
/// A `static` declaration.
12101202
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
12111203
pub struct Static {

src/tools/jsondoclint/src/item_kind.rs

-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub(crate) enum Kind {
1313
Variant,
1414
Function,
1515
TypeAlias,
16-
OpaqueTy,
1716
Constant,
1817
Trait,
1918
TraitAlias,
@@ -55,7 +54,6 @@ impl Kind {
5554

5655
// FIXME(adotinthevoid): I'm not sure if these are correct
5756
Keyword => false,
58-
OpaqueTy => false,
5957
ProcAttribute => false,
6058
ProcDerive => false,
6159

@@ -99,7 +97,6 @@ impl Kind {
9997
Kind::Enum => false,
10098
Kind::Variant => false,
10199
Kind::TypeAlias => false,
102-
Kind::OpaqueTy => false,
103100
Kind::Constant => false,
104101
Kind::Trait => false,
105102
Kind::TraitAlias => false,
@@ -149,7 +146,6 @@ impl Kind {
149146
ItemEnum::TraitAlias(_) => TraitAlias,
150147
ItemEnum::Impl(_) => Impl,
151148
ItemEnum::TypeAlias(_) => TypeAlias,
152-
ItemEnum::OpaqueTy(_) => OpaqueTy,
153149
ItemEnum::Constant { .. } => Constant,
154150
ItemEnum::Static(_) => Static,
155151
ItemEnum::Macro(_) => Macro,
@@ -177,7 +173,6 @@ impl Kind {
177173
ItemKind::Keyword => Keyword,
178174
ItemKind::Macro => Macro,
179175
ItemKind::Module => Module,
180-
ItemKind::OpaqueTy => OpaqueTy,
181176
ItemKind::Primitive => Primitive,
182177
ItemKind::ProcAttribute => ProcAttribute,
183178
ItemKind::ProcDerive => ProcDerive,

src/tools/jsondoclint/src/validator.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::hash::Hash;
33

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

@@ -101,7 +101,6 @@ impl<'a> Validator<'a> {
101101
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
102102
ItemEnum::Impl(x) => self.check_impl(x, id),
103103
ItemEnum::TypeAlias(x) => self.check_type_alias(x),
104-
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x),
105104
ItemEnum::Constant { type_, const_ } => {
106105
self.check_type(type_);
107106
self.check_constant(const_);
@@ -230,11 +229,6 @@ impl<'a> Validator<'a> {
230229
self.check_type(&x.type_);
231230
}
232231

233-
fn check_opaque_ty(&mut self, x: &'a OpaqueTy) {
234-
x.bounds.iter().for_each(|b| self.check_generic_bound(b));
235-
self.check_generics(&x.generics);
236-
}
237-
238232
fn check_constant(&mut self, _x: &'a Constant) {
239233
// nop
240234
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ignore-tidy-linelength
2+
#![feature(impl_trait_in_assoc_type)]
3+
4+
pub struct AlwaysTrue;
5+
6+
/// impl IntoIterator
7+
impl IntoIterator for AlwaysTrue {
8+
//@ set Item = '$.index[*][?(@.docs=="type Item")].id'
9+
/// type Item
10+
type Item = bool;
11+
12+
//@ count '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[*]' 1
13+
//@ is '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.name' '"Iterator"'
14+
//@ count '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.args.angle_bracketed.bindings[*]' 1
15+
//@ is '$.index[*][?(@.docs=="type IntoIter")].inner.assoc_type.default.impl_trait[0].trait_bound.trait.args.angle_bracketed.bindings[0].name' '"Item"'
16+
//@ 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"'
17+
18+
//@ set IntoIter = '$.index[*][?(@.docs=="type IntoIter")].id'
19+
/// type IntoIter
20+
type IntoIter = impl Iterator<Item = bool>;
21+
22+
//@ set into_iter = '$.index[*][?(@.docs=="fn into_iter")].id'
23+
/// fn into_iter
24+
fn into_iter(self) -> Self::IntoIter {
25+
std::iter::repeat(true)
26+
}
27+
}
28+
29+
//@ ismany '$.index[*][?(@.docs=="impl IntoIterator")].inner.impl.items[*]' $Item $IntoIter $into_iter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(impl_trait_in_assoc_type)]
2+
3+
pub struct AlwaysTrue;
4+
5+
//@ has impl_trait_in_assoc_type/struct.AlwaysTrue.html
6+
7+
impl IntoIterator for AlwaysTrue {
8+
type Item = bool;
9+
10+
//@ has - '//*[@id="associatedtype.IntoIter"]//h4[@class="code-header"]' \
11+
// 'type IntoIter = impl Iterator<Item = bool>'
12+
type IntoIter = impl Iterator<Item = bool>;
13+
14+
fn into_iter(self) -> Self::IntoIter {
15+
std::iter::repeat(true)
16+
}
17+
}

0 commit comments

Comments
 (0)