Skip to content

Commit 7fde9a8

Browse files
committed
doc: add a "primitive type reference" page
While it is not useful to list impls here, and there are no inherent methods, references are still a primitive (and very important) type and should get an entry in the overview on http://doc.rust-lang.org/std/#primitives and a place to put general verbiage about references, and probably a reference to the book. We do *not* add links to this page from other types, like we do for `&[T]`, because that would likely be more confusing than helpful. Fixes: rust-lang#15654
1 parent 50909f2 commit 7fde9a8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,7 @@ pub enum PrimitiveType {
14951495
Array,
14961496
PrimitiveTuple,
14971497
PrimitiveRawPointer,
1498+
PrimitiveRef,
14981499
}
14991500

15001501
#[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)]
@@ -1573,6 +1574,7 @@ impl PrimitiveType {
15731574
"slice" => Some(Slice),
15741575
"tuple" => Some(PrimitiveTuple),
15751576
"pointer" => Some(PrimitiveRawPointer),
1577+
"ref" => Some(PrimitiveRef),
15761578
_ => None,
15771579
}
15781580
}
@@ -1611,6 +1613,7 @@ impl PrimitiveType {
16111613
Slice => "slice",
16121614
PrimitiveTuple => "tuple",
16131615
PrimitiveRawPointer => "pointer",
1616+
PrimitiveRef => "ref",
16141617
}
16151618
}
16161619

@@ -2350,6 +2353,7 @@ fn build_deref_target_impls(cx: &DocContext,
23502353
Array => tcx.lang_items.slice_impl(),
23512354
PrimitiveTuple => None,
23522355
PrimitiveRawPointer => tcx.lang_items.const_ptr_impl(),
2356+
PrimitiveRef => None,
23532357
};
23542358
if let Some(did) = did {
23552359
if !did.is_local() {

src/libstd/primitive_docs.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,27 @@ mod prim_char { }
165165
///
166166
mod prim_unit { }
167167

168+
#[doc(primitive = "ref")]
169+
//
170+
/// Borrowed references, `&T`, and `&mut T`.
171+
///
172+
/// References fundamental to Rust's system of ownership and borrowing. They
173+
/// are represented as pointers, but the compiler can statically ensure that no
174+
/// unsafety results from passing and dereferencing them.
175+
///
176+
/// Shared references (`&T`) allow read-only access to the pointee, while
177+
/// mutable references (`&mut T`) allow full access, which is why mutable
178+
/// references are enforced to be exclusive.
179+
///
180+
/// (Point to the section in the book?)
181+
///
182+
/// Reference types have no inherent methods. Any methods called on a reference
183+
/// will be resolved to methods on the pointee. However, traits can be
184+
/// implemented for reference types. These implementations will show up in the
185+
/// documentation for the pointee type.
186+
///
187+
mod prim_ref { }
188+
168189
#[doc(primitive = "pointer")]
169190
//
170191
/// Raw, unsafe pointers, `*const T`, and `*mut T`.

0 commit comments

Comments
 (0)