about summary refs log tree commit diff
path: root/library/alloc/src/boxed.rs
AgeCommit message (Collapse)AuthorLines
2023-03-28Remove ~const from allocJubilee Young-28/+16
2023-03-03Make `unused_allocation` lint warn against `Box::new`Maybe Waffle-0/+1
2023-02-27Remove or justify use of #[rustc_box]Ben Kimock-5/+4
2022-12-28Update bootstrap cfgPietro Albini-30/+0
2022-12-28Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errorsfee1-dead-1/+1
Fix `unused_must_use` warning for `Box::from_raw`
2022-12-19Update coerce_unsized tracking issue from #27732 to #18598Anders Kaseorg-1/+1
Issue #27732 was closed as a duplicate of #18598. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-11-22Rollup merge of #101655 - dns2utf8:box_docs, r=dtolnayManish Goregaokar-1/+1
Make the Box one-liner more descriptive I would like to avoid a definition that relies on itself. r? `@GuillaumeGomez`
2022-11-21Touch up Box<T> one-linerDavid Tolnay-2/+2
2022-11-06Bump version placeholders to releaseMark Rousskov-1/+1
2022-11-05Fix unused_must_use warning for Box::from_rawAnett Seeker-1/+1
2022-11-05Enforce Tuple trait on Fn traitsMichael Goulet-0/+31
2022-10-17Auto merge of #101837 - scottmcm:box-array-from-vec, r=m-ou-sebors-1/+50
Add `Box<[T; N]>: TryFrom<Vec<T>>` We have `[T; N]: TryFrom<Vec<T>>` (#76310) and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not this combination. `vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case. **Insta-stable, so needs an FCP** (I tried to make this work with `, A`, but that's disallowed because of `#[fundamental]` https://github.com/rust-lang/rust/issues/29635#issuecomment-1247598385)
2022-09-26remove cfg(bootstrap)Pietro Albini-14/+0
2022-09-17Add `Box<[T; N]>: TryFrom<Vec<T>>`Scott McMurray-1/+50
We have `[T; N]: TryFrom<Vec<T>>` and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not the combination. `vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case. **Insta-stable, so needs an FCP**
2022-09-16Do not implement `Unpin` as constDeadbeef-2/+1
2022-09-10Make the one-liner more descriptiveStefan Schindler-2/+2
2022-08-28Rollup merge of #99570 - XrXr:box-from-slice-docs, r=thomccMatthias Krüger-1/+1
Box::from(slice): Clarify that contents are copied A colleague mentioned that they interpreted the old text as saying that only the pointer and the length are copied. Add a clause so it is more clear that the pointed to contents are also copied.
2022-08-22Move error trait into coreJane Losare-Lusby-0/+306
2022-08-20Improve primitive/std docs separation and headersCameron Steffen-1/+1
2022-07-21Box::from(slice): Clarify that contents are copiedAlan Wu-1/+1
A colleague mentioned that they interpreted the old text as saying that only the pointer and the length are copied. Add a clause so it is more clear that the pointed to contents are also copied.
2022-07-15add `#[must_use]` to `Box::from_raw`rhysd-0/+1
2022-07-01update cfg(bootstrap)sPietro Albini-21/+4
2022-06-02Rollup merge of #97655 - steffahn:better-pin-box-construction-docs, r=thomccMatthias Krüger-4/+28
Improve documentation for constructors of pinned `Box`es Adds a cross-references between `Box::pin` and `Box::into_pin` (and other related methods, i.e. the equivalent `From` implementation, and the unstable `pin_in` method), in particular now that `into_pin` [was stabilized](https://github.com/rust-lang/rust/pull/97397). The main goal is to further improve visibility of the fact that `Box<T> -> Pin<Box<T>>` conversion exits in the first place, and that `Box::pin(x)` is – essentially – just a convenience function for `Box::into_pin(Box::new(x))` The motivating context why I think this is important is even experienced Rust users overlooking the existence this kind of conversion, [e.g. in this thread on IRLO](https://internals.rust-lang.org/t/pre-rfc-function-variants/16732/7?u=steffahn); and also the fact that that discussion brought up that there would be a bunch of Box-construction methods "missing" such as e.g. methods with fallible allocation a la "`Box::try_pin`", and similar; while those are in fact *not* necessary, because you can use `Box::into_pin(Box::try_new(x)?)` instead. I have *not* included explicit mention of methods (e.g. `try_new`) in the docs of stable methods (e.g. `into_pin`). (Referring to unstable API in stable API docs would be bad style IMO.) Stable examples I have in mind with the statement "constructing a (pinned) Box in a different way than with `Box::new`" are things like cloning a `Box`, or `Box::from_raw`. If/when `try_new` would get stabilized, it would become a very good concrete example use-case of `Box::into_pin` IMO.
2022-06-02Improve documentation for constructors of pinned `Box`esFrank Steffahn-4/+28
2022-06-02Auto merge of #97293 - est31:remove_box, r=oli-obkbors-4/+26
Add #[rustc_box] and use it inside alloc This commit adds an alternative content boxing syntax, and uses it inside alloc. ```Rust #![feature(box_syntax)] fn foo() { let foo = box bar; } ``` is equivalent to ```Rust #![feature(rustc_attrs)] fn foo() { let foo = #[rustc_box] Box::new(bar); } ``` The usage inside the very performance relevant code in liballoc is the only remaining relevant usage of box syntax in the compiler (outside of tests, which are comparatively easy to port). box syntax was originally designed to be used by all Rust developers. This introduces a replacement syntax more tailored to only being used inside the Rust compiler, and with it, lays the groundwork for eventually removing box syntax. [Earlier work](https://github.com/rust-lang/rust/pull/87781#issuecomment-894714878) by `@nbdd0121` to lower `Box::new` to `box` during THIR -> MIR building ran into borrow checker problems, requiring the lowering to be adjusted in a way that led to [performance regressions](https://github.com/rust-lang/rust/pull/87781#issuecomment-894872367). The proposed change in this PR lowers `#[rustc_box] Box::new` -> `box` in the AST -> HIR lowering step, which is way earlier in the compiler, and thus should cause less issues both performance wise as well as regarding type inference/borrow checking/etc. Hopefully, future work can move the lowering further back in the compiler, as long as there are no performance regressions.
2022-06-02Stabilize `box_into_pin`Yuki Okushi-2/+21
2022-06-01Use #[rustc_box] in alloc instead of box syntaxest31-4/+26
2022-05-30Fix typo uniqeness -> uniquenessDavid Tolnay-1/+1
2022-05-26Document the current aliasing rules for `Box<T>`.Nilstrieb-0/+14
Currently, `Box<T>` gets `noalias`, meaning it has the same rules as `&mut T`. This is sparsely documented, even though it can have quite a big impact on unsafe code using box. Therefore, these rules are documented here, with a big warning that they are not normative and subject to change, since we have not yet committed to an aliasing model and the state of `Box<T>` is especially uncertain.
2022-05-06Add a dedicated length-prefixing method to `Hasher`Scott McMurray-0/+6
This accomplishes two main goals: - Make it clear who is responsible for prefix-freedom, including how they should do it - Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.
2022-04-11impl const Default for Box<[T]> and Box<str>Josh Stone-4/+12
2022-04-08Add ThinBox type for 1 stack pointer sized heap allocated trait objectsJane Lusby-0/+5
Relevant commit messages from squashed history in order: Add initial version of ThinBox update test to actually capture failure swap to middle ptr impl based on matthieu-m's design Fix stack overflow in debug impl The previous version would take a `&ThinBox<T>` and deref it once, which resulted in a no-op and the same type, which it would then print causing an endless recursion. I've switched to calling `deref` by name to let method resolution handle deref the correct number of times. I've also updated the Drop impl for good measure since it seemed like it could be falling prey to the same bug, and I'll be adding some tests to verify that the drop is happening correctly. add test to verify drop is behaving add doc examples and remove unnecessary Pointee bounds ThinBox: use NonNull ThinBox: tests for size Apply suggestions from code review Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> use handle_alloc_error and fix drop signature update niche and size tests add cfg for allocating APIs check null before calculating offset add test for zst and trial usage prevent optimizer induced ub in drop and cleanup metadata gathering account for arbitrary size and alignment metadata Thank you nika and thomcc! Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org> Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-04-05trivial cfg(bootstrap) changesPietro Albini-17/+9
2022-03-21Rename `~const Drop` to `~const Destruct`Deadbeef-10/+18
2022-03-10Rollup merge of #93950 - T-O-R-U-S:use-modern-formatting-for-format!-macros, ↵Dylan DPC-6/+6
r=Mark-Simulacrum Use modern formatting for format! macros This updates the standard library's documentation to use the new format_args syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored). `eprintln!("{}", e)` becomes `eprintln!("{e}")`, but `eprintln!("{}", e.kind())` remains untouched.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-6/+6
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-10Revert accidental stabilizationOli Scherer-2/+1
2022-02-03Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`.Charles Lew-3/+3
2022-01-04Add tracking issues (`const_box`, `const_alloc_error`)woppopo-22/+22
2021-12-23Constify `Box<T, A>` methodswoppopo-24/+68
2021-12-04Rollup merge of #90851 - ibraheemdev:downcast-unchecked, r=scottmcmMatthias Krüger-28/+109
Add unchecked downcast methods ```rust impl dyn Any (+ Send + Sync) { pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T; pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T; } impl<A: Allocator> Box<dyn Any (+ Send + Sync), A> { pub unsafe fn downcast_unchecked<T: Any>(&self) -> Box<T, A>; } ```
2021-12-03fix stability annotations for `Box::downcast`Ibraheem Ahmed-2/+2
2021-12-02Implement write() method for Box<MaybeUninit<T>>Martin Habovstiak-0/+36
This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in #63291 which this change extends.
2021-11-20fix doc links for `downcast_unchecked`Ibraheem Ahmed-0/+6
2021-11-12add tracking issue for `downcast_unchecked`Ibraheem Ahmed-3/+3
2021-11-12add unchecked downcast methodsIbraheem Ahmed-28/+103
2021-11-09document Box and box_free connectionasquared31415-0/+3
2021-10-10Add #[must_use] to alloc constructorsJohn Kugelman-0/+12
2021-10-09Remove unnecessary hyphenTim McNamara-1/+1
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-10-09Simplify wordingTim McNamara-4/+4
Co-authored-by: Josh Triplett <josh@joshtriplett.org> Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>