about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-01-21Rename alloc::force_expr to __rust_force_expr.Mara Bos-4/+4
2021-01-21Turn alloc's force_expr macro into a regular macro_rules!{}.Mara Bos-10/+13
Otherwise rust-analyzer doesn't understand vec![].
2021-01-21Enforce statically that `MIN_NON_ZERO_CAP` is calculated at compile timeJoshua Nelson-16/+14
Previously, it would usually get computed by LLVM, but this enforces it.
2021-01-21Rollup merge of #81179 - CPerezz:fix_interal_doc_warns, r=jyn514Yuki Okushi-1/+1
Fix broken links with `--document-private-items` in the standard library As it was suggested in #81037 `SpecFromIter` is not in the scope and therefore we get a warning when we try to do document private intems in `rust/library/alloc/`. This addresses #81037 by adding the trait in the scope as ```@jyn514``` suggested and also adding an `allow(unused_imports)` flag so that the compiler does not complain, Since the trait is not used per se in the code, it's just needed to have properly documented docs.
2021-01-21Rollup merge of #80601 - steffahn:improve_format_string_grammar, r=m-ou-seYuki Okushi-4/+5
Improve grammar in documentation of format strings The docs previously were * using some weird `<` and `>` around some nonterminals * _correct me if these **did** have any meaning_ * using of a (not explicitly defined) `text` nonterminal that didn’t explicitly disallow productions containing `'{'` or `'}'` * incorrect in not allowing for `x?` and `X?` productions of `type` * unnecessarily ambiguous, both * allowing `type` to be `''`, and * using an optional `[type]` * using inconsistent underscore/hyphenation style between `format_string` and `format_spec` vs `maybe-format` _Rendered:_ ![Screenshot_20210101_230901](https://user-images.githubusercontent.com/3986214/103447038-69d7a180-4c86-11eb-8fa0-0a6160a7ff7a.png) _(current docs: https://doc.rust-lang.org/nightly/std/fmt/#syntax)_ ```@rustbot``` modify labels: T-doc
2021-01-21Remove link to current sectionIvan Tham-2/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-01-20BTreeMap: bring back the key slice for immutable lookupStein Somers-43/+23
2021-01-20Add more details explaning the Vec visualizationIvan Tham-20/+22
Suggested by oli-obk
2021-01-20Add Vec visualization to understand capacityIvan Tham-0/+21
Visualize vector while differentiating between stack and heap. Inspired by cheats.rs, as this is probably the first place beginner go, they could understand stack and heap, length and capacity with this. Not sure if adding this means we should add to other places too. Superseeds #76066
2021-01-19BTreeMap: compile-test all borrowing interfaces and test more chaotic orderStein Somers-1/+87
2021-01-19Add SpecFromIter ref in the comments directlyCPerezz-3/+1
2021-01-19Rollup merge of #81115 - ssomers:btree_drainy_refactor_4, r=Mark-SimulacrumGuillaume Gomez-121/+8
BTreeMap: prefer bulk_steal functions over specialized ones The `steal_` functions (apart from their return value) are basically specializations of the more general `bulk_steal_` functions. This PR removes the specializations. The library/alloc benchmarks say this is never slower and up to 6% faster. r? ``@Mark-Simulacrum``
2021-01-19Rollup merge of #81112 - m-ou-se:alloc-std-ops-reexport, r=KodrAusGuillaume Gomez-5/+0
Remove unused alloc::std::ops re-export. Removes unused re-export in alloc/lib.rs.
2021-01-18Fix soundness issue for `replace_range` and `range`dylni-6/+20
2021-01-18Fix internal rustdoc broken linksCPerezz-0/+2
As it was suggested in #81037 `SpecFromIter` is not in the scope and therefore (even it should fail), we get a warning when we try do document private intems in `rust/library/alloc/`. This fixes #81037 by adding the trait in the scope and also adding an `allow(unused_imports)` flag so that the compiler does not complain, Since the trait is not used per se in the code, it's just needed to have properly documented docs.
2021-01-18Avoid hash_slice in VecDeque's Hash implementationKonrad Borowski-3/+47
Fixes #80303.
2021-01-18BTreeMap: prefer bulk_steal functions over specialized onesStein Somers-121/+8
2021-01-18BTreeMap: convert search functions to methodsStein Somers-83/+83
2021-01-18Auto merge of #81090 - ssomers:btree_drainy_refactor_2, r=Mark-Simulacrumbors-34/+60
BTreeMap: offer merge in variants with more clarity r? `@Mark-Simulacrum`
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.