Skip to content

Commit 6b505d6

Browse files
authored
Rollup merge of #45354 - cuviper:unit_doc, r=QuietMisdreavus
rustdoc: add a primitive page for "unit" In `src/libstd/primitive_docs.rs`, a `#[doc(primitive = "unit")]` section has sat long neglected. This patch teaches rustdoc to recognize "unit", and steals its trait implementations away from the tuple page.
2 parents c6892f4 + 9fda05c commit 6b505d6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/librustdoc/clean/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ impl Clean<ExternalCrate> for CrateNum {
238238
if prim.is_some() {
239239
break;
240240
}
241+
// FIXME: should warn on unknown primitives?
241242
}
242243
}
243244
}
@@ -1627,6 +1628,7 @@ pub enum PrimitiveType {
16271628
Slice,
16281629
Array,
16291630
Tuple,
1631+
Unit,
16301632
RawPointer,
16311633
Reference,
16321634
Fn,
@@ -1662,7 +1664,11 @@ impl Type {
16621664
Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
16631665
Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice),
16641666
Array(..) | BorrowedRef { type_: box Array(..), .. } => Some(PrimitiveType::Array),
1665-
Tuple(..) => Some(PrimitiveType::Tuple),
1667+
Tuple(ref tys) => if tys.is_empty() {
1668+
Some(PrimitiveType::Unit)
1669+
} else {
1670+
Some(PrimitiveType::Tuple)
1671+
},
16661672
RawPointer(..) => Some(PrimitiveType::RawPointer),
16671673
BorrowedRef { type_: box Generic(..), .. } => Some(PrimitiveType::Reference),
16681674
BareFunction(..) => Some(PrimitiveType::Fn),
@@ -1708,7 +1714,11 @@ impl GetDefId for Type {
17081714
BorrowedRef { type_: box Generic(..), .. } =>
17091715
Primitive(PrimitiveType::Reference).def_id(),
17101716
BorrowedRef { ref type_, .. } => type_.def_id(),
1711-
Tuple(..) => Primitive(PrimitiveType::Tuple).def_id(),
1717+
Tuple(ref tys) => if tys.is_empty() {
1718+
Primitive(PrimitiveType::Unit).def_id()
1719+
} else {
1720+
Primitive(PrimitiveType::Tuple).def_id()
1721+
},
17121722
BareFunction(..) => Primitive(PrimitiveType::Fn).def_id(),
17131723
Slice(..) => Primitive(PrimitiveType::Slice).def_id(),
17141724
Array(..) => Primitive(PrimitiveType::Array).def_id(),
@@ -1742,6 +1752,7 @@ impl PrimitiveType {
17421752
"array" => Some(PrimitiveType::Array),
17431753
"slice" => Some(PrimitiveType::Slice),
17441754
"tuple" => Some(PrimitiveType::Tuple),
1755+
"unit" => Some(PrimitiveType::Unit),
17451756
"pointer" => Some(PrimitiveType::RawPointer),
17461757
"reference" => Some(PrimitiveType::Reference),
17471758
"fn" => Some(PrimitiveType::Fn),
@@ -1772,6 +1783,7 @@ impl PrimitiveType {
17721783
Array => "array",
17731784
Slice => "slice",
17741785
Tuple => "tuple",
1786+
Unit => "unit",
17751787
RawPointer => "pointer",
17761788
Reference => "reference",
17771789
Fn => "fn",
@@ -2693,6 +2705,7 @@ fn build_deref_target_impls(cx: &DocContext,
26932705
Slice => tcx.lang_items().slice_impl(),
26942706
Array => tcx.lang_items().slice_impl(),
26952707
Tuple => None,
2708+
Unit => None,
26962709
RawPointer => tcx.lang_items().const_ptr_impl(),
26972710
Reference => None,
26982711
Fn => None,

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
614614
}
615615
clean::Tuple(ref typs) => {
616616
match &typs[..] {
617-
&[] => primitive_link(f, PrimitiveType::Tuple, "()"),
617+
&[] => primitive_link(f, PrimitiveType::Unit, "()"),
618618
&[ref one] => {
619619
primitive_link(f, PrimitiveType::Tuple, "(")?;
620620
//carry f.alternate() into this display w/o branching manually

0 commit comments

Comments
 (0)