1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! # The Rust core allocation library
13 //! This is the lowest level library through which allocation in Rust can be
16 //! This library, like libcore, is not intended for general usage, but rather as
17 //! a building block of other libraries. The types and interfaces in this
18 //! library are reexported through the [standard library](../std/index.html),
19 //! and should not be used through this library.
21 //! Currently, there are four major definitions in this library.
25 //! The [`Box`](boxed/index.html) type is a smart pointer type. There can
26 //! only be one owner of a `Box`, and the owner can decide to mutate the
27 //! contents, which live on the heap.
29 //! This type can be sent among threads efficiently as the size of a `Box` value
30 //! is the same as that of a pointer. Tree-like data structures are often built
31 //! with boxes because each node often has only one owner, the parent.
33 //! ## Reference counted pointers
35 //! The [`Rc`](rc/index.html) type is a non-threadsafe reference-counted pointer
36 //! type intended for sharing memory within a thread. An `Rc` pointer wraps a
37 //! type, `T`, and only allows access to `&T`, a shared reference.
39 //! This type is useful when inherited mutability (such as using `Box`) is too
40 //! constraining for an application, and is often paired with the `Cell` or
41 //! `RefCell` types in order to allow mutation.
43 //! ## Atomically reference counted pointers
45 //! The [`Arc`](arc/index.html) type is the threadsafe equivalent of the `Rc`
46 //! type. It provides all the same functionality of `Rc`, except it requires
47 //! that the contained type `T` is shareable. Additionally, `Arc<T>` is itself
48 //! sendable while `Rc<T>` is not.
50 //! This types allows for shared access to the contained data, and is often
51 //! paired with synchronization primitives such as mutexes to allow mutation of
54 //! ## Heap interfaces
56 //! The [`heap`](heap/index.html) module defines the low-level interface to the
57 //! default global allocator. It is not compatible with the libc allocator API.
59 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
60 #![cfg_attr(stage0, feature(custom_attribute))]
61 #![crate_name = "alloc"]
62 #![unstable(feature = "alloc")]
64 #![crate_type = "rlib"]
65 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
66 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
67 html_root_url = "http://doc.rust-lang.org/nightly/",
68 test(no_crate_inject))]
71 #![feature(allocator)]
72 #![feature(box_syntax)]
73 #![feature(coerce_unsized)]
75 #![feature(core_intrinsics)]
76 #![feature(core_prelude)]
77 #![feature(custom_attribute)]
78 #![feature(fundamental)]
79 #![feature(lang_items)]
82 #![feature(optin_builtin_traits)]
84 #![feature(staged_api)]
85 #![feature(unboxed_closures)]
87 #![feature(unsafe_no_drop_flag, filling_drop)]
89 #![cfg_attr(test, feature(test, alloc, rustc_private))]
90 #![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
97 #[cfg(all(not(feature = "external_funcs"), not(feature = "external_crate")))]
100 // Allow testing this library
102 #[cfg(test)] #[macro_use] extern crate std;
103 #[cfg(test)] #[macro_use] extern crate log;
105 // Heaps provided for low-level allocation strategies
109 // Primitive types using the heaps above
111 // Need to conditionally define the mod from `boxed.rs` to avoid
112 // duplicating the lang-items when building in test cfg; but also need
113 // to allow code to have `use boxed::HEAP;`
114 // and `use boxed::Box;` declarations.
118 mod boxed { pub use std::boxed::{Box, HEAP}; }
124 /// Common out-of-memory routine
128 // FIXME(#14674): This really needs to do something other than just abort
129 // here, but any printing done must be *guaranteed* to not
131 unsafe { core::intrinsics::abort() }
134 // FIXME(#14344): When linking liballoc with libstd, this library will be linked
135 // as an rlib (it only exists as an rlib). It turns out that an
136 // optimized standard library doesn't actually use *any* symbols
137 // from this library. Everything is inlined and optimized away.
138 // This means that linkers will actually omit the object for this
139 // file, even though it may be needed in the future.
141 // To get around this for now, we define a dummy symbol which
142 // will never get inlined so the stdlib can call it. The stdlib's
143 // reference to this symbol will cause this library's object file
144 // to get linked in to libstd successfully (the linker won't
147 pub fn fixme_14344_be_sure_to_link_to_collections() {}