Skip to content

Commit

Permalink
Rollup merge of rust-lang#45354 - cuviper:unit_doc, r=QuietMisdreavus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennytm authored Oct 18, 2017
2 parents c6892f4 + 9fda05c commit 6b505d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl Clean<ExternalCrate> for CrateNum {
if prim.is_some() {
break;
}
// FIXME: should warn on unknown primitives?
}
}
}
Expand Down Expand Up @@ -1627,6 +1628,7 @@ pub enum PrimitiveType {
Slice,
Array,
Tuple,
Unit,
RawPointer,
Reference,
Fn,
Expand Down Expand Up @@ -1662,7 +1664,11 @@ impl Type {
Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice),
Array(..) | BorrowedRef { type_: box Array(..), .. } => Some(PrimitiveType::Array),
Tuple(..) => Some(PrimitiveType::Tuple),
Tuple(ref tys) => if tys.is_empty() {
Some(PrimitiveType::Unit)
} else {
Some(PrimitiveType::Tuple)
},
RawPointer(..) => Some(PrimitiveType::RawPointer),
BorrowedRef { type_: box Generic(..), .. } => Some(PrimitiveType::Reference),
BareFunction(..) => Some(PrimitiveType::Fn),
Expand Down Expand Up @@ -1708,7 +1714,11 @@ impl GetDefId for Type {
BorrowedRef { type_: box Generic(..), .. } =>
Primitive(PrimitiveType::Reference).def_id(),
BorrowedRef { ref type_, .. } => type_.def_id(),
Tuple(..) => Primitive(PrimitiveType::Tuple).def_id(),
Tuple(ref tys) => if tys.is_empty() {
Primitive(PrimitiveType::Unit).def_id()
} else {
Primitive(PrimitiveType::Tuple).def_id()
},
BareFunction(..) => Primitive(PrimitiveType::Fn).def_id(),
Slice(..) => Primitive(PrimitiveType::Slice).def_id(),
Array(..) => Primitive(PrimitiveType::Array).def_id(),
Expand Down Expand Up @@ -1742,6 +1752,7 @@ impl PrimitiveType {
"array" => Some(PrimitiveType::Array),
"slice" => Some(PrimitiveType::Slice),
"tuple" => Some(PrimitiveType::Tuple),
"unit" => Some(PrimitiveType::Unit),
"pointer" => Some(PrimitiveType::RawPointer),
"reference" => Some(PrimitiveType::Reference),
"fn" => Some(PrimitiveType::Fn),
Expand Down Expand Up @@ -1772,6 +1783,7 @@ impl PrimitiveType {
Array => "array",
Slice => "slice",
Tuple => "tuple",
Unit => "unit",
RawPointer => "pointer",
Reference => "reference",
Fn => "fn",
Expand Down Expand Up @@ -2693,6 +2705,7 @@ fn build_deref_target_impls(cx: &DocContext,
Slice => tcx.lang_items().slice_impl(),
Array => tcx.lang_items().slice_impl(),
Tuple => None,
Unit => None,
RawPointer => tcx.lang_items().const_ptr_impl(),
Reference => None,
Fn => None,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt:
}
clean::Tuple(ref typs) => {
match &typs[..] {
&[] => primitive_link(f, PrimitiveType::Tuple, "()"),
&[] => primitive_link(f, PrimitiveType::Unit, "()"),
&[ref one] => {
primitive_link(f, PrimitiveType::Tuple, "(")?;
//carry f.alternate() into this display w/o branching manually
Expand Down

0 comments on commit 6b505d6

Please sign in to comment.