about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2018-05-09Rollup merge of #50527 - glandium:cleanup, r=sfacklerkennytm-1/+1
Cleanup a `use` in a raw_vec test `allocator` is deprecated in favor of `alloc`, and `Alloc` is already imported through `super::*`.
2018-05-09Rollup merge of #50511 - Manishearth:must-use, r=QuietMisdreavuskennytm-2/+4
Add some explanations for #[must_use] `#[must_use]` can be given a string argument which is shown whilst warning for things. We should add a string argument to most of the user-exposed ones. I added these for everything but the operators, mostly because I'm not sure what to write there or if we need anything there.
2018-05-09Rollup merge of #50460 - F001:const_string, r=kennytmkennytm-1/+3
Make `String::new()` const Following the steps of https://github.com/rust-lang/rust/pull/50233 , make `String::new()` a `const fn`.
2018-05-09Update features to 1.28.0George Burton-2/+2
2018-05-08Make an ensure_root_is_owned method to reduce duplicationC Jones-15/+10
Also remove some unnecessary debug_assert! when creating the shared root, since the root should be stored in the rodata and thus be impossible to accidentally modify.
2018-05-08Auto merge of #50497 - RalfJung:pinmut, r=withoutboatsbors-3/+3
Rename Pin to PinMut, and some more breaking changes As discussed at [1] §3 and [2] and [3], a formal look at pinning requires considering a distinguished "shared pinned" mode/typestate. Given that, it seems desirable to at least eventually actually expose that typestate as a reference type. This renames Pin to PinMut, freeing the name Pin in case we want to use it for a shared pinned reference later on. [1] https://www.ralfj.de/blog/2018/04/10/safe-intrusive-collections-with-pinning.html [2] https://github.com/rust-lang/rfcs/pull/2349#issuecomment-379250361 [3] https://github.com/rust-lang/rust/issues/49150#issuecomment-380488275 Cc @withoutboats
2018-05-08Cleanup a `use` in a raw_vec testMike Hommey-1/+1
`allocator` is deprecated in favor of `alloc`, and `Alloc` is already imported through `super::*`.
2018-05-07Add debug asserts and fix some violationsC Jones-0/+16
2018-05-07Make into_key_slice avoid taking out-of-bounds pointersC Jones-14/+34
2018-05-07Split into_slices() to avoid making extra slicesC Jones-25/+41
This splits into_slices() into into_key_slice() and into_val_slice(). While the extra calls would get optimized out, this is a useful semantic change since we call keys() while iterating, and we don't want to construct and out-of-bounds val() pointer in the process if we happen to be pointing to the shared static root. This also paves the way for doing the alignment handling conditional differently for the keys and values.
2018-05-07Don't drop the shared static nodeC Jones-8/+13
We modify the drop implementation in IntoIter to not drop the shared root
2018-05-07Add a statically allocated empty node for empty mapsC Jones-2/+43
This gives a pointer to that static empty node instead of allocating a new node, and then whenever inserting makes sure that the root isn't that empty node.
2018-05-07Make LeafNode #[repr(C)] and put the metadata before generic itemsC Jones-8/+12
This way we can safely statically allocate a LeafNode to use as the placeholder before allocating, and any type accessing it will be able to access the metadata at the same offset.
2018-05-07Add explanation for #[must_use] on string replace methodsManish Goregaokar-2/+4
2018-05-07Rename Pin to PinMutRalf Jung-3/+3
As discussed at [1] §3 and [2] and [3], a formal look at pinning requires considering a distinguished "shared pinned" mode/typestate. Given that, it seems desirable to at least eventually actually expose that typestate as a reference type. This renames Pin to PinMut, freeing the name Pin in case we want to use it for a shared pinned reference later on. [1] https://www.ralfj.de/blog/2018/04/10/safe-intrusive-collections-with-pinning.html [2] https://github.com/rust-lang/rfcs/pull/2349#issuecomment-379250361 [3] https://github.com/rust-lang/rust/issues/49150#issuecomment-380488275
2018-05-06Use ManuallyDrop instead of Option in Hole implementationNikita Popov-6/+5
The Option is always Some until drop, where it becomes None. Make this more explicit and avoid unwraps by using ManuallyDrop. This change should be performance-neutral as LLVM already optimizes the unwraps away in the inlined code.
2018-05-05make `String::new()` constF001-1/+3
2018-05-01Auto merge of #49724 - kennytm:range-inc-start-end-methods, r=Kimundibors-2/+2
Introduce RangeInclusive::{new, start, end} methods and make the fields private. cc #49022
2018-04-30Auto merge of #48925 - zackmdavis:fn_must_stabilize, r=nikomatsakisbors-1/+2
stabilize `#[must_use]` for functions and must-use comparison operators (RFC 1940) r? @nikomatsakis
2018-05-01Rollup merge of #50233 - mark-i-m:const_vec, r=kennytmkennytm-5/+9
Make `Vec::new` a `const fn` `RawVec::empty/_in` are a hack. They're there because `if size_of::<T> == 0 { !0 } else { 0 }` is not allowed in `const` yet. However, because `RawVec` is unstable, the `empty/empty_in` constructors can be removed when #49146 is done...
2018-04-30revise test gen macro for strMichael Lamparski-144/+81
2018-04-30Make the fields of RangeInclusive private.kennytm-2/+2
Added new()/start()/end() methods to RangeInclusive. Changed the lowering of `..=` to use RangeInclusive::new().
2018-04-30decrease false negatives for str overflow testMichael Lamparski-1/+3
2018-04-30flesh out tests for SliceIndexMichael Lamparski-99/+378
m*n lines of implementation deserves m*n lines of tests
2018-04-30collect str SliceIndex tests into a modMichael Lamparski-137/+140
GitHub users: I think you can add ?w=1 to the url for a vastly cleaner whitespace-ignoring diff
2018-04-29heh, logic is hardMark Mansi-1/+1
2018-04-29use const trickMark Mansi-24/+7
2018-04-28stabilize `#[must_use]` for functions and must-use operatorsZack M. Davis-1/+2
This is in the matter of RFC 1940 and tracking issue #43302.
2018-04-27Update the stable attributes to use the current nightly version numberGeorge Burton-2/+2
2018-04-28Rollup merge of #49858 - dmizuk:unique-doc-hidden, r=steveklabnikkennytm-0/+1
std: Mark `ptr::Unique` with `#[doc(hidden)]` `Unique` is now perma-unstable, so let's hide its docs.
2018-04-27Auto merge of #50097 - glandium:box_free, r=nikomatsakisbors-7/+17
Partial future-proofing for Box<T, A> In some ways, this is similar to @eddyb's PR #47043 that went stale, but doesn't cover everything. Notably, this still leaves Box internalized as a pointer in places, so practically speaking, only ZSTs can be practically added to the Box type with the changes here (the compiler ICEs otherwise). The Box type is not changed here, that's left for the future because I want to test that further first, but this puts things in place in a way that hopefully will make things easier.
2018-04-26not insta-stableMark Mansi-0/+2
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