about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-05-22Rollup merge of #111810 - compiler-errors:less-macro, r=thomccMatthias Krüger-18/+8
Don't use inner macro in `marker_impls` Just recurse instead of having to define an inner macro to avoid the problem with expansion binders being misnumbered between the `$meta` and `$T` variables. cc `@Veykril` this should fix rust-lang/rust-analyzer#14862 since we've gotten rid of the inner macro.
2023-05-22Auto merge of #111781 - the8472:filter-map-chunk, r=thomccbors-3/+160
optimize next_chunk impls for Filter and FilterMap ``` OLD: benchmarks: iter::bench_next_chunk_filter_even 104.00ns/iter +/- 1.00ns iter::bench_next_chunk_filter_map_even 101.00ns/iter +/- 1.00ns iter::bench_next_chunk_filter_map_mostly_false 1.99µs/iter +/- 10.00ns iter::bench_next_chunk_filter_map_predictably_true 56.00ns/iter +/- 0.00ns iter::bench_next_chunk_filter_mostly_false 1.15µs/iter +/- 6.00ns iter::bench_next_chunk_filter_predictably_true 65.00ns/iter +/- 1.00ns NEW: benchmarks: iter::bench_next_chunk_filter_even 42.00ns/iter +/- 0.00ns iter::bench_next_chunk_filter_map_even 49.00ns/iter +/- 1.00ns iter::bench_next_chunk_filter_map_mostly_false 501.00ns/iter +/- 3.00ns iter::bench_next_chunk_filter_map_predictably_true 31.00ns/iter +/- 0.00ns iter::bench_next_chunk_filter_mostly_false 534.00ns/iter +/- 13.00ns iter::bench_next_chunk_filter_predictably_true 28.00ns/iter +/- 1.00ns ```
2023-05-21drop_in_place docs: remove pseudocode-ish implementation detailsErik Desjardins-15/+1
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-1/+1
2023-05-21Don't use inner macro in marker_implsMichael Goulet-18/+8
2023-05-21Auto merge of #111696 - lukas-code:offset-of-erase-regions-harder, ↵bors-0/+5
r=compiler-errors don't skip inference for type in `offset_of!` Fixes https://github.com/rust-lang/rust/issues/111678 by no longer skipping inference on the type in `offset_of!`. Simply erasing the regions the during writeback isn't enough and can cause ICEs. A test case for this is included. This reverts https://github.com/rust-lang/rust/pull/111661, because it becomes redundant, since inference already erases the regions.
2023-05-20improve drop_in_place docsErik Desjardins-4/+6
2023-05-20Add missing "unsafe" to fix doctestPatrick Walton-1/+1
2023-05-20Update documentation for `drop_in_place()`Patrick Walton-6/+24
2023-05-20Auto merge of #111646 - Voultapher:restore-branchless-code-gen-for-merge, ↵bors-26/+12
r=cuviper Use code with reliable branchless code-gen for slice::sort merge The recent LLVM 16 update changes code-gen to be not branchless anymore, in the slice::sort implementation merge function. This improves performance by 30% for random patterns, restoring the performance to the state with LLVM 15. Fixes #111559
2023-05-20don't skip inference for type in `offset_of!`Lukas Markeffsky-0/+5
2023-05-20Auto merge of #111778 - Dylan-DPC:rollup-107ig9h, r=Dylan-DPCbors-1/+16
Rollup of 10 pull requests Successful merges: - #111491 (Dont check `must_use` on nested `impl Future` from fn) - #111606 (very minor cleanups) - #111619 (Add timings for MIR passes to profiling report) - #111652 (Better diagnostic for `use Self::..`) - #111665 (Add more tests for the offset_of macro) - #111708 (Give a more useful location for where a span_bug was delayed) - #111715 (Fix doc comment for `ConstParamTy` derive) - #111723 (style: do not overwrite obligations) - #111743 (Improve cgu merging debug output) - #111762 (fix: emit error when fragment is `MethodReceiverExpr` and items is empty) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-20optimize next_chunk impls for Filter and FilterMapThe 8472-3/+160
2023-05-20Rollup merge of #111715 - juntyr:const-param-ty-derive-fix, r=NilstriebDylan DPC-1/+1
Fix doc comment for `ConstParamTy` derive See https://github.com/rust-lang/rust/pull/111670#discussion_r1196453888 Thanks ````@Nilstrieb```` for the pointer :)
2023-05-20Rollup merge of #111665 - est31:offset_of_tests, r=WaffleLapkinDylan DPC-0/+15
Add more tests for the offset_of macro Implements what I [suggested in the tracking issue](https://github.com/rust-lang/rust/issues/106655#issuecomment-1535007205), plus some further improvements: * ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check r? `````@WaffleLapkin`````
2023-05-20Auto merge of #111524 - scottmcm:escape-using-ascii, r=cuviperbors-50/+65
`ascii::Char`-ify the escaping code in `core` This means that `EscapeIterInner::as_str` no longer needs unsafe code, because the type system ensures the internal buffer is only ASCII, and thus valid UTF-8. Come to think of it, this also gives it a (non-guaranteed) niche. cc `@BurntSushi` as potentially interested `ascii::Char` tracking issue: #110998
2023-05-19Auto merge of #111453 - scottmcm:constify-as-slice, r=Mark-Simulacrumbors-6/+6
constify `slice_as_chunks` (unstable) Tracking issue: #74985 Nothing complicated required; just adding `const` to the declarations.
2023-05-19Add slice::{split_,}{first,last}_chunk{,_mut}ltdk-0/+258
2023-05-19tidyIbraheem Ahmed-2/+1
2023-05-19remove unstable `Poll::ready`Ibraheem Ahmed-94/+3
2023-05-19constify `slice_as_chunks` (unstable)Scott McMurray-6/+6
Tracking issue: 74985 Nothing complicated required; just adding `const` to the declarations.
2023-05-19Auto merge of #111590 - dtolnay:panictemporaries, r=bjorn3bors-12/+12
Shorten even more panic temporary lifetimes Followup to #104134. As pointed out by `@bjorn3` in https://github.com/rust-lang/rust/pull/104134#pullrequestreview-1425585948, there are other cases in the panic macros which would also benefit from dropping their non-Send temporaries as soon as possible, avoiding pointlessly holding them across an await point. For the tests added in this PR, here are the failures you get today on master without the macro changes in this PR: <details> <summary>tests/ui/macros/panic-temporaries-2018.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:52:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:53:18 | LL | require_send(panic_str()); | ^^^^^^^^^^^ future returned by `panic_str` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:40:36 | LL | f(panic!((NOT_SEND, "...").1)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries-2018.rs:54:18 | LL | require_send(unreachable_display()); | ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries-2018.rs:45:31 | LL | f(unreachable!(NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries-2018.rs:48:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 5 previous errors ``` </details> <details> <summary>tests/ui/macros/panic-temporaries.rs</summary> ```console error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | -------- ^^^^^- `NOT_SEND` is later dropped here | | | | | await occurs here, with `NOT_SEND` maybe used later | has type `NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: future cannot be sent between threads safely --> tests/ui/macros/panic-temporaries.rs:42:18 | LL | require_send(panic_display()); | ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send` | = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8` note: future is not `Send` as this value is used across an await --> tests/ui/macros/panic-temporaries.rs:35:31 | LL | f(panic!("{}", NOT_SEND)).await; | ---------------------- ^^^^^- the value is later dropped here | | | | | await occurs here, with the value maybe used later | has type `&NotSend` which is not `Send` note: required by a bound in `require_send` --> tests/ui/macros/panic-temporaries.rs:38:25 | LL | fn require_send(_: impl Send) {} | ^^^^ required by this bound in `require_send` error: aborting due to 2 previous errors ``` </details> r? bjorn3
2023-05-18Option::map_or_else: Show an example of integrating with ResultColin Walters-1/+20
Moving this from https://github.com/rust-lang/libs-team/issues/59 where an API addition was rejected. But I think it's valuable to add this example to the documentation at least.
2023-05-18Add more tests for the offset_of!() macroest31-0/+15
* ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious descision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check
2023-05-18Fix doc comment for `ConstParamTy` deriveJuniper Tyree-1/+1
See https://github.com/rust-lang/rust/pull/111670#discussion_r1196453888 Thanks @Nilstrieb for the pointer :)
2023-05-18Document `Pin` memory layoutJules Bertholet-0/+2
2023-05-17Rollup merge of #111654 - JoJoJet:unsafe-cell-from-mut-lib, r=joshtriplettDylan DPC-0/+21
Add a conversion from `&mut T` to `&mut UnsafeCell<T>` Provides a safe way of downgrading an exclusive reference into an alias-able `&UnsafeCell<T>` reference. ACP: https://github.com/rust-lang/libs-team/issues/198.
2023-05-17Rollup merge of #111649 - Nilstrieb:derive-const-param-ty, r=BoxyUwUDylan DPC-0/+8
Add derive for `core::marker::ConstParamTy` This makes it easier to implement it for a type, just like `Copy`. `@BoxyUwU` half asked me to add it
2023-05-17Rollup merge of #111043 - jmillikin:cstr-is-empty, r=dtolnayDylan DPC-3/+2
Stabilize feature `cstr_is_empty` Fixes #102444 ACP: https://github.com/rust-lang/libs-team/issues/106
2023-05-16add `UnsafeCell::from_mut`JoJoJet-0/+21
2023-05-16Add derive for `core::marker::ConstParamTy`Nilstrieb-0/+8
This makes it easier to implement it for a type, just like `Copy`.
2023-05-16Hide repr attribute from doc of types without guaranteed reprDavid Tolnay-9/+9
2023-05-16Use code with reliable branchless code-gen for slice::sort mergeLukas Bergdoll-26/+12
The recent LLVM 16 update changes code-gen to be not branchless anymore, in the slice::sort implementation merge function. This improves performance by 30% for random patterns, restoring the performance to the state with LLVM 15.
2023-05-16Auto merge of #111044 - jmillikin:nonzero-negation, r=dtolnaybors-18/+12
Stabilize feature `nonzero_negation_ops` Fixes #102443 ACP: https://github.com/rust-lang/libs-team/issues/105
2023-05-15Mark internal functions and traits unsafeLegionMammal978-24/+45
2023-05-15Give better error when collecting into `&[T]`Chayim Refael Friedman-0/+10
2023-05-15Rollup merge of #111587 - cbeuw:copy-for-deref, r=oli-obkMatthias Krüger-1/+2
Custom MIR: Support `Rvalue::CopyForDeref` r? `@oli-obk` or `@tmiasko` or `@JakobDegen`
2023-05-15Rollup merge of #108356 - gftea:master, r=workingjubileeMatthias Krüger-1/+3
improve doc test for UnsafeCell::raw_get improve docs of public API `UnsafeCell::raw_get`
2023-05-15Rollup merge of #108291 - chenyukang:yukang/fix-benchmarks, r=workingjubileeMatthias Krüger-30/+30
Fix more benchmark test with black_box Follow up fix for https://github.com/rust-lang/rust/issues/107590
2023-05-15Shorten lifetime of even more panic temporariesDavid Tolnay-12/+12
2023-05-15DocumentationAndy Wang-1/+1
2023-05-15Add CopyForDeref to custom MIRAndy Wang-0/+1
2023-05-15Rollup merge of #111581 - scottmcm:fix-pattern-comment, r=workingjubileeMatthias Krüger-4/+4
Fix some misleading and copy-pasted `Pattern` examples These examples were listed twice and also were confusable with doing a substring match instead of a any-of-set match.
2023-05-15Rollup merge of #102673 - lukas-code:infered-lifetimes, r=ehussMatthias Krüger-1/+1
Update doc for `PhantomData` to match code example After https://github.com/rust-lang/rust/pull/106621, there is no longer a `T: 'a` annotation in the doc example, so update the text to match the code.
2023-05-14Fix some misleading and copy-pasted `Pattern` examplesScott McMurray-4/+4
These examples were listed twice and also were confusable with doing a substring match instead of a any-of-set match.
2023-05-15Auto merge of #108273 - tspiteri:const_slice_split_at_not_mut, r=dtolnaybors-1/+2
Stabilize const slice::split_at This stabilizes the use of the following method in const context: ```rust impl<T> [T] { pub const fn split_at(&self, mid: usize) -> (&[T], &[T]); } ``` cc tracking issue #101158
2023-05-14Auto merge of #92048 - Urgau:num-midpoint, r=scottmcmbors-3/+313
Add midpoint function for all integers and floating numbers This pull-request adds the `midpoint` function to `{u,i}{8,16,32,64,128,size}`, `NonZeroU{8,16,32,64,size}` and `f{32,64}`. This new function is analog to the [C++ midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) function, and basically compute `(a + b) / 2` with a rounding towards ~~`a`~~ negative infinity in the case of integers. Or simply said: `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a sufficiently-large signed integral type. Note that unlike the C++ function this pull-request does not implement this function on pointers (`*const T` or `*mut T`). This could be implemented in a future pull-request if desire. ### Implementation For `f32` and `f64` the implementation in based on the `libcxx` [one](https://github.com/llvm/llvm-project/blob/18ab892ff7e9032914ff7fdb07685d5945c84fef/libcxx/include/__numeric/midpoint.h#L65-L77). I originally tried many different approach but all of them failed or lead me with a poor version of the `libcxx`. Note that `libstdc++` has a very similar one; Microsoft STL implementation is also basically the same as `libcxx`. It unfortunately doesn't seems like a better way exist. For unsigned integers I created the macro `midpoint_impl!`, this macro has two branches: - The first one take `$SelfT` and is used when there is no unsigned integer with at least the double of bits. The code simply use this formula `a + (b - a) / 2` with the arguments in the correct order and signs to have the good rounding. - The second branch is used when a `$WideT` (at least double of bits as `$SelfT`) is provided, using a wider number means that no overflow can occur, this greatly improve the codegen (no branch and less instructions). For signed integers the code basically forwards the signed numbers to the unsigned version of midpoint by mapping the signed numbers to their unsigned numbers (`ex: i8 [-128; 127] to [0; 255]`) and vice versa. I originally created a version that worked directly on the signed numbers but the code was "ugly" and not understandable. Despite this mapping "overhead" the codegen is better than my most optimized version on signed integers. ~~Note that in the case of unsigned numbers I tried to be smart and used `#[cfg(target_pointer_width = "64")]` to determine if using the wide version was better or not by looking at the assembly on godbolt. This was applied to `u32`, `u64` and `usize` and doesn't change the behavior only the assembly code generated.~~
2023-05-14explain that `PhantomData<&'a T>` infers `T: 'a`Lukas Markeffsky-1/+1
2023-05-14Shorten lifetime of panic temporaries in panic_fmt caseDavid Tolnay-6/+10
2023-05-14Auto merge of #111425 - Bryanskiy:privacy_ef, r=petrochenkovbors-0/+6
Populate effective visibilities in `rustc_privacy` (take 2) Same as https://github.com/rust-lang/rust/pull/110907 + regressions fixes. Fixes https://github.com/rust-lang/rust/issues/111359. r? `@petrochenkov`