about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-10-11 21:25:13 +0200
committerSimon Sapin <simon.sapin@exyr.org>2017-10-12 07:46:02 +0200
commit818d2249475910fa1f7844486abb2d7239056d96 (patch)
treefdd82a5a1e635d4e92bd5eec909dd7fc7f4ef3dd /src
parentcbf5d39cca2e837c7a9880e69e110e714d19c6aa (diff)
downloadrust-818d2249475910fa1f7844486abb2d7239056d96.tar.gz
rust-818d2249475910fa1f7844486abb2d7239056d96.zip
Fix out of date unstable book entries for `alloc_*` features.
Diffstat (limited to 'src')
-rw-r--r--src/doc/unstable-book/src/library-features/alloc-jemalloc.md53
-rw-r--r--src/doc/unstable-book/src/library-features/alloc-system.md31
-rw-r--r--src/liballoc_system/lib.rs2
3 files changed, 26 insertions, 60 deletions
diff --git a/src/doc/unstable-book/src/library-features/alloc-jemalloc.md b/src/doc/unstable-book/src/library-features/alloc-jemalloc.md
index 18ff838dd32..425d4cb79b2 100644
--- a/src/doc/unstable-book/src/library-features/alloc-jemalloc.md
+++ b/src/doc/unstable-book/src/library-features/alloc-jemalloc.md
@@ -8,55 +8,6 @@ See also [`alloc_system`](library-features/alloc-system.html).
 
 ------------------------
 
-The compiler currently ships two default allocators: `alloc_system` and
-`alloc_jemalloc` (some targets don't have jemalloc, however). These allocators
-are normal Rust crates and contain an implementation of the routines to
-allocate and deallocate memory. The standard library is not compiled assuming
-either one, and the compiler will decide which allocator is in use at
-compile-time depending on the type of output artifact being produced.
-
-Binaries generated by the compiler will use `alloc_jemalloc` by default (where
-available). In this situation the compiler "controls the world" in the sense of
-it has power over the final link. Primarily this means that the allocator
-decision can be left up the compiler.
-
-Dynamic and static libraries, however, will use `alloc_system` by default. Here
-Rust is typically a 'guest' in another application or another world where it
-cannot authoritatively decide what allocator is in use. As a result it resorts
-back to the standard APIs (e.g. `malloc` and `free`) for acquiring and releasing
-memory.
-
-# Switching Allocators
-
-Although the compiler's default choices may work most of the time, it's often
-necessary to tweak certain aspects. Overriding the compiler's decision about
-which allocator is in use is done simply by linking to the desired allocator:
-
-```rust,no_run
-#![feature(alloc_system)]
-
-extern crate alloc_system;
-
-fn main() {
-    let a = Box::new(4); // Allocates from the system allocator.
-    println!("{}", a);
-}
-```
-
-In this example the binary generated will not link to jemalloc by default but
-instead use the system allocator. Conversely to generate a dynamic library which
-uses jemalloc by default one would write:
-
-```rust,ignore
-#![feature(alloc_jemalloc)]
-#![crate_type = "dylib"]
-
-extern crate alloc_jemalloc;
-
-pub fn foo() {
-    let a = Box::new(4); // Allocates from jemalloc.
-    println!("{}", a);
-}
-# fn main() {}
-```
+This feature has been replaced by [the `jemallocator` crate on crates.io.][jemallocator].
 
+[jemallocator]: https://crates.io/crates/jemallocator
diff --git a/src/doc/unstable-book/src/library-features/alloc-system.md b/src/doc/unstable-book/src/library-features/alloc-system.md
index 1d261db6ba1..9effab202ca 100644
--- a/src/doc/unstable-book/src/library-features/alloc-system.md
+++ b/src/doc/unstable-book/src/library-features/alloc-system.md
@@ -1,10 +1,10 @@
 # `alloc_system`
 
-The tracking issue for this feature is: [#33082]
+The tracking issue for this feature is: [#32838]
 
-[#33082]: https://github.com/rust-lang/rust/issues/33082
+[#32838]: https://github.com/rust-lang/rust/issues/32838
 
-See also [`alloc_jemalloc`](library-features/alloc-jemalloc.html).
+See also [`global_allocator`](language-features/global-allocator.html).
 
 ------------------------
 
@@ -30,13 +30,18 @@ memory.
 
 Although the compiler's default choices may work most of the time, it's often
 necessary to tweak certain aspects. Overriding the compiler's decision about
-which allocator is in use is done simply by linking to the desired allocator:
+which allocator is in use is done through the `#[global_allocator]` attribute:
 
 ```rust,no_run
-#![feature(alloc_system)]
+#![feature(alloc_system, global_allocator, allocator_api)]
 
 extern crate alloc_system;
 
+use alloc_system::System;
+
+#[global_allocator]
+static A: System = System;
+
 fn main() {
     let a = Box::new(4); // Allocates from the system allocator.
     println!("{}", a);
@@ -47,11 +52,22 @@ In this example the binary generated will not link to jemalloc by default but
 instead use the system allocator. Conversely to generate a dynamic library which
 uses jemalloc by default one would write:
 
+(The `alloc_jemalloc` crate cannot be used to control the global allocator,
+crate.io’s `jemallocator` crate provides equivalent functionality.)
+
+```toml
+# Cargo.toml
+[dependencies]
+jemallocator = "0.1"
+```
 ```rust,ignore
-#![feature(alloc_jemalloc)]
+#![feature(global_allocator)]
 #![crate_type = "dylib"]
 
-extern crate alloc_jemalloc;
+extern crate jemallocator;
+
+#[global_allocator]
+static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
 
 pub fn foo() {
     let a = Box::new(4); // Allocates from jemalloc.
@@ -59,4 +75,3 @@ pub fn foo() {
 }
 # fn main() {}
 ```
-
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs
index 2eb659699eb..7aa5f8a9186 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -14,7 +14,7 @@
 #![unstable(feature = "alloc_system",
             reason = "this library is unlikely to be stabilized in its current \
                       form or name",
-            issue = "27783")]
+            issue = "32838")]
 #![feature(global_allocator)]
 #![feature(allocator_api)]
 #![feature(alloc)]