summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2019-06-27Rollup merge of #62043 - Centril:remove-fnbox, r=cramertjMazdak Farrokhzad-79/+0
Remove `FnBox` Remove `FnBox` since we now have `Box<dyn FnOnce>`. Closes https://github.com/rust-lang/rust/issues/28796. r? @cramertj
2019-06-22Remove FnBox.Mazdak Farrokhzad-79/+0
2019-06-22Rollup merge of #61146 - czipperz:SliceConcatExt-connect-default-to-join, ↵Mazdak Farrokhzad-9/+3
r=sfackler SliceConcatExt::connect defaults to calling join It makes sense to default a deprecated method to the new one. Precedence example is `Error::cause` defaults to calling `Error::source`.
2019-06-17Rollup merge of #61893 - chpio:weak_ptr_eq_methods, r=rkruppeMazdak Farrokhzad-14/+14
make `Weak::ptr_eq`s into methods This makes the `Weak::ptr_eq`s associated function into methods. There's no reason for methods on `Weak`s to be associated functions, as there is no `Dered` thus no possibility of a collision. Also: methods can be called using the associated function syntax. follow up on https://github.com/rust-lang/rust/pull/55987 [Tracking issue for weak_ptr_eq](https://github.com/rust-lang/rust/issues/55981)
2019-06-16make `Weak::ptr_eq`s into methodsThomas Heck-14/+14
2019-06-16Separate liballoc modulechansuke-1/+1
2019-06-16Rollup merge of #61447 - scottmcm:vec-vecdeque, r=sfacklerMazdak Farrokhzad-0/+31
Add some Vec <-> VecDeque documentation These are more than just `.into_iter().collect()`, so talk about some of their nuances. For VecDeque -> Vec I'm trying to intentionally not write a guarantee for people making their own `Vec`s, since the rules are more complicated than I think we want to commit to forever. The "Vec -> VecDeque doesn't reallocate" guarantee seems reasonable, though. (And I'm intentionally ambiguous about when it's O(1) instead of O(n).)
2019-06-14Auto merge of #61421 - vorner:string-in-rc-into-raw-docs, r=RalfJungbors-28/+28
docs: Use String in Rc::into_raw examples It is unclear if accessing an integer after `drop_in_place` has been called on it is undefined behaviour or not, as demonstrated by the discussion in https://github.com/rust-lang/rust/pull/60766#pullrequestreview-243414222. Avoid these uncertainties by using String which frees memory in its `drop_in_place` to make sure this is undefined behaviour. The message in the docs should be to watch out and not access the data after that, not discussing when one maybe could get away with it O:-).
2019-06-13docs: Use String in Rc::into_raw examplesMichal 'vorner' Vaner-28/+28
It is unclear if accessing an integer after `drop_in_place` has been called on it is undefined behaviour or not, as demonstrated by the discussion in https://github.com/rust-lang/rust/pull/60766#pullrequestreview-243414222. Avoid these uncertainties by using String which frees memory in its `drop_in_place` to make sure this is undefined behaviour. The message in the docs should be to watch out and not access the data after that, not discussing when one maybe could get away with it O:-).
2019-06-12Hygienize macros in the standard libraryVadim Petrochenkov-1/+1
2019-06-11Remove the questionably-useful exampleScott McMurray-22/+0
2019-06-08Add hyperlinks to Vec and VecDequeScott McMurray-2/+2
Let's try the auto-linking instead, since the relative ones don't work.
2019-06-08Apply suggestions from code reviewscottmcm-1/+1
Co-Authored-By: Joe ST <joe@fbstj.net>
2019-06-08Put the docs on the methods instead of the implsScott McMurray-53/+53
Since simulacrum suggested (on Discord) they're better there.
2019-06-08Apply suggestions from code reviewscottmcm-10/+10
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-06-08Add some Vec <-> VecDeque documentationScott McMurray-0/+53
These are more than just `.into_iter().collect()`, so talk about some of their nuances.
2019-06-08Turn `#[allocator]` into a built-in attribute and rename it to ↵Vadim Petrochenkov-2/+3
`#[rustc_allocator]`
2019-06-04Rollup merge of #61420 - felixrabe:patch-2, r=dtolnayMazdak Farrokhzad-6/+4
Succinctify splice docs
2019-06-04Rollup merge of #61419 - scottmcm:casing-is-on-strings, r=cramertjMazdak Farrokhzad-0/+7
Add an unusual-conversion example to to_uppercase Like how to_lowercase has ὈΔΥΣΣΕΎΣ.
2019-06-04Rollup merge of #61135 - czipperz:rc-make_mut-weak-doc, r=Mark-SimulacrumMazdak Farrokhzad-7/+27
Fix documentation of `Rc::make_mut` regarding `rc::Weak`. Closes #60961
2019-06-01Succinctify splice docsFelix Rabe-6/+4
2019-06-01Add an unusual-conversion example to to_uppercaseScott McMurray-0/+7
Like how to_lowercase has ὈΔΥΣΣΕΎΣ.
2019-05-30Stabilize iter_nth_back featureLzu Tao-1/+0
2019-05-30Rollup merge of #61244 - RalfJung:box, r=rkruppeMazdak Farrokhzad-5/+4
Box::into_vec: use Box::into_raw instead of mem::forget `Box::into_raw` does, in one step, turn the `Box` into a raw ptr and avoid deallocation. Seems cleaner than separating the two. Also, `mem::forget` gets the `Box` with a `noalias` argument, but it is not actually correct that this is an exclusive pointer. So a stricter version of Stacked Borrows would complain here. (I can't actually make Stacked Borrows that strict yet though due to other issues.)
2019-05-29Rollup merge of #60766 - vorner:weak-into-raw, r=sfacklerMazdak Farrokhzad-12/+314
Weak::into_raw Hello This is my first shot at #60728. I'd like to consult it a bit before moving further. The biggest question I have is if this API makes sense. My motivation for it is to be able to store the `Weak` in `AtomicPtr`. For that I don't actually need for the pointer to point to the `T`, any pointer (maybe casted to `usize`) would be good enough, but this mirrors what `Arc` does and could be useful for other things too (like comparing if Arc and Weak point to the same thing without playing with the counts), while some opaque pointer wouldn't. Some secondary questions, if this is deemed desirable are: * The weak pointer may be dangling if it is created by `Weak::new()`. It would make sense to treat this as NULL, but that is incompatible with `T: ?Sized` ‒ both `new()` and `ptr::null()` are available only for sized types. The current implementation is therefore also available only for sized `T`s. It would be possible to allow `?Sized` if the API would be `fn into_raw(self) -> Option<NonNull<T>>` and `fn from_raw(NonNull<T>)`, but that's different API than `Arc` has. What would be preferred? * There's a FIXME in my code about what I suspect could be UB. Is it really UB & how to get the pointer correctly? Is manual offsetting of the pointer the only way? * Am I missing some other necessary thing around the feature gates and such? * Is the documentation understandable? I know writing docs is not my strongest skill :-|. Thinks I'd like to do as part of the PR, but are not yet done: * Turn the referenced issue into tracking issue for the feature flag. * Once the `sync::Weak` is considered reasonable, I'd do the equivalent for `rc::Weak`. * This might call for few more tests than what is currently part of the documentation.
2019-05-27Box::into_vec: use Box::into_raw instead of mem::forgetRalf Jung-5/+4
2019-05-27Update src/liballoc/boxed.rsAleksey Kladov-0/+1
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-05-27make Box<str>::clone simpler & saferAleksey Kladov-4/+2
2019-05-27avoid materializing unintialized Boxes in RawVecAleksey Kladov-7/+12
2019-05-26rc::Weak::{as,from,into}_rawMichal 'vorner' Vaner-6/+156
Methods on the Weak to access it as a raw pointer to the data.
2019-05-26sync::Weak::{as,from,into}_rawMichal 'vorner' Vaner-6/+158
Methods on the Weak to access it as raw pointer to the data.
2019-05-26Rollup merge of #61114 - RalfJung:vec, r=GankroMazdak Farrokhzad-7/+92
Vec: avoid creating slices to the elements Instead of `self.deref_mut().as_mut_ptr()` to get a raw pointer to the buffer, use `self.buf.ptr_mut()`. This (a) avoids creating a unique reference to all existing elements without any need, and (b) creates a pointer that can actually be used for the *entire* buffer, and not just for the part of it covered by `self.deref_mut()`. I also got worried about `RawVec::ptr` returning a `*mut T` from an `&self`, so I added both a mutable and an immutable version. Cc @Gankro in particular for the `assume` changes -- I don't know why that is not in `Unique`, but I moved it up from `Vec::deref` to `RawVec::ptr` to avoid having to repeat it everywhere. Fixes https://github.com/rust-lang/rust/issues/60847
2019-05-25shadow as_ptr as as_mut_ptr in Vec to avoid going through DerefRalf Jung-7/+71
2019-05-25add test checking that Vec push/pop does not invalidate pointersRalf Jung-0/+21
2019-05-24Remove unused import in doctestChris Gregory-1/+1
2019-05-24Reword `are not other` to `are no other`Chris Gregory-1/+1
Co-Authored-By: Jonas Schievink <jonasschievink@gmail.com>
2019-05-24SliceConcatExt::connect defaults to calling joinChris Gregory-9/+3
2019-05-24Fix documentation of `Rc::make_mut` regarding `rc::Weak`.Chris Gregory-7/+27
2019-05-24Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35Simon Sapin-9/+33
FCP completion: https://github.com/rust-lang/rust/issues/28796#issuecomment-439731515
2019-05-24Rollup merge of #61086 - RalfJung:box, r=alexcrichtonMazdak Farrokhzad-5/+6
Box::into_unique: do the reborrow-to-raw *after* destroying the Box Currently we first "reborrow" the box to a raw pointer, and then `forget` it. When tracking raw pointers more strictly (something I am experimenting with locally in Miri), the "use" induced by passing the box to `forget` invalidates the previously created raw pointer. So adjust my hack from https://github.com/rust-lang/rust/pull/58429 to reorder the two operations.
2019-05-23adjust commentRalf Jung-1/+2
2019-05-23Box::into_unique: do the reborrow-to-raw *after* destroying the BoxRalf Jung-4/+4
2019-05-23fix dangling reference in Vec::appendRalf Jung-3/+4
2019-05-22Revert "Add implementations of last in terms of next_back on a bunch of ↵Steven Fackler-88/+0
DoubleEndedIterators." This reverts commit 3e86cf36b5114f201868bf459934fe346a76a2d4.
2019-05-22Auto merge of #59445 - alexreg:ban-multi-trait-objects-via-aliases, r=oli-obkbors-4/+4
Ban multi-trait objects via trait aliases Obviously, multi-trait objects are not normally supported, so they should not be supported via trait aliases. This has been factored out from the previous PR https://github.com/rust-lang/rust/pull/55994 (see point 1). r? @Centril CC @nikomatsakis ------------------ ### RELNOTES: We now allow `dyn Send + fmt::Debug` with equivalent semantics to `dyn fmt::Debug + Send`. That is, the order of the mentioned traits does not matter wrt. principal/not-principal traits. This is a small change that might deserve a mention in the blog post because it is a language change but most likely not. See https://github.com/rust-lang/rust/blob/ce2ee305f9165c037ecddddb5792588a15ff6c37/src/test/ui/traits/wf-trait-object-reverse-order.rs. // @Centril
2019-05-22Rollup merge of #60963 - blkerby:boxed_docs, r=alexcrichtonMazdak Farrokhzad-25/+64
Update boxed::Box docs on memory layout The existing docs for the `Box` type state that "the way `Box` allocates and releases memory is unspecified", and that therefore the only valid pointer to pass to `Box::from_raw` is one obtained from `Box::into_raw`. This is inconsistent with the module-level docs which specify, > It is valid to convert both ways between a Box and a raw pointer allocated with the Global allocator, given that the Layout used with the allocator is correct for the type. More precisely, a value: *mut T that has been allocated with the Global allocator with Layout::for_value(&*value) may be converted into a box using Box::<T>::from_raw(value). Conversely, the memory backing a value: *mut T obtained from Box::<T>::into_raw may be deallocated using the Global allocator with Layout::for_value(&*value). This pull request updates the docs for `Box` to make them consistent with the module-level docs and adds some examples of how to use the global allocator in conjunction with `Box::from_raw` and `Box::into_raw`.
2019-05-20Create and reference Memory Layout section of boxed docsBrent Kerby-31/+39
2019-05-20Rollup merge of #60952 - dtolnay:heap, r=AmanieuMazdak Farrokhzad-0/+43
Document BinaryHeap time complexity I went into some detail on the time complexity of `push` because it is relevant for using BinaryHeap efficiently -- specifically that you should avoid pushing many elements in ascending order when possible. r? @Amanieu Closes #47976. Closes #59698.
2019-05-20Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPCMazdak Farrokhzad-0/+18
Fix intra-doc link resolution failure on re-exporting libstd Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366). ```rust pub use std::*; ``` Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates. Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.) r? @QuietMisdreavus
2019-05-20Ban multi-trait objects via trait aliases.Alexander Regueiro-4/+4