]> git.lizzy.rs Git - rust.git/blobdiff - src/doc/guide-unsafe.md
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / doc / guide-unsafe.md
index 8349c8ebcb6489e72d288c967186b6e9a1722cf8..8c67634d57aec590dd314fbff95d7497192230d4 100644 (file)
@@ -137,7 +137,7 @@ explicitly with, respectively, `value as *const T` and `value as *mut T`).
 
 Going the opposite direction, from `*const` to a reference `&`, is not
 safe. A `&T` is always valid, and so, at a minimum, the raw pointer
-`*const T` has to be a valid to a valid instance of type `T`. Furthermore,
+`*const T` has to point to a valid instance of type `T`. Furthermore,
 the resulting pointer must satisfy the aliasing and mutability laws of
 references. The compiler assumes these properties are true for any
 references, no matter how they are created, and so any conversion from
@@ -446,7 +446,7 @@ possible in two ways: the `#[start]` attribute, or overriding the
 default shim for the C `main` function with your own.
 
 The function marked `#[start]` is passed the command line parameters
-in the same format as C:
+in the same format as C:
 
 ```
 #![no_std]
@@ -461,11 +461,12 @@ fn start(_argc: int, _argv: *const *const u8) -> int {
     0
 }
 
-// These functions are invoked by the compiler, but not
+// These functions and traits are used by the compiler, but not
 // for a bare-bones hello world. These are normally
 // provided by libstd.
 #[lang = "stack_exhausted"] extern fn stack_exhausted() {}
 #[lang = "eh_personality"] extern fn eh_personality() {}
+#[lang = "sized"] trait Sized { }
 # // fn main() {} tricked you, rustdoc!
 ```
 
@@ -488,13 +489,14 @@ pub extern fn main(argc: int, argv: *const *const u8) -> int {
 
 #[lang = "stack_exhausted"] extern fn stack_exhausted() {}
 #[lang = "eh_personality"] extern fn eh_personality() {}
+#[lang = "sized"] trait Sized { }
 # // fn main() {} tricked you, rustdoc!
 ```
 
 
 The compiler currently makes a few assumptions about symbols which are available
 in the executable to call. Normally these functions are provided by the standard
-library, but without it you must define your own.
+xlibrary, but without it you must define your own.
 
 The first of these two functions, `stack_exhausted`, is invoked whenever stack
 overflow is detected.  This function has a number of restrictions about how it
@@ -508,6 +510,12 @@ mechanisms of the compiler. This is often mapped to GCC's personality function
 information), but crates which do not trigger failure can be assured that this
 function is never called.
 
+The final item in the example is a trait called `Sized`. This a trait
+that represents data of a known static size: it is integral to the
+Rust type system, and so the compiler expects the standard library to
+provide it. Since you are not using the standard library, you have to
+provide it yourself.
+
 ## Using libcore
 
 > **Note**: the core library's structure is unstable, and it is recommended to
@@ -537,11 +545,12 @@ extern crate core;
 use core::prelude::*;
 
 use core::mem;
-use core::raw::Slice;
 
 #[no_mangle]
 pub extern fn dot_product(a: *const u32, a_len: u32,
                           b: *const u32, b_len: u32) -> u32 {
+    use core::raw::Slice;
+
     // Convert the provided arrays into Rust slices.
     // The core::raw module guarantees that the Slice
     // structure has the same memory layout as a &[T]
@@ -592,7 +601,7 @@ standard library itself.
 # Interacting with the compiler internals
 
 > **Note**: this section is specific to the `rustc` compiler; these
-> parts of the language may never be full specified and so details may
+> parts of the language may never be fully specified and so details may
 > differ wildly between implementations (and even versions of `rustc`
 > itself).
 >
@@ -685,6 +694,7 @@ fn main(argc: int, argv: *const *const u8) -> int {
 
 #[lang = "stack_exhausted"] extern fn stack_exhausted() {}
 #[lang = "eh_personality"] extern fn eh_personality() {}
+#[lang = "sized"] trait Sized {}
 ```
 
 Note the use of `abort`: the `exchange_malloc` lang item is assumed to