Skip to content

Commit 9bd60a6

Browse files
committed
Auto merge of rust-lang#115078 - camelid:tydef-to-alias, r=aDotInTheVoid,GuillaumeGomez
rustdoc: Rename typedef to type alias This matches the name used by the [Rust Reference][1], which is also what people usually call these items. [1]: https://doc.rust-lang.org/reference/items/type-aliases.html r? `@GuillaumeGomez`
2 parents 840ed5d + 912d11d commit 9bd60a6

30 files changed

+179
-176
lines changed

src/librustdoc/clean/inline.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ pub(crate) fn try_inline(
8080
clean::UnionItem(build_union(cx, did))
8181
}
8282
Res::Def(DefKind::TyAlias { .. }, did) => {
83-
record_extern_fqn(cx, did, ItemType::Typedef);
83+
record_extern_fqn(cx, did, ItemType::TypeAlias);
8484
build_impls(cx, did, attrs_without_docs, &mut ret);
85-
clean::TypedefItem(build_type_alias(cx, did))
85+
clean::TypeAliasItem(build_type_alias(cx, did))
8686
}
8787
Res::Def(DefKind::Enum, did) => {
8888
record_extern_fqn(cx, did, ItemType::Enum);
@@ -287,7 +287,7 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
287287
clean::Union { generics, fields }
288288
}
289289

290-
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
290+
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::TypeAlias> {
291291
let predicates = cx.tcx.explicit_predicates_of(did);
292292
let type_ = clean_middle_ty(
293293
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()),
@@ -296,7 +296,7 @@ fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef>
296296
None,
297297
);
298298

