Skip to content

Commit 8641e70

Browse files
authored
Merge pull request #180 from jyn514/master
[WIP] Add more links
2 parents 737029d + e0702e4 commit 8641e70

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/exotic-sizes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ information that "completes" them (more on this below).
2020
There are two major DSTs exposed by the language:
2121

2222
* trait objects: `dyn MyTrait`
23-
* slices: `[T]`, `str`, and others
23+
* slices: [`[T]`], [`str`], and others
2424

2525
A trait object represents some type that implements the traits it specifies.
2626
The exact original type is *erased* in favor of runtime reflection
@@ -194,3 +194,5 @@ should behave.
194194

195195
[dst-issue]: https://github.com/rust-lang/rust/issues/26403
196196
[extern-types]: https://github.com/rust-lang/rfcs/blob/master/text/1861-extern-types.md
197+
[`str`]: ../std/primitive.str.html
198+
[`[T]`]: ../std/primitive.slice.html

src/safe-unsafe-meaning.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ maintains the contracts the trait requires.
2424

2525
You can use `unsafe` on a block to declare that all unsafe actions performed
2626
within are verified to uphold the contracts of those operations. For instance,
27-
the index passed to `slice::get_unchecked` is in-bounds.
27+
the index passed to [`slice::get_unchecked`][get_unchecked] is in-bounds.
2828

2929
You can use `unsafe` on a trait implementation to declare that the implementation
30-
upholds the trait's contract. For instance, that a type implementing `Send` is
30+
upholds the trait's contract. For instance, that a type implementing [`Send`] is
3131
really safe to move to another thread.
3232

3333
The standard library has a number of unsafe functions, including:
3434

35-
* `slice::get_unchecked`, which performs unchecked indexing, allowing
36-
memory safety to be freely violated.
37-
* `mem::transmute` reinterprets some value as having a given type, bypassing
38-
type safety in arbitrary ways (see [conversions] for details).
39-
* Every raw pointer to a sized type has an `offset` method that
35+
* [`slice::get_unchecked`][get_unchecked], which performs unchecked indexing,
36+
allowing memory safety to be freely violated.
37+
* [`mem::transmute`][transmute] reinterprets some value as having a given type,
38+
bypassing type safety in arbitrary ways (see [conversions] for details).
39+
* Every raw pointer to a sized type has an [`offset`][ptr_offset] method that
4040
invokes Undefined Behavior if the passed offset is not ["in bounds"][ptr_offset].
4141
* All FFI (Foreign Function Interface) functions are `unsafe` to call because the
4242
other language can do arbitrary operations that the Rust compiler can't check.
@@ -65,11 +65,11 @@ relationship between Safe and Unsafe Rust. Safe Rust inherently has to
6565
trust that any Unsafe Rust it touches has been written correctly.
6666
On the other hand, Unsafe Rust has to be very careful about trusting Safe Rust.
6767

68-
As an example, Rust has the `PartialOrd` and `Ord` traits to differentiate
68+
As an example, Rust has the [`PartialOrd`] and [`Ord`] traits to differentiate
6969
between types which can "just" be compared, and those that provide a "total"
7070
ordering (which basically means that comparison behaves reasonably).
7171

72-
`BTreeMap` doesn't really make sense for partially-ordered types, and so it
72+
[`BTreeMap`] doesn't really make sense for partially-ordered types, and so it
7373
requires that its keys implement `Ord`. However, `BTreeMap` has Unsafe Rust code
7474
inside of its implementation. Because it would be unacceptable for a sloppy `Ord`
7575
implementation (which is Safe to write) to cause Undefined Behavior, the Unsafe
@@ -156,4 +156,8 @@ of the sort of care that must be taken, and what contracts Unsafe Rust must upho
156156
[`GlobalAlloc`]: ../std/alloc/trait.GlobalAlloc.html
157157
[conversions]: conversions.html
158158
[ptr_offset]: ../std/primitive.pointer.html#method.offset
159-
159+
[get_unchecked]: ../std/primitive.slice.html#method.get_unchecked
160+
[transmute]: ../std/mem/fn.transmute.html
161+
[`PartialOrd`]: ../std/cmp/trait.PartialOrd.html
162+
[`Ord`]: ../std/cmp/trait.Ord.html
163+
[`BTreeMap`]: ../std/collections/struct.BTreeMap.html

src/what-unsafe-does.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ language cares about is preventing the following things:
3838
* slice metadata is invalid if the length is not a valid `usize`
3939
(i.e., it must not be read from uninitialized memory)
4040
* a type with custom invalid values that is one of those values, such as a
41-
`NonNull` that is null. (Requesting custom invalid values is an unstable
41+
[`NonNull`] that is null. (Requesting custom invalid values is an unstable
4242
feature, but some stable libstd types, like `NonNull`, make use of it.)
4343

4444
"Producing" a value happens any time a value is assigned, passed to a
@@ -84,3 +84,4 @@ these problems are considered impractical to categorically prevent.
8484
[uninitialized memory]: uninitialized.html
8585
[race]: races.html
8686
[target features]: ../reference/attributes/codegen.html#the-target_feature-attribute
87+
[`NonNull`]: ../std/ptr/struct.NonNull.html

0 commit comments

Comments
 (0)