about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-01-18Format codeoxalica-6/+2
2021-01-17Auto merge of #80524 - jyn514:unknown-tool-lints, r=flip1995,matthewjasperbors-2/+4
Don't make tools responsible for checking unknown and renamed lints Previously, clippy (and any other tool emitting lints) had to have their own separate UNKNOWN_LINTS pass, because the compiler assumed any tool lint could be valid. Now, as long as any lint starting with the tool prefix exists, the compiler will warn when an unknown lint is present. This may interact with the unstable `tool_lint` feature, which I don't entirely understand, but it will take the burden off those external tools to add their own lint pass, which seems like a step in the right direction to me. - Don't mark `ineffective_unstable_trait_impl` as an internal lint - Use clippy's more advanced lint suggestions - Deprecate the `UNKNOWN_CLIPPY_LINTS` pass (and make it a no-op) - Say 'unknown lint `clippy::x`' instead of 'unknown lint x' This is tested by existing clippy tests. When https://github.com/rust-lang/rust/pull/80527 merges, it will also be tested in rustdoc tests. AFAIK there is no way to test this with rustc directly.
2021-01-18Optimize Vec::retainoxalica-11/+68
2021-01-17Rollup merge of #81082 - ssomers:btree_cleanup_comments, r=Mark-SimulacrumMara Bos-6/+8
BTreeMap: clean up a few more comments And mark `pop` as unsafe. r? ```@Mark-Simulacrum```
2021-01-17Rollup merge of #81080 - bugadani:vec-diag, r=oli-obk,m-ou-seMara Bos-4/+12
Force vec![] to expression position only r? `@oli-obk` I went with the lazy way of only changing what broke. I moved the test to ui/macros because the diagnostics no longer give suggestions. Closes #61933
2021-01-17Force vec! to expressions onlyDániel Buga-4/+12
2021-01-17Remove unused alloc::std::ops re-export.Mara Bos-5/+0
2021-01-17Auto merge of #81083 - ssomers:btree_drainy_refactor_1, r=Mark-Simulacrumbors-13/+14
BTreeMap: expose new_internal function and sanitize from_new_internal `new_internal` is the functional core of the imperative `push_internal_level`, and `from_new_internal` can easily do a proper job instead of returning a half-baked node. r? `@Mark-Simulacrum`
2021-01-16BTreeMap: offer merge in variants with more clarityStein Somers-34/+60
2021-01-16Rollup merge of #81069 - ogoffart:rc_new_cyclic_doc, r=Mark-SimulacrumMara Bos-0/+20
Add sample code for Rc::new_cyclic
2021-01-16Rollup merge of #80764 - CAD97:weak-unsized-as-ptr-again, r=RalfJungMara Bos-95/+153
Re-stabilize Weak::as_ptr and friends for unsized T As per [T-lang consensus](https://hackmd.io/7r3_is6uTz-163fsOV8Vfg), this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization) and not _obviously_ better (as it requires using `wrapping_offset` rather than `offset` more). <details><summary>Basically said optimization</summary> Specialize on `T: Sized`: ```rust fn as_ptr(&self) -> *const T { if [ T is Sized ] || !is_dangling(ptr) { (ptr as *mut T).set_ptr_value( (ptr as *mut u8).wrapping_offset(data_offset) ) } else { ptr::null() } } fn from_raw(*const T) -> Self { if [ T is Sized ] || !ptr.is_null() { let ptr = (ptr as *mut RcBox).set_ptr_value( (ptr as *mut u8).wrapping_offset(-data_offset) ); Weak { ptr } } else { Weak::new() } } ``` (but with more `set_ptr_value` to avoid `Sized` restrictions and maintain metadata.) Written in this fashion, this is not a correctness-critical specialization (i.e. so long as `[ T is Sized ]` is false for unsized `T`, it can be `rand()` for sized `T` without breaking correctness), but it's still touchy, so I'd rather do it in another PR with separate review. --- </details> This effectively reverts #80422 and re-establishes #74160. T-libs [previously signed off](https://github.com/rust-lang/rust/pull/74160#issuecomment-660539373) on this stable API change in #74160.
2021-01-16Rollup merge of #80681 - ChrisJefferson:logic-error-doc, r=m-ou-seMara Bos-1/+10
Clarify what the effects of a 'logic error' are This clarifies what a 'logic error' is (which is a term used to describe what happens if you put things in a hash table or btree and then use something like a refcell to break the internal ordering). This tries to be as vague as possible, as we don't really want to promise what happens, except "bad things, but not UB". This was discussed in #80657
2021-01-16BTreeMap: expose new_internal function and sanitize from_new_internalStein Somers-13/+14
2021-01-16BTreeMap: clean up a few more commentsStein Somers-6/+8
2021-01-16Auto merge of #77435 - hanmertens:binary_heap_append, r=scottmcmbors-2/+8
Always use extend in BinaryHeap::append This is faster, see #77433. Fixes #77433
2021-01-16Clarify what the effects of a 'logic error' areChris Jefferson-1/+10
2021-01-16Add sample code for Rc::new_cyclicOlivier Goffart-0/+20
2021-01-16Auto merge of #80873 - ssomers:btree_cleanup_slices_4, r=Mark-Simulacrumbors-81/+88
BTreeMap: tougher checks on code using raw into_kv_pointers r? `@Mark-Simulacrum`
2021-01-15Don't mark `ineffective_unstable_trait_impl` as an internal lintJoshua Nelson-2/+4
It's not an internal lint: - It's not in the rustc::internal lint group - It's on unconditionally, because it actually lints `staged_api`, not the compiler This fixes a bug where `#[deny(rustc::internal)]` would warn that `rustc::internal` was an unknown lint.
2021-01-15Change rebuild heuristic in BinaryHeap::appendHan Mertens-2/+8
See #77433 for why the new heuristic was chosen. Fixes #77433
2021-01-15Rollup merge of #80834 - bugadani:vecdeque, r=oli-obkYuki Okushi-5/+4
Remove unreachable panics from VecDeque::{front/back}[_mut] `VecDeque`'s `front`, `front_mut`, `back` and `back_mut` methods are implemented in terms of the index operator, which causes these functions to contain [unreachable panic calls](https://rust.godbolt.org/z/MTnq1o). This PR reimplements these methods in terms of `get[_mut]` instead.
2021-01-14Remove unreachable panics from VecDequeDániel Buga-5/+4
2021-01-14Rollup merge of #80972 - KodrAus:deprecate/remove_item, r=nagisaMara Bos-21/+0
Remove unstable deprecated Vec::remove_item Closes #40062 The `Vec::remove_item` method was deprecated in `1.46.0` (in August of 2020). This PR now removes that unstable method entirely.
2021-01-14Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-seMara Bos-1/+1
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop For https://github.com/rust-lang/rust/issues/55002 We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2021-01-13Apply suggestions from code reviewChristopher Durham-2/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-01-13Auto merge of #80824 - cuviper:heap-clones, r=kennytmbors-23/+65
Try to avoid locals when cloning into Box/Rc/Arc For generic `T: Clone`, we can allocate an uninitialized box beforehand, which gives the optimizer a chance to create the clone directly in the heap. For `T: Copy`, we can go further and do a simple memory copy, regardless of optimization level. The same applies to `Rc`/`Arc::make_mut` when they must clone the data.
2021-01-13deprecate atomic::spin_loop_hint in favour of hint::spin_loopAshley Mannix-1/+1
2021-01-13remove unstable deprecated Vec::remove_itemAshley Mannix-21/+0
2021-01-12move WriteCloneIntoRaw into alloc::allocJosh Stone-27/+31
2021-01-12Add Box::downcast() for dyn Any + Send + SyncSebastian Dröge-0/+33
2021-01-11Move directly when Rc/Arc::make_mut splits from WeakJosh Stone-14/+13
When only other `Weak` references remain, we can directly move the data into the new unique allocation as a plain memory copy.
2021-01-11Specialize Rc/Arc::make_mut clones to try to avoid localsJosh Stone-5/+18
As we did with `Box`, we can allocate an uninitialized `Rc` or `Arc` beforehand, giving the optimizer a chance to skip the local value for regular clones, or avoid any local altogether for `T: Copy`.
2021-01-11Specialize Box clones to try to avoid localsJosh Stone-2/+28
For generic `T: Clone`, we can allocate an uninitialized box beforehand, which gives the optimizer a chance to create the clone directly in the heap. For `T: Copy`, we can go further and do a simple memory copy, regardless of optimization level.
2021-01-10Weak::into_raw shouldn't translate sentinel valueCAD97-27/+21
2021-01-11Add another test case for #79808Yuki Okushi-0/+15
Taken from #80293.
2021-01-10BTreeMap: tougher checks on code using raw into_kv_pointersStein Somers-81/+88
2021-01-10Auto merge of #80391 - ssomers:btree_cleanup_slices_3, r=Mark-Simulacrumbors-26/+32
BTreeMap: tougher checking on most uses of copy_nonoverlapping Miri checks pointer provenance and destination, but we can check it in debug builds already. Also, we can let Miri confirm we don't mistake imprints of moved keys and values as genuine. r? `@Mark-Simulacrum`
2021-01-09Add comment to `Vec::truncate` explaining `>` vs `>=`Camelid-0/+3
Hopefully this will prevent people from continuing to ask about this over and over again :) See [this Zulip discussion][1] for more. [1]: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Vec.3A.3Atruncate.20implementation
2021-01-09Provide reasoning for rc data_offset safetyCAD97-8/+12
2021-01-08BTreeMap: tougher checks on most uses of copy_nonoverlappingStein Somers-26/+32
2021-01-07Replace set_data_ptr with pointer::set_ptr_valueCAD97-32/+5
2021-01-07Reclarify Weak<->raw pointer safety commentsCAD97-4/+4
2021-01-07Remove "pointer describes" terminologyCAD97-10/+8
2021-01-07Tighten/clarify documentation of rc data_offsetCAD97-10/+4
2021-01-06Re-stabilize Weak::as_ptr &friends for unsized TCAD97-35/+130
As per T-lang consensus, this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization for correctness, not just optimization).
2021-01-05Rollup merge of #80666 - jjlin:master, r=Dylan-DPCYuki Okushi-0/+1
Fix missing link for "fully qualified syntax" This issue can currently be seen at https://doc.rust-lang.org/stable/std/rc/index.html#toggle-all-docs:~:text=%5B-,fully%20qualified%20syntax It originates from #76138, where the link was added to `library/alloc/src/sync.rs`, but not `library/alloc/src/rc.rs`.
2021-01-05Rollup merge of #80442 - steffahn:mention_arc_in_cow, r=Mark-SimulacrumYuki Okushi-0/+5
Mention Arc::make_mut and Rc::make_mut in the documentation of Cow Following this discussion: https://users.rust-lang.org/t/should-the-cow-documentation-mention-arc/53341 _Rendered (the last paragraph is new):_ ![Screenshot_20201228_171551](https://user-images.githubusercontent.com/3986214/103228135-5d72e200-4930-11eb-89e1-38b5c86b08c7.png) `@rustbot` modify labels: T-doc, T-libs
2021-01-03Fix missing link for "fully qualified syntax"Jeremy Lin-0/+1
2021-01-03Rollup merge of #80591 - lcnr:incomplete-features, r=RalfJungGuillaume Gomez-2/+1
remove allow(incomplete_features) from std cc https://github.com/rust-lang/rust/pull/80349#issuecomment-753357123 > Now I am somewhat concerned that the standard library uses some of these features... I think it is theoretically ok to use incomplete features in the standard library or the compiler if we know that there is an already working subset and we explicitly document what we have to be careful about. Though at that point it is probably better to try and split the incomplete feature into two separate ones, similar to `min_specialization`. Will be interesting once `feature(const_evaluatable_checked)` works well enough to imo be used in the compiler but not yet well enough to be removed from `INCOMPLETE_FEATURES`. r? `@RalfJung`
2021-01-02Auto merge of #77832 - camelid:remove-manual-link-resolves, r=jyn514bors-4/+0
Remove many unnecessary manual link resolves from library Now that #76934 has merged, we can remove a lot of these! E.g, this is no longer necessary: [`Vec<T>`]: Vec cc `@jyn514`