299-
Box::new(clean::Typedef {
299+
Box::new(clean::TypeAlias {
300300
type_,
301301
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
302302
item_type: None,

src/librustdoc/clean/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12191219
None,
12201220
);
12211221
AssocTypeItem(
1222-
Box::new(Typedef {
1222+
Box::new(TypeAlias {
12231223
type_: clean_ty(default, cx),
12241224
generics,
12251225
item_type: Some(item_type),
@@ -1264,7 +1264,7 @@ pub(crate) fn clean_impl_item<'tcx>(
12641264
None,
12651265
);
12661266
AssocTypeItem(
1267-
Box::new(Typedef { type_, generics, item_type: Some(item_type) }),
1267+
Box::new(TypeAlias { type_, generics, item_type: Some(item_type) }),
12681268
Vec::new(),
12691269
)
12701270
}
@@ -1461,7 +1461,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14611461

14621462
if tcx.defaultness(assoc_item.def_id).has_value() {
14631463
AssocTypeItem(
1464-
Box::new(Typedef {
1464+
Box::new(TypeAlias {
14651465
type_: clean_middle_ty(
14661466
ty::Binder::dummy(
14671467
tcx.type_of(assoc_item.def_id).instantiate_identity(),
@@ -1480,7 +1480,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14801480
}
14811481
} else {
14821482
AssocTypeItem(
1483-
Box::new(Typedef {
1483+
Box::new(TypeAlias {
14841484
type_: clean_middle_ty(
14851485
ty::Binder::dummy(
14861486
tcx.type_of(assoc_item.def_id).instantiate_identity(),
@@ -2617,7 +2617,11 @@ fn clean_maybe_renamed_item<'tcx>(
26172617
cx.current_type_aliases.remove(&def_id);
26182618
}
26192619
}
2620-
TypedefItem(Box::new(Typedef { type_: rustdoc_ty, generics, item_type: Some(ty) }))
2620+
TypeAliasItem(Box::new(TypeAlias {
2621+
type_: rustdoc_ty,
2622+
generics,
2623+
item_type: Some(ty),
2624+
}))
26212625
}
26222626
ItemKind::Enum(ref def, generics) => EnumItem(Enum {
26232627
variants: def.variants.iter().map(|v| clean_variant(v, cx)).collect(),

src/librustdoc/clean/types.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ impl Item {
530530
pub(crate) fn is_ty_method(&self) -> bool {
531531
self.type_() == ItemType::TyMethod
532532
}
533-
pub(crate) fn is_typedef(&self) -> bool {
534-
self.type_() == ItemType::Typedef
533+
pub(crate) fn is_type_alias(&self) -> bool {
534+
self.type_() == ItemType::TypeAlias
535535
}
536536
pub(crate) fn is_primitive(&self) -> bool {
537537
self.type_() == ItemType::Primitive
@@ -799,7 +799,7 @@ pub(crate) enum ItemKind {
799799
EnumItem(Enum),
800800
FunctionItem(Box<Function>),
801801
ModuleItem(Module),
802-
TypedefItem(Box<Typedef>),
802+
TypeAliasItem(Box<TypeAlias>),
803803
OpaqueTyItem(OpaqueTy),
804804
StaticItem(Static),
805805
ConstantItem(Constant),
@@ -832,7 +832,7 @@ pub(crate) enum ItemKind {
832832
/// The bounds may be non-empty if there is a `where` clause.
833833
TyAssocTypeItem(Generics, Vec<GenericBound>),
834834
/// An associated type in a trait impl or a provided one in a trait declaration.
835-
AssocTypeItem(Box<Typedef>, Vec<GenericBound>),
835+
AssocTypeItem(Box<TypeAlias>, Vec<GenericBound>),
836836
/// An item that has been stripped by a rustdoc pass
837837
StrippedItem(Box<ItemKind>),
838838
KeywordItem,
@@ -857,7 +857,7 @@ impl ItemKind {
857857
ExternCrateItem { .. }
858858
| ImportItem(_)
859859
| FunctionItem(_)
860-
| TypedefItem(_)
860+
| TypeAliasItem(_)
861861
| OpaqueTyItem(_)
862862
| StaticItem(_)
863863
| ConstantItem(_)
@@ -891,7 +891,7 @@ impl ItemKind {
891891
| ModuleItem(_)
892892
| ExternCrateItem { .. }
893893
| FunctionItem(_)
894-
| TypedefItem(_)
894+
| TypeAliasItem(_)
895895
| OpaqueTyItem(_)
896896
| StaticItem(_)
897897
| ConstantItem(_)
@@ -2230,7 +2230,7 @@ pub(crate) struct PathSegment {
22302230
}
22312231

22322232
#[derive(Clone, Debug)]
2233-
pub(crate) struct Typedef {
2233+
pub(crate) struct TypeAlias {
22342234
pub(crate) type_: Type,
22352235
pub(crate) generics: Generics,
22362236
/// `type_` can come from either the HIR or from metadata. If it comes from HIR, it may be a type

src/librustdoc/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) trait DocFolder: Sized {
5555
ExternCrateItem { src: _ }
5656
| ImportItem(_)
5757
| FunctionItem(_)
58-
| TypedefItem(_)
58+
| TypeAliasItem(_)
5959
| OpaqueTyItem(_)
6060
| StaticItem(_)
6161
| ConstantItem(_)

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
389389
match *item.kind {
390390
clean::StructItem(..)
391391
| clean::EnumItem(..)
392-
| clean::TypedefItem(..)
392+
| clean::TypeAliasItem(..)
393393
| clean::TraitItem(..)
394394
| clean::TraitAliasItem(..)
395395
| clean::FunctionItem(..)

src/librustdoc/formats/item_type.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) enum ItemType {
2929
Struct = 3,
3030
Enum = 4,
3131
Function = 5,
32-
Typedef = 6,
32+
TypeAlias = 6,
3333
Static = 7,
3434
Trait = 8,
3535
Impl = 9,
@@ -75,7 +75,7 @@ impl<'a> From<&'a clean::Item> for ItemType {
7575
clean::UnionItem(..) => ItemType::Union,
7676
clean::EnumItem(..) => ItemType::Enum,
7777
clean::FunctionItem(..) => ItemType::Function,
78-
clean::TypedefItem(..) => ItemType::Typedef,
78+
clean::TypeAliasItem(..) => ItemType::TypeAlias,
7979
clean::OpaqueTyItem(..) => ItemType::OpaqueTy,
8080
clean::StaticItem(..) => ItemType::Static,
8181
clean::ConstantItem(..) => ItemType::Constant,
@@ -115,7 +115,7 @@ impl From<DefKind> for ItemType {
115115
DefKind::Struct => Self::Struct,
116116
DefKind::Union => Self::Union,
117117
DefKind::Trait => Self::Trait,
118-
DefKind::TyAlias { .. } => Self::Typedef,
118+
DefKind::TyAlias { .. } => Self::TypeAlias,
119119
DefKind::TraitAlias => Self::TraitAlias,
120120
DefKind::Macro(kind) => match kind {
121121
MacroKind::Bang => ItemType::Macro,
@@ -156,7 +156,7 @@ impl ItemType {
156156
ItemType::Union => "union",
157157
ItemType::Enum => "enum",
158158
ItemType::Function => "fn",
159-
ItemType::Typedef => "type",
159+
ItemType::TypeAlias => "type",
160160
ItemType::Static => "static",
161161
ItemType::Trait => "trait",
162162
ItemType::Impl => "impl",

src/librustdoc/html/render/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ struct AllTypes {
235235
traits: FxHashSet<ItemEntry>,
236236
macros: FxHashSet<ItemEntry>,
237237
functions: FxHashSet<ItemEntry>,
238-
typedefs: FxHashSet<ItemEntry>,
238+
type_aliases: FxHashSet<ItemEntry>,
239239
opaque_tys: FxHashSet<ItemEntry>,
240240
statics: FxHashSet<ItemEntry>,
241241
constants: FxHashSet<ItemEntry>,
@@ -255,7 +255,7 @@ impl AllTypes {
255255
traits: new_set(100),
256256
macros: new_set(100),
257257
functions: new_set(100),
258-
typedefs: new_set(100),
258+
type_aliases: new_set(100),
259259
opaque_tys: new_set(100),
260260
statics: new_set(100),
261261
constants: new_set(100),
@@ -279,7 +279,7 @@ impl AllTypes {
279279
ItemType::Trait => self.traits.insert(ItemEntry::new(new_url, name)),
280280
ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)),
281281
ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)),
282-
ItemType::Typedef => self.typedefs.insert(ItemEntry::new(new_url, name)),
282+
ItemType::TypeAlias => self.type_aliases.insert(ItemEntry::new(new_url, name)),
283283
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
284284
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
285285
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
@@ -317,8 +317,8 @@ impl AllTypes {
317317
if !self.functions.is_empty() {
318318
sections.insert(ItemSection::Functions);
319319
}
320-
if !self.typedefs.is_empty() {
321-
sections.insert(ItemSection::TypeDefinitions);
320+
if !self.type_aliases.is_empty() {
321+
sections.insert(ItemSection::TypeAliases);
322322
}
323323
if !self.opaque_tys.is_empty() {
324324
sections.insert(ItemSection::OpaqueTypes);
@@ -374,7 +374,7 @@ impl AllTypes {
374374
print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros);
375375
print_entries(f, &self.derive_macros, ItemSection::DeriveMacros);
376376
print_entries(f, &self.functions, ItemSection::Functions);
377-
print_entries(f, &self.typedefs, ItemSection::TypeDefinitions);
377+
print_entries(f, &self.type_aliases, ItemSection::TypeAliases);
378378
print_entries(f, &self.trait_aliases, ItemSection::TraitAliases);
379379
print_entries(f, &self.opaque_tys, ItemSection::OpaqueTypes);
380380
print_entries(f, &self.statics, ItemSection::Statics);
@@ -1237,7 +1237,7 @@ fn render_deref_methods(
12371237
.iter()
12381238
.find_map(|item| match *item.kind {
12391239
clean::AssocTypeItem(box ref t, _) => Some(match *t {
1240-
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
1240+
clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
12411241
_ => (&t.type_, &t.type_),
12421242
}),
12431243
_ => None,
@@ -2035,7 +2035,7 @@ pub(crate) enum ItemSection {
20352035
Statics,
20362036
Traits,
20372037
Functions,
2038-
TypeDefinitions,
2038+
TypeAliases,
20392039
Unions,
20402040
Implementations,
20412041
TypeMethods,
@@ -2067,7 +2067,7 @@ impl ItemSection {
20672067
Statics,
20682068
Traits,
20692069
Functions,
2070-
TypeDefinitions,
2070+
TypeAliases,
20712071
Unions,
20722072
Implementations,
20732073
TypeMethods,
@@ -2093,7 +2093,7 @@ impl ItemSection {
20932093
Self::Unions => "unions",
20942094
Self::Enums => "enums",
20952095
Self::Functions => "functions",
2096-
Self::TypeDefinitions => "types",
2096+
Self::TypeAliases => "types",
20972097
Self::Statics => "statics",
20982098
Self::Constants => "constants",
20992099
Self::Traits => "traits",
@@ -2123,7 +2123,7 @@ impl ItemSection {
21232123
Self::Unions => "Unions",
21242124
Self::Enums => "Enums",
21252125
Self::Functions => "Functions",
2126-
Self::TypeDefinitions => "Type Definitions",
2126+
Self::TypeAliases => "Type Aliases",
21272127
Self::Statics => "Statics",
21282128
Self::Constants => "Constants",
21292129
Self::Traits => "Traits",
@@ -2154,7 +2154,7 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
21542154
ItemType::Union => ItemSection::Unions,
21552155
ItemType::Enum => ItemSection::Enums,
21562156
ItemType::Function => ItemSection::Functions,
2157-
ItemType::Typedef => ItemSection::TypeDefinitions,
2157+
ItemType::TypeAlias => ItemSection::TypeAliases,
21582158
ItemType::Static => ItemSection::Statics,
21592159
ItemType::Constant => ItemSection::Constants,
21602160
ItemType::Trait => ItemSection::Traits,

src/librustdoc/html/render/print_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(super) fn print_item(
198198
clean::StructItem(..) => "Struct ",
199199
clean::UnionItem(..) => "Union ",
200200
clean::EnumItem(..) => "Enum ",
201-
clean::TypedefItem(..) => "Type Definition ",
201+
clean::TypeAliasItem(..) => "Type Alias ",
202202
clean::MacroItem(..) => "Macro ",
203203
clean::ProcMacroItem(ref mac) => match mac.kind {
204204
MacroKind::Bang => "Macro ",
@@ -273,7 +273,7 @@ pub(super) fn print_item(
273273
clean::StructItem(ref s) => item_struct(buf, cx, item, s),
274274
clean::UnionItem(ref s) => item_union(buf, cx, item, s),
275275
clean::EnumItem(ref e) => item_enum(buf, cx, item, e),
276-
clean::TypedefItem(ref t) => item_typedef(buf, cx, item, t),
276+
clean::TypeAliasItem(ref t) => item_type_alias(buf, cx, item, t),
277277
clean::MacroItem(ref m) => item_macro(buf, cx, item, m),
278278
clean::ProcMacroItem(ref m) => item_proc_macro(buf, cx, item, m),
279279
clean::PrimitiveItem(_) => item_primitive(buf, cx, item),
@@ -343,7 +343,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
343343
ItemType::Static => 8,
344344
ItemType::Trait => 9,
345345
ItemType::Function => 10,
346-
ItemType::Typedef => 12,
346+
ItemType::TypeAlias => 12,
347347
ItemType::Union => 13,
348348
_ => 14 + ty as u8,
349349
}
@@ -1217,8 +1217,8 @@ fn item_opaque_ty(
12171217
.unwrap();
12181218
}
12191219

1220-
fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Typedef) {
1221-
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
1220+
fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
1221+
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TypeAlias) {
12221222
wrap_item(w, |w| {
12231223
write!(
12241224
w,

src/librustdoc/html/render/sidebar.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
8282
clean::PrimitiveItem(_) => sidebar_primitive(cx, it),
8383
clean::UnionItem(ref u) => sidebar_union(cx, it, u),
8484
clean::EnumItem(ref e) => sidebar_enum(cx, it, e),
85-
clean::TypedefItem(_) => sidebar_typedef(cx, it),
85+
clean::TypeAliasItem(_) => sidebar_type_alias(cx, it),
8686
clean::ModuleItem(ref m) => vec![sidebar_module(&m.items)],
8787
clean::ForeignTypeItem => sidebar_foreign_type(cx, it),
8888
_ => vec![],
@@ -100,7 +100,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf
100100
|| it.is_union()
101101
|| it.is_enum()
102102
|| it.is_mod()
103-
|| it.is_typedef()
103+
|| it.is_type_alias()
104104
{
105105
(
106106
match *it.kind {
@@ -230,7 +230,7 @@ fn sidebar_primitive<'a>(cx: &'a Context<'_>, it: &'a clean::Item) -> Vec<LinkBl
230230
}
231231
}
232232

233-
fn sidebar_typedef<'a>(cx: &'a Context<'_>, it: &'a clean::Item) -> Vec<LinkBlock<'a>> {
233+
fn sidebar_type_alias<'a>(cx: &'a Context<'_>, it: &'a clean::Item) -> Vec<LinkBlock<'a>> {
234234
let mut items = vec![];
235235
sidebar_assoc_items(cx, it, &mut items);
236236
items
@@ -334,7 +334,7 @@ fn sidebar_deref_methods<'a>(
334334
if let Some((target, real_target)) =
335335
impl_.inner_impl().items.iter().find_map(|item| match *item.kind {
336336
clean::AssocTypeItem(box ref t, _) => Some(match *t {
337-
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
337+
clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
338338
_ => (&t.type_, &t.type_),
339339
}),
340340
_ => None,

src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function preLoadCss(cssUrl) {
499499
block("static", "static", "Statics");
500500
block("trait", "traits", "Traits");
501501
block("fn", "functions", "Functions");
502-
block("type", "types", "Type Definitions");
502+
block("type", "types", "Type Aliases");
503503
block("foreigntype", "foreign-types", "Foreign Types");
504504
block("keyword", "keywords", "Keywords");
505505
block("traitalias", "trait-aliases", "Trait Aliases");

0 commit comments

Comments
 (0)