Commit Graph

111 Commits

Author SHA1 Message Date
Bugen Zhao c872ccc510 delegate box error provide
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
2023-10-31 16:35:59 +08:00
Gimbles 695beca219 Update boxed.rs 2023-10-21 23:41:32 +05:30
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer 60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Ralf Jung f2172ea4e2 avoid transmuting Box when we can just cast raw pointers instead 2023-08-14 10:15:25 +02:00
Amanieu d'Antras d24be14276 Eliminate ZST allocations in Box and Vec 2023-07-13 15:00:53 +01:00
DrMeepster a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Jules Bertholet 18d2c60975 cfg-gate BoxFromSlice trait
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2023-04-29 18:10:10 -04:00
Jules Bertholet 075ee26b68 Loosen From<&[T]> for Box<[T]> bound to T: Clone 2023-04-26 23:41:07 -04:00
Deadbeef 4ecbd3be52 fix alloc 2023-04-16 07:21:33 +00:00
Deadbeef 76dbe29104 rm const traits in libcore 2023-04-16 06:49:27 +00:00
KaDiWa ad2b34d0e3 remove some unneeded imports 2023-04-12 19:27:18 +02:00
Jubilee Young e34ad76363 Remove ~const from alloc 2023-03-28 10:37:16 -07:00
Maybe Waffle 9ac0da8f39 Make unused_allocation lint warn against Box::new 2023-03-03 12:02:55 +00:00
Ben Kimock 5448123a11 Remove or justify use of #[rustc_box] 2023-02-27 20:54:55 -05:00
Pietro Albini 11191279b7 Update bootstrap cfg 2022-12-28 09:18:43 -05:00
fee1-dead 58233e90b8 Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errors
Fix `unused_must_use` warning for `Box::from_raw`
2022-12-28 15:51:39 +08:00
Anders Kaseorg 8c73ce6611 Update coerce_unsized tracking issue from #27732 to #18598
Issue #27732 was closed as a duplicate of #18598.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-12-19 23:09:47 -08:00
Manish Goregaokar 2f8dbe3797 Rollup merge of #101655 - dns2utf8:box_docs, r=dtolnay
Make the Box one-liner more descriptive

I would like to avoid a definition that relies on itself.

r? `@GuillaumeGomez`
2022-11-22 01:26:06 -05:00
David Tolnay 70cee5af4b Touch up Box<T> one-liner 2022-11-21 15:28:41 -08:00
Mark Rousskov 455a7bc685 Bump version placeholders to release 2022-11-06 17:11:02 -05:00
Anett Seeker 3b8b0ac62a Fix unused_must_use warning for Box::from_raw 2022-11-05 21:52:18 +01:00
Michael Goulet 2786acce98 Enforce Tuple trait on Fn traits 2022-11-05 17:34:47 +00:00
bors 06f049a355 Auto merge of #101837 - scottmcm:box-array-from-vec, r=m-ou-se
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-10-17 19:46:04 +00:00
Pietro Albini 3975d55d98 remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Scott McMurray 4d3a31caf0 Add Box<[T; N]>: TryFrom<Vec<T>>
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-17 14:15:37 -07:00
Deadbeef 5a6273e263 Do not implement Unpin as const 2022-09-16 11:48:42 +08:00
Stefan Schindler f613bd6d3a Make the one-liner more descriptive 2022-09-10 16:24:05 +02:00
Matthias Krüger 65820098b9 Rollup merge of #99570 - XrXr:box-from-slice-docs, r=thomcc
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-28 09:35:13 +02:00
Jane Losare-Lusby bf7611d55e Move error trait into core 2022-08-22 13:28:25 -07:00
Cameron Steffen 17ddcb434b Improve primitive/std docs separation and headers 2022-08-20 16:50:29 -05:00
Alan Wu 321419ec42 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-07-21 13:15:29 -04:00
rhysd fa3156ec42 add #[must_use] to Box::from_raw 2022-07-15 17:05:50 +09:00
Pietro Albini 6b2d3d5f3c update cfg(bootstrap)s 2022-07-01 15:48:23 +02:00
Matthias Krüger 5b64aab2b6 Rollup merge of #97655 - steffahn:better-pin-box-construction-docs, r=thomcc
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-02 23:39:07 +02:00
Frank Steffahn 6e2ac5df31 Improve documentation for constructors of pinned Boxes 2022-06-02 15:32:48 +02:00
bors 20976bae5c Auto merge of #97293 - est31:remove_box, r=oli-obk
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-02 13:20:19 +00:00
Yuki Okushi 572c39000b Stabilize box_into_pin 2022-06-02 07:24:14 +09:00
est31 535e28b6c6 Use #[rustc_box] in alloc instead of box syntax 2022-06-01 02:28:34 +02:00
David Tolnay ffd7f5873e Fix typo uniqeness -> uniqueness 2022-05-30 16:49:28 -07:00
Nilstrieb e7c468dc59 Document the current aliasing rules for Box<T>.
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-26 21:28:07 +02:00
Scott McMurray 98054377ee Add a dedicated length-prefixing method to Hasher
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-05-06 00:03:38 -07:00
Josh Stone a2902ebe57 impl const Default for Box<[T]> and Box<str> 2022-04-11 12:14:18 -07:00
Jane Lusby a87a0d089e Add ThinBox type for 1 stack pointer sized heap allocated trait objects
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-08 09:00:16 -07:00
Pietro Albini 181d28bb61 trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
Deadbeef 1f3ee7f32e Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
Dylan DPC 5a7f09d9a3 Rollup merge of #93950 - T-O-R-U-S:use-modern-formatting-for-format!-macros, 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-10 23:12:57 +01:00
T-O-R-U-S 72a25d05bf Use implicit capture syntax in format_args
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-10 10:23:40 -05:00
Oli Scherer 5f7ca55df6 Revert accidental stabilization 2022-03-10 14:36:51 +00:00
Charles Lew 18130a21dc Move {core,std}::stream::Stream to {core,std}::async_iter::AsyncIterator. 2022-02-03 21:03:06 +08:00