about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2018-04-26make Vec::new const :PMark Mansi-1/+1
2018-04-26Rollup merge of #50219 - ralfbiedert:master, r=frewsxcvGuillaume Gomez-1/+1
Added missing `.` in docs.
2018-04-26Rollup merge of #50177 - matthiaskrgr:std_std_replacen__must_use, r=oli-obkGuillaume Gomez-0/+3
mark std::str::replace(,n) as #[must_use] let x = "a b c c"; x.replacen("c", "d", 2"); might not do what people might think it does.
2018-04-25make RawVec::empty constMark Mansi-1/+4
2018-04-25Make Vec::new constMark Mansi-1/+17
2018-04-25Added missing `.` in docs.Ralf Biedert-1/+1
2018-04-25Switch box_free to take the destructured contents of BoxMike Hommey-7/+17
As of now, Box only contains a Unique pointer, so this is the sole argument to box_free. Consequently, we remove the code supporting the previous box_free signature. We however keep the old definition for bootstrapping purpose.
2018-04-24Auto merge of #48999 - GuillaumeGomez:add-repeat-on-slice, r=Kimundibors-53/+91
Add repeat method on slice Fixes #48784.
2018-04-23mark std::str::replacen and std::str::replace as #[must_use].Matthias Krüger-0/+3
2018-04-22Implement From for more types on CowGeorge Burton-0/+15
2018-04-22Remove Alloc::oomSteven Fackler-13/+8
2018-04-22Replace GlobalAlloc::oom with a lang itemSteven Fackler-21/+22
2018-04-22Auto merge of #49896 - SimonSapin:inherent, r=alexcrichtonbors-3170/+20
Add inherent methods in libcore for [T], [u8], str, f32, and f64 # Background Primitive types are defined by the language, they don’t have a type definition like `pub struct Foo { … }` in any crate. So they don’t “belong” to any crate as far as `impl` coherence is concerned, and on principle no crate would be able to define inherent methods for them, without a trait. Since we want these types to have inherent methods anyway, the standard library (with cooperation from the compiler) bends this rule with code like [`#[lang = "u8"] impl u8 { /*…*/ }`](https://github.com/rust-lang/rust/blob/1.25.0/src/libcore/num/mod.rs#L2244-L2245). The `#[lang]` attribute is permanently-unstable and never intended to be used outside of the standard library. Each lang item can only be defined once. Before this PR there is one impl-coherence-rule-bending lang item per primitive type (plus one for `[u8]`, which overlaps with `[T]`). And so one `impl` block each. These blocks for `str`, `[T]` and `[u8]` are in liballoc rather than libcore because *some* of the methods (like `<[T]>::to_vec(&self) -> Vec<T> where T: Clone`) need a global memory allocator which we don’t want to make a requirement in libcore. Similarly, `impl f32` and `impl f64` are in libstd because some of the methods are based on FFI calls to C’s `libm` and we want, as much as possible, libcore not to require “runtime support”. In libcore, the methods of `str` and `[T]` that don’t allocate are made available through two **unstable traits** `StrExt` and `SliceExt` (so the traits can’t be *named* by programs on the Stable release channel) that have **stable methods** and are re-exported in the libcore prelude (so that programs on Stable can *call* these methods anyway). Non-allocating `[u8]` methods are not available in libcore: https://github.com/rust-lang/rust/issues/45803. Some `f32` and `f64` methods are in an unstable `core::num::Float` trait with stable methods, but that one is **not in the libcore prelude**. (So as far as Stable programs are concerns it doesn’t exist, and I don’t know what the point was to mark these methods `#[stable]`.) https://github.com/rust-lang/rust/issues/32110 is the tracking issue for these unstable traits. # High-level proposal Since the standard library is already bending the rules, why not bend them *a little more*? By defining a few additional lang items, the compiler can allow the standard library to have *two* `impl` blocks (in different crates) for some primitive types. The `StrExt` and `SliceExt` traits still exist for now so that we can bootstrap from a previous-version compiler that doesn’t have these lang items yet, but they can be removed in next release cycle. (`Float` is used internally and needs to be public for libcore unit tests, but was already `#[doc(hidden)]`.) I don’t know if https://github.com/rust-lang/rust/issues/32110 should be closed by this PR, or only when the traits are entirely removed after we make a new bootstrap compiler. # Float methods Among the methods of the `core::num::Float` trait, three are based on LLVM intrinsics: `abs`, `signum`, and `powi`. PR https://github.com/rust-lang/rust/pull/27823 “Remove dependencies on libm functions from libcore” moved a bunch of `core::num::Float` methods back to libstd, but left these three behind. However they aren’t specifically discussed in the PR thread. The `compiler_builtins` crate defines `__powisf2` and `__powidf2` functions that look like implementations of `powi`, but I couldn’t find a connection with the `llvm.powi.f32` and `llvm.powi.f32` intrinsics by grepping through LLVM’s code. In discussion starting at https://github.com/rust-lang/rust/issues/32110#issuecomment-370647922 Alex says that we do not want methods in libcore that require “runtime support”, but it’s not clear whether that applies to these `abs`, `signum`, or `powi`. In doubt, I’ve **removed** them for the trait and moved them to inherent methods in libstd for now. We can move them back later (or in this PR) if we decide that’s appropriate. # Change details For users on the Stable release channel: * I believe this PR does not make any breaking change * Some methods for `[u8]`, `f32`, and `f64` are newly available to `#![no_std]` users (fixes https://github.com/rust-lang/rust/issues/45803) * There should be no visible change for `std` users in terms of what programs compile or what their behavior is. (Only in compiler error messages, possibly.) For Nightly users, additionally: * The unstable `StrExt` and `SliceExt` traits are gone * Their methods are now inherent methods of `str` and `[T]` (so only code that explicitly named the traits should be affected, not "normal" method calls) * The `abs`, `signum` and `powi` methods of the `Float` trait are gone * The `Float` trait’s unstable feature name changed to `float_internals` with no associated tracking issue, to reflect it being a permanently unstable implementation detail rather than a public API on a path to stabilization. * Its remaining methods are now inherent methods of `f32` and `f64`. ----- CC @rust-lang/libs for the API changes, @rust-lang/compiler for the new lang items
2018-04-21Auto merge of #50039 - ExpHP:quick-50002, r=alexcrichtonbors-0/+30
smaller PR just to fix #50002 I pulled this out of #50010 to make it easier to backport to beta if necessary, considering that inclusive range syntax is stabilizing soon (?). It fixes a bug in `<str>::index_mut` with `(..=end)` ranges (#50002), which prior to this fix was not only unusable but also UB in the cases where it "worked" (it gave improperly truncated UTF-8). (not that I can imagine why anybody would *use* `<str>::index_mut`... but I'm not here to judge)
2018-04-21Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)Simon Sapin-1/+1
`Float` still needs to be public for libcore unit tests.
2018-04-21Add some f32 and f64 inherent methods in libcoreSimon Sapin-0/+1
… previously in the unstable core::num::Float trait. Per https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183, the `abs`, `signum`, and `powi` methods are *not* included for now since they rely on LLVM intrinsics and we haven’t determined yet whether those instrinsics lower to calls to libm functions on any platform.
2018-04-21Replace StrExt with inherent str methods in libcoreSimon Sapin-1724/+8
2018-04-21Replace SliceExt with inherent [T] methods in libcoreSimon Sapin-1391/+6
2018-04-21Move non-allocating [u8] inherent methods to libcoreSimon Sapin-54/+4
Fixes #45803
2018-04-20Auto merge of #50088 - alexcrichton:std-tweaks, r=sfacklerbors-44/+2
Tweak some stabilizations in libstd This commit tweaks a few stable APIs in the `beta` branch before they hit stable. The `str::is_whitespace` and `str::is_alphanumeric` functions were deleted (added in #49381, issue at #49657). The `and_modify` APIs added in #44734 were altered to take a `FnOnce` closure rather than a `FnMut` closure. Closes #49581 Closes #49657
2018-04-19Tweak some stabilizations in libstdAlex Crichton-44/+2
This commit tweaks a few stable APIs in the `beta` branch before they hit stable. The `str::is_whitespace` and `str::is_alphanumeric` functions were deleted (added in #49381, issue at #49657). The `and_modify` APIs added in #44734 were altered to take a `FnOnce` closure rather than a `FnMut` closure. Closes #49581 Closes #49657
2018-04-18fix my unit test that was horrendously wrongMichael Lamparski-3/+17
and add one for non-mut slicing since I touched that method too
2018-04-18Auto merge of #50017 - tinaun:stabilize-all-the-things, r=sfacklerbors-18/+5
stabilize a bunch of minor api additions besides `ptr::NonNull::cast` (which is 4 days away from end of FCP) all of these have been finished with FCP for a few weeks now with minimal issues raised * Closes #41020 * Closes #42818 * Closes #44030 * Closes #44400 * Closes #46507 * Closes #47653 * Closes #46344 the following functions will be stabilized in 1.27: * `[T]::rsplit` * `[T]::rsplit_mut` * `[T]::swap_with_slice` * `ptr::swap_nonoverlapping` * `NonNull::cast` * `Duration::from_micros` * `Duration::from_nanos` * `Duration::subsec_millis` * `Duration::subsec_micros` * `HashMap::remove_entry`
2018-04-17smaller PR just to fix #50002Michael Lamparski-0/+16
2018-04-17Rollup merge of #50013 - frewsxcv:frewsxcv-ssplice, r=GuillaumeGomezGuillaume Gomez-3/+0
Remove no longer necessary comparison to Vec::splice. `String::replace_range` was previously called `String::splice`, so this note was necessary to differentiate it from the `Vec` method. Now that it's renamed, this note no longer seems necessary.
2018-04-17stabilize `nonnull_cast` featuretinaun-1/+0
2018-04-17stabilize `swap_with_slice` featuretinaun-8/+2
2018-04-17stabilize `slice_rsplit` featuretinaun-9/+3
2018-04-17Remove no longer necessary comparison to Vec::splice.Corey Farwell-3/+0
`String::replace_range` was previously called `String::splice`, so this note was necessary to differentiate it from the `Vec` method. Now that it's renamed, this note no longer seems necessary.
2018-04-16Auto merge of #49488 - alexcrichton:small-wasm-panic, r=sfacklerbors-8/+15
std: Minimize size of panicking on wasm This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-04-17Rollup merge of #49555 - nox:inline-into-boxed, r=alexcrichtonkennytm-1/+9
Inline most of the code paths for conversions with boxed slices This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case. Everything involved in the conversions is made `#[inline]`, except for the `<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with `#[inline]`. For the record, that function was: ```rust pub fn foo() -> Box<[u8]> { vec![0].into_boxed_slice() } ``` To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
2018-04-16Auto merge of #48945 - clarcharr:iter_exhaust, r=Kimundibors-10/+6
Replace manual iterator exhaust with for_each(drop) This originally added a dedicated method, `Iterator::exhaust`, and has since been replaced with `for_each(drop)`, which is more idiomatic. <del>This is just shorthand for `for _ in &mut self {}` or `while let Some(_) = self.next() {}`. This states the intent a lot more clearly than the identical code: run the iterator to completion. <del>At least personally, my eyes tend to gloss over `for _ in &mut self {}` without fully paying attention to what it does; having a `Drop` implementation akin to: <del>`for _ in &mut self {}; unsafe { free(self.ptr); }`</del> <del>Is not as clear as: <del>`self.exhaust(); unsafe { free(self.ptr); }` <del>Additionally, I've seen debate over whether `while let Some(_) = self.next() {}` or `for _ in &mut self {}` is more clear, whereas `self.exhaust()` is clearer than both.
2018-04-15Remove #[inline(always)] on Vec::into_boxed_sliceAnthony Ramine-1/+0
2018-04-14Cleanup liballoc use statementsMike Hommey-15/+15
Some modules were still using the deprecated `allocator` module, use the `alloc` module instead. Some modules were using `super` while it's not needed. Some modules were more or less ordering them, and other not, so the latter have been modified to match the others.
2018-04-13Reduce the size of panics in RawVecAlex Crichton-8/+15
Create one canonical location which panics with "capacity overflow" instead of having many. This reduces the size of a `panic!("{}", 1)` binary on wasm from 34k to 17k.
2018-04-12Rename alloc::Void to alloc::OpaqueSimon Sapin-43/+43
2018-04-12Remove conversions for allocated pointersSimon Sapin-3/+3
One was now unused, and `NonNull::new(…).ok_or(AllocErr)` feels short enough for the few cases that need the other conversion.
2018-04-12Use NonNull<Void> instead of *mut u8 in the Alloc traitMike Hommey-65/+70
Fixes #49608
2018-04-12impl GlobalAlloc for GlobalSimon Sapin-35/+50
2018-04-12Restore Global.oom() functionalitySimon Sapin-0/+17
… now that #[global_allocator] does not define a symbol for it
2018-04-12realloc with a new size only, not a full new layout.Simon Sapin-26/+21
Changing the alignment with realloc is not supported.
2018-04-12Return Result instead of Option in alloc::Layout constructorsSimon Sapin-2/+2
2018-04-12Remove the now-unit-struct AllocErr field inside CollectionAllocErrSimon Sapin-22/+22
2018-04-12Remove the now-unit-struct AllocErr parameter of oom()Simon Sapin-13/+13
2018-04-12Use the GlobalAlloc trait for #[global_allocator]Simon Sapin-148/+40
2018-04-12Make AllocErr a zero-size unit structSimon Sapin-17/+17
2018-04-12Separate alloc::heap::Alloc trait for stage0 #[global_allocator]Simon Sapin-5/+104
2018-04-12Actually deprecate the Heap typeSimon Sapin-37/+37
2018-04-12Rename the Heap type to GlobalSimon Sapin-9/+14
… since it is the entry point for what’s registered with `#[global_allocator]`
2018-04-12Actually deprecate heap modules.Simon Sapin-3/+9