Skip to content

doc: add a "primitive type reference" page #33516

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,7 @@ pub enum PrimitiveType {
Array,
PrimitiveTuple,
PrimitiveRawPointer,
PrimitiveRef,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)]
Expand Down Expand Up @@ -1573,6 +1574,7 @@ impl PrimitiveType {
"slice" => Some(Slice),
"tuple" => Some(PrimitiveTuple),
"pointer" => Some(PrimitiveRawPointer),
"ref" => Some(PrimitiveRef),
_ => None,
}
}
Expand Down Expand Up @@ -1611,6 +1613,7 @@ impl PrimitiveType {
Slice => "slice",
PrimitiveTuple => "tuple",
PrimitiveRawPointer => "pointer",
PrimitiveRef => "ref",
}
}

Expand Down Expand Up @@ -2350,6 +2353,7 @@ fn build_deref_target_impls(cx: &DocContext,
Array => tcx.lang_items.slice_impl(),
PrimitiveTuple => None,
PrimitiveRawPointer => tcx.lang_items.const_ptr_impl(),
PrimitiveRef => None,
};
if let Some(did) = did {
if !did.is_local() {
Expand Down
21 changes: 21 additions & 0 deletions src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ mod prim_char { }
///
mod prim_unit { }

#[doc(primitive = "ref")]
//
/// Borrowed references, `&T`, and `&mut T`.
///
/// References fundamental to Rust's system of ownership and borrowing. They
Copy link
Member

Choose a reason for hiding this comment

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

References are fundamental

/// are represented as pointers, but the compiler can statically ensure that no
/// unsafety results from passing and dereferencing them.
///
/// Shared references (`&T`) allow read-only access to the pointee, while
Copy link
Member

Choose a reason for hiding this comment

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

This is somewhat nuanced where types like &Cell<T> are actually read/write, not just read only. Perhaps this could just indicate "allows aliasing"?

Copy link
Member

Choose a reason for hiding this comment

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

Also, the official term is just "reference", not "shared reference"

/// mutable references (`&mut T`) allow full access, which is why mutable
/// references are enforced to be exclusive.
///
/// (Point to the section in the book?)
Copy link
Member

Choose a reason for hiding this comment

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

This'll probably wanna be changed before landing

///
/// Reference types have no inherent methods. Any methods called on a reference
/// will be resolved to methods on the pointee. However, traits can be
/// implemented for reference types. These implementations will show up in the
/// documentation for the pointee type.
///
mod prim_ref { }

#[doc(primitive = "pointer")]
//
/// Raw, unsafe pointers, `*const T`, and `*mut T`.
Expand Down