-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize slice_first_last_chunk
#117561
Stabilize slice_first_last_chunk
#117561
Conversation
These methods currently return `(last_chunk, preceding_slice)`, which matches the existing `split_x` methods that remove one item. Change these to instead return `(preceding_slice, last_chunk)` which matches string split methods, should be more intuitive, and will allow for consistency with methods that split more items.
Clarify that these functions return array references. Also change from doing `as` casting to using the less misuseable `.cast()`.
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
I'm fine with reversing the order, although it is quite unfortunate that |
I completely agree :( I think it's better to embrace the consistency with other ordered splitting things and probably the path we would prefer to keep in the future, but it is unfortunate that the inconsistency is with such a similarly named method. |
r? libs-api |
Is it possible to stabilize these in a way that keeps the door open for infallible counterparts on arrays (once |
That sounds reasonable. If we are happy with these names, I can just adjust the items from Although on second thought... I'm not sure the first_chunk / last_chunk names work quite as well when you wind up with two "chunks" (meaning array), rather than one chunk and one slice. Something to think about I suppose |
And it's more likely that if you do |
[`split_first_chunk`][0] is a nightly only builtin. It looks like it will be [stabillized soon][1], so I decided to use it and copy over the implementation in the meantime. Amusingly, benchmark show a consistent 3% improvement to throughput compared to using `get_split`. [0]: https://doc.rust-lang.org/std/primitive.slice.html#method.split_first_chunk [1]: rust-lang/rust#117561
The functionality of these methods from `split_array` has been absorbed by the `slice_first_last_chunk` feature. This only affects the methods on slices, not those with the same name that are implemented on array types. Also adjusts testing to reflect this change.
a096e5f
to
560f158
Compare
@joshtriplett would you be able to review this? |
We discussed this in today's libs-api meeting, and agreed that we want to do the proposed stabilizations and changes: @rfcbot merge |
This comment was marked as outdated.
This comment was marked as outdated.
This stabilizes all methods under `slice_first_last_chunk`. Additionally, it const stabilizes the non-mut functions and moves the `_mut` functions under `const_slice_first_last_chunk`. These are blocked on `const_mut_refs`. As part of this change, `slice_split_at_unchecked` was marked const-stable for internal use (but not fully stable).
Thanks Ralf, that seems to have worked 500d6f6 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
🎉 🚀 @bors r+ |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#117561 (Stabilize `slice_first_last_chunk`) - rust-lang#117662 ([rustdoc] Allows links in headings) - rust-lang#119815 (Format sources into the error message when loading codegen backends) - rust-lang#119835 (Exhaustiveness: simplify empty pattern logic) - rust-lang#119984 (Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.) - rust-lang#120009 (never_patterns: typecheck never patterns) - rust-lang#120122 (Don't add needs-triage to A-diagnostics) - rust-lang#120126 (Suggest `.swap()` when encountering conflicting borrows from `mem::swap` on a slice) - rust-lang#120134 (Restrict access to the private field of newtype indexes) Failed merges: - rust-lang#119968 (Remove unused/unnecessary features) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#117561 (Stabilize `slice_first_last_chunk`) - rust-lang#117662 ([rustdoc] Allows links in headings) - rust-lang#119815 (Format sources into the error message when loading codegen backends) - rust-lang#119835 (Exhaustiveness: simplify empty pattern logic) - rust-lang#119984 (Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.) - rust-lang#120009 (never_patterns: typecheck never patterns) - rust-lang#120122 (Don't add needs-triage to A-diagnostics) - rust-lang#120126 (Suggest `.swap()` when encountering conflicting borrows from `mem::swap` on a slice) - rust-lang#120134 (Restrict access to the private field of newtype indexes) Failed merges: - rust-lang#119968 (Remove unused/unnecessary features) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117561 - tgross35:split-array, r=scottmcm Stabilize `slice_first_last_chunk` This PR does a few different things based around stabilizing `slice_first_last_chunk`. They are split up so this PR can be by-commit reviewed, I can move parts to a separate PR if desired. This feature provides a very elegant API to extract arrays from either end of a slice, such as for parsing integers from binary data. ## Stabilize `slice_first_last_chunk` ACP: rust-lang/libs-team#69 Implementation: rust-lang#90091 Tracking issue: rust-lang#111774 This stabilizes the functionality from rust-lang#111774: ```rust impl [T] { pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>; pub fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>; pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])>; pub fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T], &mut [T; N])>; } ``` Const stabilization is included for all non-mut methods, which are blocked on `const_mut_refs`. This change includes marking the trivial function `slice_split_at_unchecked` const-stable for internal use (but not fully stable). ## Remove `split_array` slice methods Tracking issue: rust-lang#90091 Implementation: rust-lang#83233 (review) This PR also removes the following unstable methods from the `split_array` feature, rust-lang#90091: ```rust impl<T> [T] { pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]); pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]); pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]); pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]); } ``` This is done because discussion at rust-lang#90091 and its implementation PR indicate a strong preference for nonpanicking APIs that return `Option`. The only difference between functions under the `split_array` and `slice_first_last_chunk` features is `Option` vs. panic, so remove the duplicates as part of this stabilization. This does not affect the array methods from `split_array`. We will want to revisit these once `generic_const_exprs` is further along. ## Reverse order of return tuple for `split_last_chunk{,_mut}` An unresolved question for rust-lang#111774 is whether to return `(preceding_slice, last_chunk)` (`(&[T], &[T; N])`) or the reverse (`(&[T; N], &[T])`), from `split_last_chunk` and `split_last_chunk_mut`. It is currently implemented as `(last_chunk, preceding_slice)` which matches `split_last -> (&T, &[T])`. The first commit changes these to `(&[T], &[T; N])` for these reasons: - More consistent with other splitting methods that return multiple values: `str::rsplit_once`, `slice::split_at{,_mut}`, `slice::align_to` all return tuples with the items in order - More intuitive (arguably opinion, but it is consistent with other language elements like pattern matching `let [a, b, rest @ ..] ...` - If we ever added a varidic way to obtain multiple chunks, it would likely return something in order: `.split_many_last::<(2, 4)>() -> (&[T], &[T; 2], &[T; 4])` - It is the ordering used in the `rsplit_array` methods I think the inconsistency with `split_last` could be acceptable in this case, since for `split_last` the scalar `&T` doesn't have any internal order to maintain with the other items. ## Unresolved questions Do we want to reserve the same names on `[u8; N]` to avoid inference confusion? rust-lang#117561 (comment) --- `slice_first_last_chunk` has only been around since early 2023, but `split_array` has been around since 2021. `@rustbot` label -T-libs +T-libs-api -T-libs +needs-fcp cc `@rust-lang/wg-const-eval,` `@scottmcm` who raised this topic, `@clarfonthey` implementer of `slice_first_last_chunk` `@jethrogb` implementer of `split_array` Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Stabilizing.20array-from-slice.20*something*.3F Fixes: rust-lang#111774
Stabilize `slice_first_last_chunk` This PR does a few different things based around stabilizing `slice_first_last_chunk`. They are split up so this PR can be by-commit reviewed, I can move parts to a separate PR if desired. This feature provides a very elegant API to extract arrays from either end of a slice, such as for parsing integers from binary data. ## Stabilize `slice_first_last_chunk` ACP: rust-lang/libs-team#69 Implementation: rust-lang/rust#90091 Tracking issue: rust-lang/rust#111774 This stabilizes the functionality from rust-lang/rust#111774: ```rust impl [T] { pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>; pub fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>; pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])>; pub fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T], &mut [T; N])>; } ``` Const stabilization is included for all non-mut methods, which are blocked on `const_mut_refs`. This change includes marking the trivial function `slice_split_at_unchecked` const-stable for internal use (but not fully stable). ## Remove `split_array` slice methods Tracking issue: rust-lang/rust#90091 Implementation: rust-lang/rust#83233 (review) This PR also removes the following unstable methods from the `split_array` feature, rust-lang/rust#90091: ```rust impl<T> [T] { pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]); pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]); pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]); pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]); } ``` This is done because discussion at #90091 and its implementation PR indicate a strong preference for nonpanicking APIs that return `Option`. The only difference between functions under the `split_array` and `slice_first_last_chunk` features is `Option` vs. panic, so remove the duplicates as part of this stabilization. This does not affect the array methods from `split_array`. We will want to revisit these once `generic_const_exprs` is further along. ## Reverse order of return tuple for `split_last_chunk{,_mut}` An unresolved question for #111774 is whether to return `(preceding_slice, last_chunk)` (`(&[T], &[T; N])`) or the reverse (`(&[T; N], &[T])`), from `split_last_chunk` and `split_last_chunk_mut`. It is currently implemented as `(last_chunk, preceding_slice)` which matches `split_last -> (&T, &[T])`. The first commit changes these to `(&[T], &[T; N])` for these reasons: - More consistent with other splitting methods that return multiple values: `str::rsplit_once`, `slice::split_at{,_mut}`, `slice::align_to` all return tuples with the items in order - More intuitive (arguably opinion, but it is consistent with other language elements like pattern matching `let [a, b, rest @ ..] ...` - If we ever added a varidic way to obtain multiple chunks, it would likely return something in order: `.split_many_last::<(2, 4)>() -> (&[T], &[T; 2], &[T; 4])` - It is the ordering used in the `rsplit_array` methods I think the inconsistency with `split_last` could be acceptable in this case, since for `split_last` the scalar `&T` doesn't have any internal order to maintain with the other items. ## Unresolved questions Do we want to reserve the same names on `[u8; N]` to avoid inference confusion? rust-lang/rust#117561 (comment) --- `slice_first_last_chunk` has only been around since early 2023, but `split_array` has been around since 2021. `@rustbot` label -T-libs +T-libs-api -T-libs +needs-fcp cc `@rust-lang/wg-const-eval,` `@scottmcm` who raised this topic, `@clarfonthey` implementer of `slice_first_last_chunk` `@jethrogb` implementer of `split_array` Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Stabilizing.20array-from-slice.20*something*.3F Fixes: #111774
`<[T]>::last_chunk` should have become const stable as part of <rust-lang#117561>. Update the const stability gate to reflect this.
…urntSushi Correct the const stabilization of `last_chunk` for slices `<[T]>::last_chunk` should have become const stable as part of <rust-lang#117561>. Update the const stability gate to reflect this.
reorganised attrs removed OsStr impls added backticks Add note about possible allocation-sharing to Arc/Rc<str/[T]/CStr>::default. Use shared statics for the ArcInner for Arc<str, CStr>::default, and for Arc<[T]>::default where alignof(T) <= 16. fixed unsafe block Revert "fixed unsafe block" This reverts commit 6eb6aee. Return coherent description for boolean instead of panicking Improve check-cfg CLI errors with more structured diagnostics Move various stdlib tests to library/std/tests Run tidy on tests Rename test for issue 21058 Implement `edition` method on `Rustdoc` type as well Migrate `run-make/doctests-runtool` to rmake Rename `run-make-support` library `output` method to `command_output` Add new `output` method to `Rustc` and `Rustdoc` types Migrate `run-make/rustdoc-error-lines` to `rmake.rs` add f16 associated constants NaN and infinity are not included as they require arithmetic. add f128 associated constants NaN and infinity are not included as they require arithmetic. add constants in std::f16::consts add constants in std::f128::consts update error messages in ui tests Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times Also mention that there might be leftover directories in the error case. Prefer lower vtable candidates in select in new solver Don't consider candidates with no failing where clauses Use super_fold in RegionsToStatic visitor Make check-cfg docs more user-friendly Record impl args in the InsepctCandiate rather than rematching during select Use correct ImplSource for alias bounds BorrowckInferCtxt: infcx by value borrowck: more eagerly prepopulate opaques switch new solver to directly inject opaque types Update books Adjust dbg.value/dbg.declare checks for LLVM update llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example call void @llvm.dbg.declare(...) becomes #dbg_declare(...) Update tests accordingly to work with both the old and new way. Adjust 64-bit ARM data layouts for LLVM update LLVM has updated data layouts to specify `Fn32` on 64-bit ARM to avoid C++ accidentally underaligning functions when trying to comply with member function ABIs. This should only affect Rust in cases where we had a similar bug (I don't believe we have one), but our data layout must match to generate code. As a compatibility adaptatation, if LLVM is not version 19 yet, `Fn32` gets voided from the data layout. See llvm/llvm-project#90415 Update version of cc crate to v1.0.97 Reason: In order to build the Windows version of the Rust toolchain for the Android platform, the following patch to the cc is crate is required to avoid incorrectly determining that we are building with the Android NDK: rust-lang/cc-rs@57853c4 This patch is present in version 1.0.80 and newer versions of the cc crate. The rustc source distribution currently has 3 different versions of cc in the vendor directory, only one of which has the necessary fix. We (the Android Rust toolchain) are currently maintaining local patches to upgrade the cc crate dependency versions, which we would like to upstream. Furthermore, beyond the specific reason, the cc crate in bootstrap is currently pinned at an old version due to problems in the past when trying to update it. It is worthwhile to figure out and resolve these problems so we can keep the dependency up-to-date. Other fixes: As of cc v1.0.78, object files are prefixed with a 16-character hash. Update src/bootstrap/src/core/build_steps/llvm.rs to account for this to avoid failures when building libunwind and libcrt. Note that while the hash prefix was introduced in v1.0.78, in order to determine the names of the object files without scanning the directory, we rely on the compile_intermediates method, which was introduced in cc v1.0.86 As of cc v1.0.86, compilation on MacOS uses the -mmacosx-version-min flag. A long-standing bug in the CMake rules for compiler-rt causes compilation to fail when this flag is specified. So we add a workaround to suppress this flag. Updating to cc v1.0.91 and newer requires fixes to bootstrap unit tests. The unit tests use targets named "A", "B", etc., which fail a validation check introduced in 1.0.91 of the cc crate. Implement lldb formattter for "clang encoded" enums (LLDB 18.1+) Summary: I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information. This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way. I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums. Test Plan: ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode Other Thoughs A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now. f16::is_sign_{positive,negative} were feature-gated on f128 Correct the const stabilization of `last_chunk` for slices `<[T]>::last_chunk` should have become const stable as part of <rust-lang#117561>. Update the const stability gate to reflect this. Add tests Lower never patterns to Unreachable in mir rustdoc: dedup search form HTML This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because - the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank - it requires very little HTML, so it's a real win in size [parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token This shrinks the standard library by about 60MiB, by my test. rustdoc: allow custom element rustdoc-search generalize hr alias: avoid unconstrainable infer vars narrow down visibilities in `rustc_parse::lexer` replace another Option<Span> by DUMMY_SP Don't ICE when we cannot eval a const to a valtree in the new solver Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check` coverage: Add branch coverage support for let-else coverage: Add branch coverage support for if-let and let-chains Do not ICE on foreign malformed `diagnostic::on_unimplemented` Fix rust-lang#124651. Add test for rust-lang#124651 Update cargo compiler: Privatize `Parser::current_closure` This was added as pub in 2021 and remains only privately used in 2024! compiler: derive Debug in parser It's annoying to debug the parser if you have to stop every five seconds to add a Debug impl. compiler: add `Parser::debug_lookahead` I tried debugging a parser-related issue but found it annoying to not be able to easily peek into the Parser's token stream. Add a convenience fn that offers an opinionated view into the parser, but one that is useful for answering basic questions about parser state. Fuchsia test runner: fixup script This commit fixes several issues in the fuchsia-test-runner.py script: 1. Migrate from `pm` to `ffx` for package management, as `pm` is now deprecated. Furthermore, the `pm` calls used in this script no longer work at Fuchsia's HEAD. This is the largest change in this commit, and impacts all steps around repository management (creation and registration of the repo, as well as package publishing). 2. Allow for `libtest` to be either statically or dynamically linked. The script assumed it was dynamically linked, but the current Rust behavior at HEAD is to statically link it. 3. Minor cleanup to use `ffx --machine json` rather than string parsing. 4. Minor cleanup to the docs around the script. std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly. add note about `AlreadyExists` to `create_new` Apply suggestions from code review Co-authored-by: Jubilee <[email protected]> iOS/tvOS/watchOS/visionOS: Default to kernel-defined backlog in listen This behavior is defined in general for the XNU kernel, not just macOS: https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/kern/uipc_socket.c iOS/tvOS/watchOS/visionOS: Set the main thread name Tested in the iOS simulator that the thread name is not set by default, and that setting it improves the debugging experience in lldb / Xcode. iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions Tested on an old MacBook and the iOS simulator. iOS/tvOS/watchOS/visionOS: Fix reading large files Tested in the iOS simulator with something like: ``` let mut buf = vec![0; c_int::MAX as usize - 1 + 2]; let read_bytes = f.read(&mut buf).unwrap(); ``` iOS/tvOS/watchOS/visionOS: Improve File Debug impl This uses `libc::fcntl`, which, while not explicitly marked as available in the headers, is already used by `File::sync_all` and `File::sync_data` on these platforms, so should be fine to use here as well. next_power_of_two: add a doctest to show what happens on 0 rustc: Change LLVM target for the wasm32-wasip2 Rust target This commit changes the LLVM target of for the Rust `wasm32-wasip2` target to `wasm32-wasip2` as well. LLVM does a bit of detection on the target string to know when to call `wasm-component-ld` vs `wasm-ld` so otherwise clang is invoking the wrong linker. rustc: Don't pass `-fuse-ld=lld` on wasm targets This argument isn't necessary for WebAssembly targets since `wasm-ld` is the only linker for the targets. Passing it otherwise interferes with Clang's linker selection on `wasm32-wasip2` so avoid it altogether. rustc: Change wasm32-wasip2 to PIC-by-default This commit changes the new `wasm32-wasip2` target to being PIC by default rather than the previous non-PIC by default. This change is intended to make it easier for the standard library to be used in a shared object in its precompiled form. This comes with a hypothetical modest slowdown but it's expected that this is quite minor in most use cases or otherwise wasm compilers and/or optimizing runtimes can elide the cost. Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes an ICE that occurred when the struct in question has an error Fix insufficient logic when searching for the underlying allocation in the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts. rustdoc: use stability, instead of features, to decide what to show To decide if internal items should be inlined in a doc page, check if the crate is itself internal, rather than if it has the rustc_private feature flag. The standard library uses internal items, but is not itself internal and should not show internal items on its docs pages. Avoid a cast in `ptr::slice_from_raw_parts(_mut)` Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not. If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it. add enum variant field names to make the code clearer remove redundant flat vs nested distinction to simplify enum turn all_nested_unused into used_childs store the span of the nested part of the use tree in the ast remove braces when fixing a nested use tree into a single use Use generic `NonZero` in examples. Simplify `clippy` lint. Simplify suggestion. Use generic `NonZero`. crashes: add lastest batch of crash tests Make sure we don't deny macro vars w keyword names Simplify `use crate::rustc_foo::bar` occurrences. They can just be written as `use rustc_foo::bar`, which is far more standard. (I didn't even know that a `crate::` prefix was valid.) Update cc crate to v1.0.97 Ignore empty RUSTC_WRAPPER in bootstrap This change ignores the RUSTC_WRAPPER_REAL environment variable if it's set to the empty string. This matches cargo behaviour and allows users to easily shadow a globally set RUSTC_WRAPPER (which they might have set for non-rustc projects). Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes an ICE that occurred when the struct in question has an error Implement `as_chunks` with `split_at_unchecked` Remove `macro_use` from `stable_hasher`. Normal `use` items are nicer. Reorder top-level crate items. - `use` before `mod` - `pub` before `non-pub` - Alphabetical order within sections Remove `extern crate tracing`. `use` is a nicer way of doing things. Document `Pu128`. And move the `repr` line after the `derive` line, where it's harder to overlook. (I overlooked it initially, and didn't understand how this type worked.) Remove `TinyList`. It is optimized for lists with a single element, avoiding the need for an allocation in that case. But `SmallVec<[T; 1]>` also avoids the allocation, and is better in general: more standard, log2 number of allocations if the list exceeds one item, and a much more capable API. This commit removes `TinyList` and converts the two uses to `SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant file so they are in just two sections (`pub` and non-`pub`), ordered alphabetically, instead of many sections. (This is a relevant part of the change because I had to decide where to add a `use` item for `SmallVec`.) Remove `vec_linked_list`. It provides a way to effectively embed a linked list within an `IndexVec` and also iterate over that list. It's written in a very generic way, involving two traits `Links` and `LinkElem`. But the `Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the whole thing is only used in one module within `rustc_borrowck`. So I think it's over-engineered and hard to read. Plus it has no comments. This commit removes it, and adds a (non-generic) local iterator for the use within `rustc_borrowck`. Much simpler. Remove `enum_from_u32`. It's a macro that just creates an enum with a `from_u32` method. It has two arms. One is unused and the other has a single use. This commit inlines that single use and removes the whole macro. This increases readability because we don't have two different macros interacting (`enum_from_u32` and `language_item_table`). Update Tests Fix Error Messages for `break` Inside Coroutines Previously, `break` inside `gen` blocks and functions were incorrectly identified to be enclosed by a closure. This PR fixes it by displaying an appropriate error message for async blocks, async closures, async functions, gen blocks, gen closures, gen functions, async gen blocks, async gen closures and async gen functions. Note: gen closure and async gen closure are not supported by the compiler yet but I have added an error message here assuming that they might be implemented in the future. Also, fixes grammar in a few places by replacing `inside of a $coroutine` with `inside a $coroutine`. Migrate `run-make/rustdoc-map-file` to rmake Add more ICEs due to malformed diagnostic::on_unimplemented Fix ICEs in diagnostic::on_unimplemented Handle field projections like slice indexing in invalid_reference_casting Fix typos Do not add leading asterisk in the `PartialEq` Adding leading asterisk can cause compilation failure for the _types_ that don't implement the `Copy`. Use sum type for `WorkflowRunType` Parse try build CI job name from commit message Make the regex more robust Address review comments CI: fix auto builds and make sure that we always have at least a single CI job Include the line number in tidy's `iter_header` Tidy check for test revisions that are mentioned but not declared If a `[revision]` name appears in a test header directive or error annotation, but isn't declared in the `//@ revisions:` header, that is almost always a mistake. In cases where a revision needs to be temporarily disabled, adding it to an `//@ unused-revision-names:` header will suppress these checks for that name. Adding the wildcard name `*` to the unused list will suppress these checks for the entire file. Fix test problems discovered by the revision check Most of these changes either add revision names that were apparently missing, or explicitly mark a revision name as currently unused. fix rust-lang#124714 str.to_lowercase sigma handling Make a minimal amount of region APIs public Add `ErrorGuaranteed` to `Recovered::Yes` and use it more. The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error. interpret/miri: better errors on failing offset_from chore: remove repetitive words Make `#![feature]` suggestion MaybeIncorrect Update Makefiles with explanatory comments correct comments add FIXME Upgrade the version of Clang used in the build, move MSVC builds to Server 2022 Rename Generics::params to Generics::own_params Add benchmarks for `impl Debug for str` In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress `impl Debug for str`. Remove unused `step_trait` feature. Also sort the features. Remove unused `LinkSelfContainedDefault::is_linker_enabled` method. Correct a comment. I tried simplifying `RegionCtxt`, which led me to finding that the fields are printed in `sccs_info`. Fix up `DescriptionCtx::new`. The comment mentions that `ReBound` and `ReVar` aren't expected here. Experimentation with the full test suite indicates this is true, and that `ReErased` also doesn't occur. So the commit introduces `bug!` for those cases. (If any of them show up later on, at least we'll have a test case.) The commit also remove the first sentence in the comment. `RePlaceholder` is now handled in the match arm above this comment and nothing is printed for it, so that sentence is just wrong. Furthermore, issue rust-lang#13998 was closed some time ago. Fix out-of-date comment. The type name has changed. Remove `TyCtxt::try_normalize_erasing_late_bound_regions`. It's unused. Remove out-of-date comment. The use of `Binder` was removed in the recent rust-lang#123900, but the comment wasn't removed at the same time. De-tuple two `vtable_trait_first_method_offset` args. Thus eliminating a `FIXME` comment. opt-dist: use xz2 instead of xz crate xz crate consist of simple reexport of xz2 crate. Why? Idk. analyse visitor: build proof tree in probe update crashes always use `GenericArgsRef` Inline and remove unused methods. `InferCtxt::next_{ty,const,int,float}_var_id` each have a single call site, in `InferCtt::next_{ty,const,int,float}_var` respectively. The only remaining method that creates a var_id is `InferCtxt::next_ty_var_id_in_universe`, which has one use outside the crate. Use fewer origins when creating type variables. `InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements. print walltime benchmarks with subnanosecond precision example results when benchmarking 1-4 serialized ADD instructions ``` running 4 tests test add ... bench: 0.24 ns/iter (+/- 0.00) test add2 ... bench: 0.48 ns/iter (+/- 0.01) test add3 ... bench: 0.72 ns/iter (+/- 0.01) test add4 ... bench: 0.96 ns/iter (+/- 0.01) ``` emit fractional benchmark nanoseconds in libtest's JSON output format bootstrap should also render fractional nanoseconds for benchmarks from_str_radix: outline only the panic function codegen: memmove/memset cannot be non-temporal coverage: Separately compute the set of BCBs with counter mappings coverage: Make the special case for async functions exit early coverage: Don't recompute the number of test vector bitmap bytes The code in `extract_mcdc_mappings` that allocates these bytes already knows how many are needed in total, so there's no need to immediately recompute that value in the calling function. coverage: Destructure the mappings struct to make sure we don't miss any coverage: Rename `CoverageSpans` to `ExtractedMappings` coverage: Tidy imports in `rustc_mir_transform::coverage` Fix parse error message for meta items Refactor float `Primitive`s to a separate `Float` type Migrate `run-make/rustdoc-output-path` to rmake Make builtin_deref just return a Ty rename some variants in FulfillmentErrorCode Remove glob imports for ObligationCauseCode Rename some ObligationCauseCode variants More rename fallout Name tweaks Add a codegen test for transparent aggregates Aggregating arrays can always take the place path Make SSA aggregates without needing an alloca Lift `Lift` Lift `TraitRef` into `rustc_type_ir` Also debug Apply nits, make some bounds into supertraits on inherent traits Add `-lmingwex` second time in `mingw_libs` Upcoming mingw-w64 releases will contain small math functions refactor which moved implementation around. As a result functions like `lgamma` now depend on libraries in this order: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`. Fixes rust-lang#124221 ignore generics args in attribute paths bootstrap: add comments for the automatic dry run fix typo Co-authored-by: jyn <[email protected]> reachable computation: extend explanation of what this does, and why Make sure we consume a generic arg when checking mistyped turbofish Update cargo std::rand: adding solaris/illumos for getrandom support. To help solarish support for miri https://rust-lang/miri/issues/3567 Update ena to 0.14.3 Fix typo in ManuallyDrop's documentation Add @saethlin to some triagebot groups Refactor Apple `target_abi` This was bundled together with `Arch`, which complicated a few code paths and meant we had to do more string matching than necessary. Match ergonomics 2024: let `&` patterns eat `&mut` Various fixes: - Only show error when move-check would not be triggered - Add structured suggestion Fix spans when macros are involved Comments and fixes Rename `explicit_ba` No more `Option<Option<>>` Remove redundant comment Move all ref pat logic into `check_pat_ref` Add comment on `cap_to_weakly_not` Co-authored-by: Guillaume Boisseau <[email protected]> Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str` Remove feature from documentation examples Add rustc_const_stable attribute to stabilized functions Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions Document proper usage of `fmt::Error` and `fmt()`'s `Result`. Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items. check if `x test tests` missing any test directory Signed-off-by: onur-ozkan <[email protected]> remap missing path `tests/crashes` to `tests` Signed-off-by: onur-ozkan <[email protected]> add "tidy-alphabetical" check on "tests" remap list Signed-off-by: onur-ozkan <[email protected]> Handle Deref expressions in invalid_reference_casting unix/fs: a bit of cleanup around host-specific code solaris support start. reduce tokio features remove rand test the actual target-specific things we want to test are all in getrandom, and rand already tests miri itself getrandom: test with and without isolation also add some comments for why we keep certain old obscure APIs supported avoid code duplication between realloc and malloc Implement wcslen organize libc tests into a proper folder, and run some of them on Windows README: update introduction remove problems that I do not think we have seen in a while io::Error handling: keep around the full io::Error for longer so we can give better errors Implement non-null pointer for malloc(0) Allow test targets to be set via CLI args Update CI script for the miri-script test changes Update documentation for miri-script test changes minor tweaks make MIRI_TEST_TARGET entirely an internal thing make RUSTC_BLESS entirely an internal thing do not run symlink tests on Windows hosts rename 'extern-so' to 'native-lib' Preparing for merge from rustc alloc: update comments around malloc() alignment separate windows heap functions from C heap shims Add windows_i686_gnullvm to the list Pin libc back to 0.2.153 Update Cargo.lock fix few typo in filecheck annotations Consolidate obligation cause codes for where clauses Clean up users of rust_dbg_call Enable profiler for armv7-unknown-linux-gnueabihf. Always hide private fields in aliased type Migrate `run-make/rustdoc-shared-flags` to rmake Relax allocator requirements on some Rc APIs. * Remove A: Clone bound from Rc::assume_init, Rc::downcast, and Rc::downcast_unchecked. * Make From<Rc<[T; N]>> for Rc<[T]> allocator-aware. Internal changes: * Made Arc::internal_into_inner_with_allocator method into Arc::into_inner_with_allocator associated fn. * Add private Rc::into_inner_with_allocator (to match Arc), so other fns don't have to juggle ManuallyDrop. Relax A: Clone requirement on Rc/Arc::unwrap_or_clone. Add test for rust-lang#122775 Refactoring after the `PlaceValue` addition I added `PlaceValue` in 123775, but kept that one line-by-line simple because it touched so many places. This goes through to add more helpers & docs, and change some `PlaceRef` to `PlaceValue` where the type didn't need to be included. No behaviour changes. Make it possible to derive Lift/TypeVisitable/TypeFoldable in rustc_type_ir Uplift `TraitPredicate` Uplift `ExistentialTraitRef`, `ExistentialProjection`, `ProjectionPredicate` Uplift `NormalizesTo`, `CoercePredicate`, and `SubtypePredicate` Apply nits, uplift ExistentialPredicate too And `ImplPolarity` too Expand on expr_requires_semi_to_be_stmt documentation Mark expr_requires_semi_to_be_stmt call sites For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization. Macro call with braces does not require semicolon to be statement This commit by itself is supposed to have no effect on behavior. All of the call sites are updated to preserve their previous behavior. The behavior changes are in the commits that follow. Add ExprKind::MacCall statement boundary tests Fix pretty printer statement boundaries after braced macro call Delete MacCall case from pretty-printing semicolon after StmtKind::Expr I didn't figure out how to reach this condition with `expr` containing `ExprKind::MacCall`. All the approaches I tried ended up with the macro call ending up in the `StmtKind::MacCall` case below instead. In any case, from visual inspection this is a bugfix. If we do end up with a `StmtKind::Expr` containing `ExprKind::MacCall` with brace delimiter, it would not need ";" printed after it. Add test of unused_parens lint involving macro calls Document the situation with unused_parens lint and braced macro calls Add parser tests for statement boundary insertion Mark Parser::expr_is_complete call sites Document MacCall special case in Parser::expr_is_complete Document MacCall special case in Parser::parse_arm Add macro calls to else-no-if parser test Remove MacCall special case from recovery after missing 'if' after 'else' The change to the test is a little goofy because the compiler was guessing "correctly" before that `falsy! {}` is the condition as opposed to the else body. But I believe this change is fundamentally correct. Braced macro invocations in statement position are most often item-like (`thread_local! {...}`) as opposed to parenthesized macro invocations which are condition-like (`cfg!(...)`). Remove MacCall special cases from Parser::parse_full_stmt It is impossible for expr here to be a braced macro call. Expr comes from `parse_stmt_without_recovery`, in which macro calls are parsed by `parse_stmt_mac`. See this part: let kind = if (style == MacStmtStyle::Braces && self.token != token::Dot && self.token != token::Question) || self.token == token::Semi || self.token == token::Eof { StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) } else { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.maybe_recover_from_bad_qpath(e)?; let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; let e = self.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr: e, starts_statement: false }, )?; StmtKind::Expr(e) }; A braced macro call at the head of a statement is always either extended into ExprKind::Field / MethodCall / Await / Try / Binary, or else returned as StmtKind::MacCall. We can never get a StmtKind::Expr containing ExprKind::MacCall containing brace delimiter. Add classify::expr_is_complete Fix redundant parens around braced macro call in match arms use key-value format in stage0 file Currently, we are working on the python removal task on bootstrap. Which means we have to extract some data from the stage0 file using shell scripts. However, parsing values from the stage0.json file is painful because shell scripts don't have a built-in way to parse json files. This change simplifies the stage0 file format to key-value pairs, which makes it easily readable from any environment. Signed-off-by: onur-ozkan <[email protected]> awk stage0 file on CI Signed-off-by: onur-ozkan <[email protected]> use stage0 file in `bootstrap.py` Signed-off-by: onur-ozkan <[email protected]> use shared stage0 parser from `build_helper` Signed-off-by: onur-ozkan <[email protected]> remove outdated stage0.json parts Signed-off-by: onur-ozkan <[email protected]> move comments position in `src/stage0` Signed-off-by: onur-ozkan <[email protected]> io::Write::write_fmt: panic if the formatter fails when the stream does not fail std::alloc: using posix_memalign instead of memalign on solarish. simpler code path since small alignments are already taking care of. close rust-langGH-124787 Relax slice safety requirements Per rust-lang#116677 (comment), the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when rust-lang#117945 is implemented, we can revert to the old language. References must also be non-null Add `crate_type` method to `Rustdoc` Add `crate_name` method to `Rustdoc` and `Rustc` Add `python_command` and `source_path` functions Add `extern_` method to `Rustdoc` Migrate `rustdoc-scrape-examples-ordering` to `rmake` Fix some minor issues from the ui-test auto-porting solve: replace all `debug` with `trace` structurally important functions to `debug` fix hidden title in command-line-arguments docs Assert that MemCategorizationVisitor actually errors when it bails ungracefully Inline MemCategorization into ExprUseVisitor Remove unncessary mut ref Introduce TypeInformationCtxt to abstract over LateCtxt/FnCtxt Make LateCtxt be a type info delegate for EUV for clippy Try structurally resolve Apply nits Propagate errors rather than using return_if_err Match ergonomics 2024: migration lint Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion. Co-Authored-By: Guillaume Boisseau <[email protected]> Add AST pretty-printer tests for let-else Pretty-print let-else with added parenthesization when needed rename
reorganised attrs removed OsStr impls added backticks Add note about possible allocation-sharing to Arc/Rc<str/[T]/CStr>::default. Use shared statics for the ArcInner for Arc<str, CStr>::default, and for Arc<[T]>::default where alignof(T) <= 16. fixed unsafe block Revert "fixed unsafe block" This reverts commit 6eb6aee. Return coherent description for boolean instead of panicking Improve check-cfg CLI errors with more structured diagnostics Move various stdlib tests to library/std/tests Run tidy on tests Rename test for issue 21058 Implement `edition` method on `Rustdoc` type as well Migrate `run-make/doctests-runtool` to rmake Rename `run-make-support` library `output` method to `command_output` Add new `output` method to `Rustc` and `Rustdoc` types Migrate `run-make/rustdoc-error-lines` to `rmake.rs` add f16 associated constants NaN and infinity are not included as they require arithmetic. add f128 associated constants NaN and infinity are not included as they require arithmetic. add constants in std::f16::consts add constants in std::f128::consts update error messages in ui tests Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times Also mention that there might be leftover directories in the error case. Prefer lower vtable candidates in select in new solver Don't consider candidates with no failing where clauses Use super_fold in RegionsToStatic visitor Make check-cfg docs more user-friendly Record impl args in the InsepctCandiate rather than rematching during select Use correct ImplSource for alias bounds BorrowckInferCtxt: infcx by value borrowck: more eagerly prepopulate opaques switch new solver to directly inject opaque types Update books Adjust dbg.value/dbg.declare checks for LLVM update llvm/llvm-project#89799 changes llvm.dbg.value/declare intrinsics to be in a different, out-of-instruction-line representation. For example call void @llvm.dbg.declare(...) becomes #dbg_declare(...) Update tests accordingly to work with both the old and new way. Adjust 64-bit ARM data layouts for LLVM update LLVM has updated data layouts to specify `Fn32` on 64-bit ARM to avoid C++ accidentally underaligning functions when trying to comply with member function ABIs. This should only affect Rust in cases where we had a similar bug (I don't believe we have one), but our data layout must match to generate code. As a compatibility adaptatation, if LLVM is not version 19 yet, `Fn32` gets voided from the data layout. See llvm/llvm-project#90415 Update version of cc crate to v1.0.97 Reason: In order to build the Windows version of the Rust toolchain for the Android platform, the following patch to the cc is crate is required to avoid incorrectly determining that we are building with the Android NDK: rust-lang/cc-rs@57853c4 This patch is present in version 1.0.80 and newer versions of the cc crate. The rustc source distribution currently has 3 different versions of cc in the vendor directory, only one of which has the necessary fix. We (the Android Rust toolchain) are currently maintaining local patches to upgrade the cc crate dependency versions, which we would like to upstream. Furthermore, beyond the specific reason, the cc crate in bootstrap is currently pinned at an old version due to problems in the past when trying to update it. It is worthwhile to figure out and resolve these problems so we can keep the dependency up-to-date. Other fixes: As of cc v1.0.78, object files are prefixed with a 16-character hash. Update src/bootstrap/src/core/build_steps/llvm.rs to account for this to avoid failures when building libunwind and libcrt. Note that while the hash prefix was introduced in v1.0.78, in order to determine the names of the object files without scanning the directory, we rely on the compile_intermediates method, which was introduced in cc v1.0.86 As of cc v1.0.86, compilation on MacOS uses the -mmacosx-version-min flag. A long-standing bug in the CMake rules for compiler-rt causes compilation to fail when this flag is specified. So we add a workaround to suppress this flag. Updating to cc v1.0.91 and newer requires fixes to bootstrap unit tests. The unit tests use targets named "A", "B", etc., which fail a validation check introduced in 1.0.91 of the cc crate. Implement lldb formattter for "clang encoded" enums (LLDB 18.1+) Summary: I landed a fix last year to enable `DW_TAG_variant_part` encoding in LLDBs (https://reviews.llvm.org/D149213). This PR is a corresponding fix in synthetic formatters to decode that information. This is in no way perfect implementation but at least it improves the status quo. But most types of enums will be visible and debuggable in some way. I've also updated most of the existing tests that touch enums and re-enabled test cases based on LLDB for enums. Test Plan: ran tests `./x test tests/debuginfo/`. Also tested manually in LLDB CLI and LLDB VSCode Other Thoughs A better approach would probably be adopting [formatters from codelldb](https://github.com/vadimcn/codelldb/blob/master/formatters/rust.py). There is some neat hack that hooks up summary provider via synthetic provider which can ultimately fix more display issues for Rust types and enums too. But getting it to work well might take more time that I have right now. f16::is_sign_{positive,negative} were feature-gated on f128 Correct the const stabilization of `last_chunk` for slices `<[T]>::last_chunk` should have become const stable as part of <rust-lang#117561>. Update the const stability gate to reflect this. Add tests Lower never patterns to Unreachable in mir rustdoc: dedup search form HTML This change constructs the search form HTML using JavaScript, instead of plain HTML. It uses a custom element because - the [parser]'s insert algorithm runs the connected callback synchronously, so we won't get layout jank - it requires very little HTML, so it's a real win in size [parser]: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token This shrinks the standard library by about 60MiB, by my test. rustdoc: allow custom element rustdoc-search generalize hr alias: avoid unconstrainable infer vars narrow down visibilities in `rustc_parse::lexer` replace another Option<Span> by DUMMY_SP Don't ICE when we cannot eval a const to a valtree in the new solver Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check` coverage: Add branch coverage support for let-else coverage: Add branch coverage support for if-let and let-chains Do not ICE on foreign malformed `diagnostic::on_unimplemented` Fix rust-lang#124651. Add test for rust-lang#124651 Update cargo compiler: Privatize `Parser::current_closure` This was added as pub in 2021 and remains only privately used in 2024! compiler: derive Debug in parser It's annoying to debug the parser if you have to stop every five seconds to add a Debug impl. compiler: add `Parser::debug_lookahead` I tried debugging a parser-related issue but found it annoying to not be able to easily peek into the Parser's token stream. Add a convenience fn that offers an opinionated view into the parser, but one that is useful for answering basic questions about parser state. Fuchsia test runner: fixup script This commit fixes several issues in the fuchsia-test-runner.py script: 1. Migrate from `pm` to `ffx` for package management, as `pm` is now deprecated. Furthermore, the `pm` calls used in this script no longer work at Fuchsia's HEAD. This is the largest change in this commit, and impacts all steps around repository management (creation and registration of the repo, as well as package publishing). 2. Allow for `libtest` to be either statically or dynamically linked. The script assumed it was dynamically linked, but the current Rust behavior at HEAD is to statically link it. 3. Minor cleanup to use `ffx --machine json` rather than string parsing. 4. Minor cleanup to the docs around the script. std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly. add note about `AlreadyExists` to `create_new` Apply suggestions from code review Co-authored-by: Jubilee <[email protected]> iOS/tvOS/watchOS/visionOS: Default to kernel-defined backlog in listen This behavior is defined in general for the XNU kernel, not just macOS: https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/kern/uipc_socket.c iOS/tvOS/watchOS/visionOS: Set the main thread name Tested in the iOS simulator that the thread name is not set by default, and that setting it improves the debugging experience in lldb / Xcode. iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions Tested on an old MacBook and the iOS simulator. iOS/tvOS/watchOS/visionOS: Fix reading large files Tested in the iOS simulator with something like: ``` let mut buf = vec![0; c_int::MAX as usize - 1 + 2]; let read_bytes = f.read(&mut buf).unwrap(); ``` iOS/tvOS/watchOS/visionOS: Improve File Debug impl This uses `libc::fcntl`, which, while not explicitly marked as available in the headers, is already used by `File::sync_all` and `File::sync_data` on these platforms, so should be fine to use here as well. next_power_of_two: add a doctest to show what happens on 0 rustc: Change LLVM target for the wasm32-wasip2 Rust target This commit changes the LLVM target of for the Rust `wasm32-wasip2` target to `wasm32-wasip2` as well. LLVM does a bit of detection on the target string to know when to call `wasm-component-ld` vs `wasm-ld` so otherwise clang is invoking the wrong linker. rustc: Don't pass `-fuse-ld=lld` on wasm targets This argument isn't necessary for WebAssembly targets since `wasm-ld` is the only linker for the targets. Passing it otherwise interferes with Clang's linker selection on `wasm32-wasip2` so avoid it altogether. rustc: Change wasm32-wasip2 to PIC-by-default This commit changes the new `wasm32-wasip2` target to being PIC by default rather than the previous non-PIC by default. This change is intended to make it easier for the standard library to be used in a shared object in its precompiled form. This comes with a hypothetical modest slowdown but it's expected that this is quite minor in most use cases or otherwise wasm compilers and/or optimizing runtimes can elide the cost. Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes an ICE that occurred when the struct in question has an error Fix insufficient logic when searching for the underlying allocation in the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts. rustdoc: use stability, instead of features, to decide what to show To decide if internal items should be inlined in a doc page, check if the crate is itself internal, rather than if it has the rustc_private feature flag. The standard library uses internal items, but is not itself internal and should not show internal items on its docs pages. Avoid a cast in `ptr::slice_from_raw_parts(_mut)` Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not. If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it. add enum variant field names to make the code clearer remove redundant flat vs nested distinction to simplify enum turn all_nested_unused into used_childs store the span of the nested part of the use tree in the ast remove braces when fixing a nested use tree into a single use Use generic `NonZero` in examples. Simplify `clippy` lint. Simplify suggestion. Use generic `NonZero`. crashes: add lastest batch of crash tests Make sure we don't deny macro vars w keyword names Simplify `use crate::rustc_foo::bar` occurrences. They can just be written as `use rustc_foo::bar`, which is far more standard. (I didn't even know that a `crate::` prefix was valid.) Update cc crate to v1.0.97 Ignore empty RUSTC_WRAPPER in bootstrap This change ignores the RUSTC_WRAPPER_REAL environment variable if it's set to the empty string. This matches cargo behaviour and allows users to easily shadow a globally set RUSTC_WRAPPER (which they might have set for non-rustc projects). Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes an ICE that occurred when the struct in question has an error Implement `as_chunks` with `split_at_unchecked` Remove `macro_use` from `stable_hasher`. Normal `use` items are nicer. Reorder top-level crate items. - `use` before `mod` - `pub` before `non-pub` - Alphabetical order within sections Remove `extern crate tracing`. `use` is a nicer way of doing things. Document `Pu128`. And move the `repr` line after the `derive` line, where it's harder to overlook. (I overlooked it initially, and didn't understand how this type worked.) Remove `TinyList`. It is optimized for lists with a single element, avoiding the need for an allocation in that case. But `SmallVec<[T; 1]>` also avoids the allocation, and is better in general: more standard, log2 number of allocations if the list exceeds one item, and a much more capable API. This commit removes `TinyList` and converts the two uses to `SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant file so they are in just two sections (`pub` and non-`pub`), ordered alphabetically, instead of many sections. (This is a relevant part of the change because I had to decide where to add a `use` item for `SmallVec`.) Remove `vec_linked_list`. It provides a way to effectively embed a linked list within an `IndexVec` and also iterate over that list. It's written in a very generic way, involving two traits `Links` and `LinkElem`. But the `Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the whole thing is only used in one module within `rustc_borrowck`. So I think it's over-engineered and hard to read. Plus it has no comments. This commit removes it, and adds a (non-generic) local iterator for the use within `rustc_borrowck`. Much simpler. Remove `enum_from_u32`. It's a macro that just creates an enum with a `from_u32` method. It has two arms. One is unused and the other has a single use. This commit inlines that single use and removes the whole macro. This increases readability because we don't have two different macros interacting (`enum_from_u32` and `language_item_table`). Update Tests Fix Error Messages for `break` Inside Coroutines Previously, `break` inside `gen` blocks and functions were incorrectly identified to be enclosed by a closure. This PR fixes it by displaying an appropriate error message for async blocks, async closures, async functions, gen blocks, gen closures, gen functions, async gen blocks, async gen closures and async gen functions. Note: gen closure and async gen closure are not supported by the compiler yet but I have added an error message here assuming that they might be implemented in the future. Also, fixes grammar in a few places by replacing `inside of a $coroutine` with `inside a $coroutine`. Migrate `run-make/rustdoc-map-file` to rmake Add more ICEs due to malformed diagnostic::on_unimplemented Fix ICEs in diagnostic::on_unimplemented Handle field projections like slice indexing in invalid_reference_casting Fix typos Do not add leading asterisk in the `PartialEq` Adding leading asterisk can cause compilation failure for the _types_ that don't implement the `Copy`. Use sum type for `WorkflowRunType` Parse try build CI job name from commit message Make the regex more robust Address review comments CI: fix auto builds and make sure that we always have at least a single CI job Include the line number in tidy's `iter_header` Tidy check for test revisions that are mentioned but not declared If a `[revision]` name appears in a test header directive or error annotation, but isn't declared in the `//@ revisions:` header, that is almost always a mistake. In cases where a revision needs to be temporarily disabled, adding it to an `//@ unused-revision-names:` header will suppress these checks for that name. Adding the wildcard name `*` to the unused list will suppress these checks for the entire file. Fix test problems discovered by the revision check Most of these changes either add revision names that were apparently missing, or explicitly mark a revision name as currently unused. fix rust-lang#124714 str.to_lowercase sigma handling Make a minimal amount of region APIs public Add `ErrorGuaranteed` to `Recovered::Yes` and use it more. The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error. interpret/miri: better errors on failing offset_from chore: remove repetitive words Make `#![feature]` suggestion MaybeIncorrect Update Makefiles with explanatory comments correct comments add FIXME Upgrade the version of Clang used in the build, move MSVC builds to Server 2022 Rename Generics::params to Generics::own_params Add benchmarks for `impl Debug for str` In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress `impl Debug for str`. Remove unused `step_trait` feature. Also sort the features. Remove unused `LinkSelfContainedDefault::is_linker_enabled` method. Correct a comment. I tried simplifying `RegionCtxt`, which led me to finding that the fields are printed in `sccs_info`. Fix up `DescriptionCtx::new`. The comment mentions that `ReBound` and `ReVar` aren't expected here. Experimentation with the full test suite indicates this is true, and that `ReErased` also doesn't occur. So the commit introduces `bug!` for those cases. (If any of them show up later on, at least we'll have a test case.) The commit also remove the first sentence in the comment. `RePlaceholder` is now handled in the match arm above this comment and nothing is printed for it, so that sentence is just wrong. Furthermore, issue rust-lang#13998 was closed some time ago. Fix out-of-date comment. The type name has changed. Remove `TyCtxt::try_normalize_erasing_late_bound_regions`. It's unused. Remove out-of-date comment. The use of `Binder` was removed in the recent rust-lang#123900, but the comment wasn't removed at the same time. De-tuple two `vtable_trait_first_method_offset` args. Thus eliminating a `FIXME` comment. opt-dist: use xz2 instead of xz crate xz crate consist of simple reexport of xz2 crate. Why? Idk. analyse visitor: build proof tree in probe update crashes always use `GenericArgsRef` Inline and remove unused methods. `InferCtxt::next_{ty,const,int,float}_var_id` each have a single call site, in `InferCtt::next_{ty,const,int,float}_var` respectively. The only remaining method that creates a var_id is `InferCtxt::next_ty_var_id_in_universe`, which has one use outside the crate. Use fewer origins when creating type variables. `InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements. print walltime benchmarks with subnanosecond precision example results when benchmarking 1-4 serialized ADD instructions ``` running 4 tests test add ... bench: 0.24 ns/iter (+/- 0.00) test add2 ... bench: 0.48 ns/iter (+/- 0.01) test add3 ... bench: 0.72 ns/iter (+/- 0.01) test add4 ... bench: 0.96 ns/iter (+/- 0.01) ``` emit fractional benchmark nanoseconds in libtest's JSON output format bootstrap should also render fractional nanoseconds for benchmarks from_str_radix: outline only the panic function codegen: memmove/memset cannot be non-temporal coverage: Separately compute the set of BCBs with counter mappings coverage: Make the special case for async functions exit early coverage: Don't recompute the number of test vector bitmap bytes The code in `extract_mcdc_mappings` that allocates these bytes already knows how many are needed in total, so there's no need to immediately recompute that value in the calling function. coverage: Destructure the mappings struct to make sure we don't miss any coverage: Rename `CoverageSpans` to `ExtractedMappings` coverage: Tidy imports in `rustc_mir_transform::coverage` Fix parse error message for meta items Refactor float `Primitive`s to a separate `Float` type Migrate `run-make/rustdoc-output-path` to rmake Make builtin_deref just return a Ty rename some variants in FulfillmentErrorCode Remove glob imports for ObligationCauseCode Rename some ObligationCauseCode variants More rename fallout Name tweaks Add a codegen test for transparent aggregates Aggregating arrays can always take the place path Make SSA aggregates without needing an alloca Lift `Lift` Lift `TraitRef` into `rustc_type_ir` Also debug Apply nits, make some bounds into supertraits on inherent traits Add `-lmingwex` second time in `mingw_libs` Upcoming mingw-w64 releases will contain small math functions refactor which moved implementation around. As a result functions like `lgamma` now depend on libraries in this order: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`. Fixes rust-lang#124221 ignore generics args in attribute paths bootstrap: add comments for the automatic dry run fix typo Co-authored-by: jyn <[email protected]> reachable computation: extend explanation of what this does, and why Make sure we consume a generic arg when checking mistyped turbofish Update cargo std::rand: adding solaris/illumos for getrandom support. To help solarish support for miri https://rust-lang/miri/issues/3567 Update ena to 0.14.3 Fix typo in ManuallyDrop's documentation Add @saethlin to some triagebot groups Refactor Apple `target_abi` This was bundled together with `Arch`, which complicated a few code paths and meant we had to do more string matching than necessary. Match ergonomics 2024: let `&` patterns eat `&mut` Various fixes: - Only show error when move-check would not be triggered - Add structured suggestion Fix spans when macros are involved Comments and fixes Rename `explicit_ba` No more `Option<Option<>>` Remove redundant comment Move all ref pat logic into `check_pat_ref` Add comment on `cap_to_weakly_not` Co-authored-by: Guillaume Boisseau <[email protected]> Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str` Remove feature from documentation examples Add rustc_const_stable attribute to stabilized functions Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions Document proper usage of `fmt::Error` and `fmt()`'s `Result`. Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items. check if `x test tests` missing any test directory Signed-off-by: onur-ozkan <[email protected]> remap missing path `tests/crashes` to `tests` Signed-off-by: onur-ozkan <[email protected]> add "tidy-alphabetical" check on "tests" remap list Signed-off-by: onur-ozkan <[email protected]> Handle Deref expressions in invalid_reference_casting unix/fs: a bit of cleanup around host-specific code solaris support start. reduce tokio features remove rand test the actual target-specific things we want to test are all in getrandom, and rand already tests miri itself getrandom: test with and without isolation also add some comments for why we keep certain old obscure APIs supported avoid code duplication between realloc and malloc Implement wcslen organize libc tests into a proper folder, and run some of them on Windows README: update introduction remove problems that I do not think we have seen in a while io::Error handling: keep around the full io::Error for longer so we can give better errors Implement non-null pointer for malloc(0) Allow test targets to be set via CLI args Update CI script for the miri-script test changes Update documentation for miri-script test changes minor tweaks make MIRI_TEST_TARGET entirely an internal thing make RUSTC_BLESS entirely an internal thing do not run symlink tests on Windows hosts rename 'extern-so' to 'native-lib' Preparing for merge from rustc alloc: update comments around malloc() alignment separate windows heap functions from C heap shims Add windows_i686_gnullvm to the list Pin libc back to 0.2.153 Update Cargo.lock fix few typo in filecheck annotations Consolidate obligation cause codes for where clauses Clean up users of rust_dbg_call Enable profiler for armv7-unknown-linux-gnueabihf. Always hide private fields in aliased type Migrate `run-make/rustdoc-shared-flags` to rmake Relax allocator requirements on some Rc APIs. * Remove A: Clone bound from Rc::assume_init, Rc::downcast, and Rc::downcast_unchecked. * Make From<Rc<[T; N]>> for Rc<[T]> allocator-aware. Internal changes: * Made Arc::internal_into_inner_with_allocator method into Arc::into_inner_with_allocator associated fn. * Add private Rc::into_inner_with_allocator (to match Arc), so other fns don't have to juggle ManuallyDrop. Relax A: Clone requirement on Rc/Arc::unwrap_or_clone. Add test for rust-lang#122775 Refactoring after the `PlaceValue` addition I added `PlaceValue` in 123775, but kept that one line-by-line simple because it touched so many places. This goes through to add more helpers & docs, and change some `PlaceRef` to `PlaceValue` where the type didn't need to be included. No behaviour changes. Make it possible to derive Lift/TypeVisitable/TypeFoldable in rustc_type_ir Uplift `TraitPredicate` Uplift `ExistentialTraitRef`, `ExistentialProjection`, `ProjectionPredicate` Uplift `NormalizesTo`, `CoercePredicate`, and `SubtypePredicate` Apply nits, uplift ExistentialPredicate too And `ImplPolarity` too Expand on expr_requires_semi_to_be_stmt documentation Mark expr_requires_semi_to_be_stmt call sites For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization. Macro call with braces does not require semicolon to be statement This commit by itself is supposed to have no effect on behavior. All of the call sites are updated to preserve their previous behavior. The behavior changes are in the commits that follow. Add ExprKind::MacCall statement boundary tests Fix pretty printer statement boundaries after braced macro call Delete MacCall case from pretty-printing semicolon after StmtKind::Expr I didn't figure out how to reach this condition with `expr` containing `ExprKind::MacCall`. All the approaches I tried ended up with the macro call ending up in the `StmtKind::MacCall` case below instead. In any case, from visual inspection this is a bugfix. If we do end up with a `StmtKind::Expr` containing `ExprKind::MacCall` with brace delimiter, it would not need ";" printed after it. Add test of unused_parens lint involving macro calls Document the situation with unused_parens lint and braced macro calls Add parser tests for statement boundary insertion Mark Parser::expr_is_complete call sites Document MacCall special case in Parser::expr_is_complete Document MacCall special case in Parser::parse_arm Add macro calls to else-no-if parser test Remove MacCall special case from recovery after missing 'if' after 'else' The change to the test is a little goofy because the compiler was guessing "correctly" before that `falsy! {}` is the condition as opposed to the else body. But I believe this change is fundamentally correct. Braced macro invocations in statement position are most often item-like (`thread_local! {...}`) as opposed to parenthesized macro invocations which are condition-like (`cfg!(...)`). Remove MacCall special cases from Parser::parse_full_stmt It is impossible for expr here to be a braced macro call. Expr comes from `parse_stmt_without_recovery`, in which macro calls are parsed by `parse_stmt_mac`. See this part: let kind = if (style == MacStmtStyle::Braces && self.token != token::Dot && self.token != token::Question) || self.token == token::Semi || self.token == token::Eof { StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) } else { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.maybe_recover_from_bad_qpath(e)?; let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; let e = self.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr: e, starts_statement: false }, )?; StmtKind::Expr(e) }; A braced macro call at the head of a statement is always either extended into ExprKind::Field / MethodCall / Await / Try / Binary, or else returned as StmtKind::MacCall. We can never get a StmtKind::Expr containing ExprKind::MacCall containing brace delimiter. Add classify::expr_is_complete Fix redundant parens around braced macro call in match arms use key-value format in stage0 file Currently, we are working on the python removal task on bootstrap. Which means we have to extract some data from the stage0 file using shell scripts. However, parsing values from the stage0.json file is painful because shell scripts don't have a built-in way to parse json files. This change simplifies the stage0 file format to key-value pairs, which makes it easily readable from any environment. Signed-off-by: onur-ozkan <[email protected]> awk stage0 file on CI Signed-off-by: onur-ozkan <[email protected]> use stage0 file in `bootstrap.py` Signed-off-by: onur-ozkan <[email protected]> use shared stage0 parser from `build_helper` Signed-off-by: onur-ozkan <[email protected]> remove outdated stage0.json parts Signed-off-by: onur-ozkan <[email protected]> move comments position in `src/stage0` Signed-off-by: onur-ozkan <[email protected]> io::Write::write_fmt: panic if the formatter fails when the stream does not fail std::alloc: using posix_memalign instead of memalign on solarish. simpler code path since small alignments are already taking care of. close rust-langGH-124787 Relax slice safety requirements Per rust-lang#116677 (comment), the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when rust-lang#117945 is implemented, we can revert to the old language. References must also be non-null Add `crate_type` method to `Rustdoc` Add `crate_name` method to `Rustdoc` and `Rustc` Add `python_command` and `source_path` functions Add `extern_` method to `Rustdoc` Migrate `rustdoc-scrape-examples-ordering` to `rmake` Fix some minor issues from the ui-test auto-porting solve: replace all `debug` with `trace` structurally important functions to `debug` fix hidden title in command-line-arguments docs Assert that MemCategorizationVisitor actually errors when it bails ungracefully Inline MemCategorization into ExprUseVisitor Remove unncessary mut ref Introduce TypeInformationCtxt to abstract over LateCtxt/FnCtxt Make LateCtxt be a type info delegate for EUV for clippy Try structurally resolve Apply nits Propagate errors rather than using return_if_err Match ergonomics 2024: migration lint Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion. Co-Authored-By: Guillaume Boisseau <[email protected]> Add AST pretty-printer tests for let-else Pretty-print let-else with added parenthesization when needed rename
This PR does a few different things based around stabilizing
slice_first_last_chunk
. They are split up so this PR can be by-commit reviewed, I can move parts to a separate PR if desired.This feature provides a very elegant API to extract arrays from either end of a slice, such as for parsing integers from binary data.
Stabilize
slice_first_last_chunk
ACP: rust-lang/libs-team#69
Implementation: #90091
Tracking issue: #111774
This stabilizes the functionality from #111774:
Const stabilization is included for all non-mut methods, which are blocked on
const_mut_refs
. This change includes marking the trivial functionslice_split_at_unchecked
const-stable for internal use (but not fully stable).Remove
split_array
slice methodsTracking issue: #90091
Implementation: #83233 (review)
This PR also removes the following unstable methods from the
split_array
feature, #90091:This is done because discussion at #90091 and its implementation PR indicate a strong preference for nonpanicking APIs that return
Option
. The only difference between functions under thesplit_array
andslice_first_last_chunk
features isOption
vs. panic, so remove the duplicates as part of this stabilization.This does not affect the array methods from
split_array
. We will want to revisit these oncegeneric_const_exprs
is further along.Reverse order of return tuple for
split_last_chunk{,_mut}
An unresolved question for #111774 is whether to return
(preceding_slice, last_chunk)
((&[T], &[T; N])
) or the reverse ((&[T; N], &[T])
), fromsplit_last_chunk
andsplit_last_chunk_mut
. It is currently implemented as(last_chunk, preceding_slice)
which matchessplit_last -> (&T, &[T])
. The first commit changes these to(&[T], &[T; N])
for these reasons:str::rsplit_once
,slice::split_at{,_mut}
,slice::align_to
all return tuples with the items in orderlet [a, b, rest @ ..] ...
.split_many_last::<(2, 4)>() -> (&[T], &[T; 2], &[T; 4])
rsplit_array
methodsI think the inconsistency with
split_last
could be acceptable in this case, since forsplit_last
the scalar&T
doesn't have any internal order to maintain with the other items.Unresolved questions
Do we want to reserve the same names on
[u8; N]
to avoid inference confusion? #117561 (comment)slice_first_last_chunk
has only been around since early 2023, butsplit_array
has been around since 2021.@rustbot label -T-libs +T-libs-api -T-libs +needs-fcp
cc @rust-lang/wg-const-eval, @scottmcm who raised this topic, @clarfonthey implementer of
slice_first_last_chunk
@jethrogb implementer ofsplit_array
Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Stabilizing.20array-from-slice.20*something*.3F
Fixes: #111774