-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait #93827
Conversation
Some changes occurred in src/tools/clippy. cc @rust-lang/clippy |
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Oh, you beat me to it! Nice work! |
I have a documentation PR at rust-lang/reference#1166. |
Please also remove |
Cc @rust-lang/wg-const-eval |
To be clear, what is being "stabilized" here is simply mentioning the types Actually having function pointers or trait objects that can be called during CTFE is future work, and will require new syntax. |
Done! |
I think my comment on zulip got drowned out by the other thread XD. Repeating it here:
|
Repeating this comment, as I'm now nominating this PR for @rust-lang/lang to consider. In the const eval meeting we had right before the new year and in the zulip discussion afterwards, there seemed resounding support for this PR's change. The changes from this PR already had existing workarounds, so no new behaviour is stabilized, just convenient syntax: |
☔ The latest upstream changes (presumably #93893) made this pull request unmergeable. Please resolve the merge conflicts. |
The PR title suggests this is aiming to stabilize both const_fn_trait_bound and const_fn_fn_ptr_basics, the latter of which seems to be what your comment discusses, whereas const_fn_trait_bound is not addressed? Are these features coupled in some way, or is it just being stabilized in the same PR for convenience? Regardless, I think it would be good to write a more complete description of the changes here into the PR description -- just because this is stabilizing 'nicer syntax' rather than truly new functionality IMO does not mean that we should side step a stabilization report for this new feature, even if it is relatively simple -- some questions that I have:
IOW, it seems like it would be a reasonable step to stabilize these as-if we were in a world where they were entirely inaccessible in const fn, since that is the blessed world from a language perspective. For const fn trait bounds, I think a similar approach of 'from scratch' stabilization, rather than a delta with the already stable language would be good. Obviously, some (all?) of the decisions have already been fairly fixed in place, but having that stabilization report would let us discuss whether some of them are in hindsight a bad idea, and potentially propose either edition changes or otherwise break the behavior in the future; skipping the stabilization report doesn't really do us much good. More on a T-compiler perspective -- it sounds like the stabilization here (via the workarounds) was done largely by accident -- have we expanded test coverage or considered what can be done to avoid future mistakes? Is there some extra validation we should try to do? |
Thanks for the comments and questions, @Mark-Simulacrum. This is my first time going starting the stabilization process, and somehow I missed the big section on "Write a stabilization report" when I read https://rustc-dev-guide.rust-lang.org/stabilization_guide.html. I agree that these features do not warrant side-stepping the normal process. I'll take some time to write up a proper report and make sure to address the questions you raised as well as the other points mentioned in the dev guide. |
b1f7412
to
44556b1
Compare
Ah, sorry I missed this part. I just pushed another commit that includes |
☔ The latest upstream changes (presumably #93956) made this pull request unmergeable. Please resolve the merge conflicts. |
I'll second what @Mark-Simulacrum wrote, a stabilization report would be great. I will also say that in some recent conversations, @tmandry and I were landing on designs that really wanted the ability to write a |
01dce81
to
4dc07cb
Compare
The `const_fn_trait_bound` feature was stabilized by <rust-lang/rust#93827>.
The `const_impl_trait` feature was stabilized by <rust-lang/rust#93827>.
The `const_fn_fn_ptr_basics` feature was stabilized by <rust-lang/rust#93827>.
…askrgr Rollup of 4 pull requests Successful merges: - rust-lang#93350 (libunwind: readd link attrs to _Unwind_Backtrace) - rust-lang#93827 (Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait) - rust-lang#94696 (Remove whitespaces and use CSS to align line numbers to the right instead) - rust-lang#94700 (rustdoc: Update minifier version) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I'm doubtful about the |
2988: Remove const_fn_trait_bound feature and update nightly (Mar 2022) r=hudson-ayers a=bradjc ### Pull Request Overview rust-lang/rust#93827 was merged, so there should soon be a nightly that allows us to remove `const_fn_trait_bound` feature. It seems like some of the tools we use aren't working right now, but this PR is a placeholder for when we can update to a new enough nightly. After this, our list of features looks like: ``` arch/cortex-m/src/lib.rs:#![feature(asm_sym)] arch/cortex-m/src/lib.rs:#![feature(naked_functions)] arch/cortex-m0/src/lib.rs:#![feature(asm_sym, naked_functions)] arch/cortex-m0p/src/lib.rs:#![feature(naked_functions)] arch/rv32i/src/lib.rs:#![feature(asm_sym, naked_functions)] boards/esp32-c3-devkitM-1/src/main.rs:#![feature(custom_test_frameworks)] boards/nano_rp2040_connect/src/main.rs:#![feature(naked_functions)] boards/opentitan/src/main.rs:#![feature(custom_test_frameworks)] boards/pico_explorer_base/src/main.rs:#![feature(naked_functions)] boards/raspberry_pi_pico/src/main.rs:#![feature(naked_functions)] chips/earlgrey/src/lib.rs:#![feature(naked_functions)] chips/esp32-c3/src/lib.rs:#![feature(naked_functions)] chips/litex_vexriscv/src/lib.rs:#![feature(asm_const)] chips/lowrisc/src/lib.rs:#![feature(const_mut_refs)] chips/swervolf-eh1/src/lib.rs:#![feature(naked_functions)] doc/courses/rustconf/application.md:#![feature(alloc)] kernel/src/lib.rs:#![feature(core_intrinsics)] libraries/riscv-csr/src/lib.rs:#![feature(asm_const)] libraries/tock-cells/src/lib.rs:#![feature(const_mut_refs)] ``` ### Testing Strategy travis ### TODO or Help Wanted Need a version of nightly with all valid tools. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Brad Campbell <[email protected]>
2988: Remove const_fn_trait_bound feature and update nightly (Mar 2022) r=lschuermann a=bradjc ### Pull Request Overview rust-lang/rust#93827 was merged, so there should soon be a nightly that allows us to remove `const_fn_trait_bound` feature. It seems like some of the tools we use aren't working right now, but this PR is a placeholder for when we can update to a new enough nightly. After this, our list of features looks like: ``` arch/cortex-m/src/lib.rs:#![feature(asm_sym)] arch/cortex-m/src/lib.rs:#![feature(naked_functions)] arch/cortex-m0/src/lib.rs:#![feature(asm_sym, naked_functions)] arch/cortex-m0p/src/lib.rs:#![feature(naked_functions)] arch/rv32i/src/lib.rs:#![feature(asm_sym, naked_functions)] boards/esp32-c3-devkitM-1/src/main.rs:#![feature(custom_test_frameworks)] boards/nano_rp2040_connect/src/main.rs:#![feature(naked_functions)] boards/opentitan/src/main.rs:#![feature(custom_test_frameworks)] boards/pico_explorer_base/src/main.rs:#![feature(naked_functions)] boards/raspberry_pi_pico/src/main.rs:#![feature(naked_functions)] chips/earlgrey/src/lib.rs:#![feature(naked_functions)] chips/esp32-c3/src/lib.rs:#![feature(naked_functions)] chips/litex_vexriscv/src/lib.rs:#![feature(asm_const)] chips/lowrisc/src/lib.rs:#![feature(const_mut_refs)] chips/swervolf-eh1/src/lib.rs:#![feature(naked_functions)] doc/courses/rustconf/application.md:#![feature(alloc)] kernel/src/lib.rs:#![feature(core_intrinsics)] libraries/riscv-csr/src/lib.rs:#![feature(asm_const)] libraries/tock-cells/src/lib.rs:#![feature(const_mut_refs)] ``` ### Testing Strategy travis ### TODO or Help Wanted Need a version of nightly with all valid tools. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Brad Campbell <[email protected]>
Pkgsrc changes: * adapt patches * new checksums Upstream changes: Version 1.61.0 (2022-05-19) ========================== Language -------- - [`const fn` signatures can now include generic trait bounds][93827] - [`const fn` signatures can now use `impl Trait` in argument and return position][93827] - [Function pointers can now be created, cast, and passed around in a `const fn`][93827] - [Recursive calls can now set the value of a function's opaque `impl Trait` return type][94081] Compiler -------- - [Linking modifier syntax in `#[link]` attributes and on the command line, as well as the `whole-archive` modifier specifically, are now supported][93901] - [The `char` type is now described as UTF-32 in debuginfo][89887] - The [`#[target_feature]`][target_feature] attribute [can now be used with aarch64 features][90621] - X86 [`#[target_feature = "adx"]` is now stable][93745] Libraries --------- - [`ManuallyDrop<T>` is now documented to have the same layout as `T`][88375] - [`#[ignore = "#"]` messages are printed when running tests][92714] - [Consistently show absent stdio handles on Windows as NULL handles][93263] - [Make `std::io::stdio::lock()` return `'static` handles.][93965] Previously, the creation of locked handles to stdin/stdout/stderr would borrow the handles being locked, which prevented writing `let out = std::io::stdout().lock();` because `out` would outlive the return value of `stdout()`. Such code now works, eliminating a common pitfall that affected many Rust users. - [`Vec::from_raw_parts` is now less restrictive about its inputs][95016] - [`std::thread::available_parallelism` now takes cgroup quotas into account.][92697] Since `available_parallelism` is often used to create a thread pool for parallel computation, which may be CPU-bound for performance, `available_parallelism` will return a value consistent with the ability to use that many threads continuously, if possible. For instance, in a container with 8 virtual CPUs but quotas only allowing for 50% usage, `available_parallelism` will return 4. Stabilized APIs --------------- - [`Pin::static_mut`] - [`Pin::static_ref`] - [`Vec::retain_mut`] - [`VecDeque::retain_mut`] - [`Write` for `Cursor<[u8; N]>`][cursor-write-array] - [`std::os::unix::net::SocketAddr::from_pathname`] - [`std::process::ExitCode`] and [`std::process::Termination`]. The stabilization of these two API s now makes it possible for programs to return errors from `main` with custom exit codes. - [`std::thread::JoinHandle::is_finished`] These APIs are now usable in const contexts: - [`<*const T>::offset` and `<*mut T>::offset`][ptr-offset] - [`<*const T>::wrapping_offset` and `<*mut T>::wrapping_offset`] [ptr-wrapping_offset] - [`<*const T>::add` and `<*mut T>::add`][ptr-add] - [`<*const T>::sub` and `<*mut T>::sub`][ptr-sub] - [`<*const T>::wrapping_add` and `<*mut T>::wrapping_add`][ptr-wrapping_add] - [`<*const T>::wrapping_sub` and `<*mut T>::wrapping_sub`][ptr-wrapping_sub] - [`<[T]>::as_mut_ptr`][slice-as_mut_ptr] - [`<[T]>::as_ptr_range`][slice-as_ptr_range] - [`<[T]>::as_mut_ptr_range`][slice-as_mut_ptr_range] Cargo ----- No feature changes, but see compatibility notes. Compatibility Notes ------------------- - Previously native static libraries were linked as `whole-archive` in some cases, but now rustc tries not to use `whole-archive` unless explicitly requested. This [change][93901] may result in linking errors in some cases. To fix such errors, native libraries linked from the command line, build scripts, or [`#[link]` attributes][link-attr] need to - (more common) either be reordered to respect dependencies between them (if `a` depends on `b` then `a` should go first and `b` second) - (less common) or be updated to use the [`+whole-archive`] modifier. - [Catching a second unwind from FFI code while cleaning up from a Rust panic now causes the process to abort][92911] - [Proc macros no longer see `ident` matchers wrapped in groups][92472] - [The number of `#` in `r#` raw string literals is now required to be less than 256][95251] - [When checking that a dyn type satisfies a trait bound, supertrait bounds are now enforced][92285] - [`cargo vendor` now only accepts one value for each `--sync` flag] [cargo/10448] - [`cfg` predicates in `all()` and `any()` are always evaluated to detect errors, instead of short-circuiting.][94295] The compatibility considerations here arise in nightly-only code that used the short-circuiting behavior of `all` to write something like `cfg(all(feature = "nightly", syntax-requiring-nightly))`, which will now fail to compile. Instead, use either `cfg_attr(feature = "nightly", ...)` or nested uses of `cfg`. - [bootstrap: static-libstdcpp is now enabled by default, and can now be disabled when llvm-tools is enabled][94832] Internal Changes ---------------- These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc and related tools. - [debuginfo: Refactor debuginfo generation for types][94261] - [Remove the everybody loops pass][93913] [88375]: rust-lang/rust#88375 [89887]: rust-lang/rust#89887 [90621]: rust-lang/rust#90621 [92285]: rust-lang/rust#92285 [92472]: rust-lang/rust#92472 [92697]: rust-lang/rust#92697 [92714]: rust-lang/rust#92714 [92911]: rust-lang/rust#92911 [93263]: rust-lang/rust#93263 [93745]: rust-lang/rust#93745 [93827]: rust-lang/rust#93827 [93901]: rust-lang/rust#93901 [93913]: rust-lang/rust#93913 [93965]: rust-lang/rust#93965 [94081]: rust-lang/rust#94081 [94261]: rust-lang/rust#94261 [94295]: rust-lang/rust#94295 [94832]: rust-lang/rust#94832 [95016]: rust-lang/rust#95016 [95251]: rust-lang/rust#95251 [`+whole-archive`]: https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#linking-modifiers-whole-archive [`Pin::static_mut`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_mut [`Pin::static_ref`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_ref [`Vec::retain_mut`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.retain_mut [`VecDeque::retain_mut`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.retain_mut [`std::os::unix::net::SocketAddr::from_pathname`]: https://doc.rust-lang.org/stable/std/os/unix/net/struct.SocketAddr.html#method.from_pathname [`std::process::ExitCode`]: https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html [`std::process::Termination`]: https://doc.rust-lang.org/stable/std/process/trait.Termination.html [`std::thread::JoinHandle::is_finished`]: https://doc.rust-lang.org/stable/std/thread/struct.JoinHandle.html#method.is_finished [cargo/10448]: rust-lang/cargo#10448 [cursor-write-array]: https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#impl-Write-4 [link-attr]: https://doc.rust-lang.org/stable/reference/items/external-blocks.html#the-link-attribute [ptr-add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.add [ptr-offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset [ptr-sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.sub [ptr-wrapping_add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_add [ptr-wrapping_offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_offset [ptr-wrapping_sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_sub [slice-as_mut_ptr]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr [slice-as_mut_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr_range [slice-as_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_ptr_range [target_feature]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute
Pkgsrc changes: * Bump required GCC to 7 (same as LLVM) to avoid ABI issues Fixes native i386 and powerpc 8.x build w/pkgsrc LLVM 14 * Bump available bootstraps to 1.61.0. * Also unlimit stacksize * Sync patches over from wip/rust * Adjust line number in patches which had non-zero offsets. * no longer pass -I/usr/pkg/include through via gcc-wrap script when building natively. Attempt at fixing version skew with curl package vs. internal version of curl (may not work...) * The NetBSD bootstraps now use .xz compression. * Use mk/atomic64.mk. Still have conditional for libatomic-links. * Default to using the internal LLVM when cross-building. Upstream changes: Version 1.62.1 (2022-07-19) ========================== Rust 1.62.1 addresses a few recent regressions in the compiler and standard library, and also mitigates a CPU vulnerability on Intel SGX. * [The compiler fixed unsound function coercions involving `impl Trait` return types.][98608] * [The compiler fixed an incremental compilation bug with `async fn` lifetimes.][98890] * [Windows added a fallback for overlapped I/O in synchronous reads and writes.][98950] * [The `x86_64-fortanix-unknown-sgx` target added a mitigation for the MMIO stale data vulnerability][98126], advisory [INTEL-SA-00615]. [98608]: rust-lang/rust#98608 [98890]: rust-lang/rust#98890 [98950]: rust-lang/rust#98950 [98126]: rust-lang/rust#98126 [INTEL-SA-00615]: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00615.html Version 1.62.0 (2022-06-30) ========================== Language -------- - [Stabilize `#[derive(Default)]` on enums with a `#[default]` variant][94457] - [Stop validating some checks in dead code after functions with uninhabited return types][93313] - [Fix constants not getting dropped if part of a diverging expression][94775] - [Support unit struct/enum variant in destructuring assignment][95380] - [Remove mutable_borrow_reservation_conflict lint and allow the code pattern][96268] Compiler -------- - [linker: Stop using whole-archive on dependencies of dylibs][96436] - [Make `unaligned_references` lint deny-by-default][95372] This lint is also a future compatibility lint, and is expected to eventually become a hard error. - [Only add codegen backend to dep info if -Zbinary-dep-depinfo is used][93969] - [Reject `#[thread_local]` attribute on non-static items][95006] - [Add tier 3 `aarch64-pc-windows-gnullvm` and `x86_64-pc-windows-gnullvm` targets\*][94872] - [Implement a lint to warn about unused macro rules][96150] - [Promote `x86_64-unknown-none` target to Tier 2\*][95705] \* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Move `CStr` to libcore, and `CString` to liballoc][94079] - [Windows: Use a pipe relay for chaining pipes][95841] - [Replace Linux Mutex and Condvar with futex based ones.][95035] - [Replace RwLock by a futex based one on Linux][95801] - [std: directly use pthread in UNIX parker implementation][96393] Stabilized APIs --------------- - [`bool::then_some`] - [`f32::total_cmp`] - [`f64::total_cmp`] - [`Stdin::lines`] - [`windows::CommandExt::raw_arg`] - [`impl<T: Default> Default for AssertUnwindSafe<T>`] - [`From<Rc<str>> for Rc<[u8]>`][rc-u8-from-str] - [`From<Arc<str>> for Arc<[u8]>`][arc-u8-from-str] - [`FusedIterator for EncodeWide`] - [RDM intrinsics on aarch64][stdarch/1285] Clippy ------ - [Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions][94206] Cargo ----- - Added the `cargo add` command for adding dependencies to `Cargo.toml` from the command-line. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-add.html) - Package ID specs now support `name@version` syntax in addition to the previous `name:version` to align with the behavior in `cargo add` and other tools. `cargo install` and `cargo yank` also now support this syntax so the version does not need to passed as a separate flag. - The `git` and `registry` directories in Cargo's home directory (usually `~/.cargo`) are now marked as cache directories so that they are not included in backups or content indexing (on Windows). - Added automatic `@` argfile support, which will use "response files" if the command-line to `rustc` exceeds the operating system's limit. Compatibility Notes ------------------- - `cargo test` now passes `--target` to `rustdoc` if the specified target is the same as the host target. [#10594](rust-lang/cargo#10594) - [rustdoc: Remove .woff font files][96279] - [Enforce Copy bounds for repeat elements while considering lifetimes][95819] Internal Changes ---------------- - [Unify ReentrantMutex implementations across all platforms][96042] These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc and related tools. [93313]: rust-lang/rust#93313 [93969]: rust-lang/rust#93969 [94079]: rust-lang/rust#94079 [94206]: rust-lang/rust#94206 [94457]: rust-lang/rust#94457 [94775]: rust-lang/rust#94775 [94872]: rust-lang/rust#94872 [95006]: rust-lang/rust#95006 [95035]: rust-lang/rust#95035 [95372]: rust-lang/rust#95372 [95380]: rust-lang/rust#95380 [95431]: rust-lang/rust#95431 [95705]: rust-lang/rust#95705 [95801]: rust-lang/rust#95801 [95819]: rust-lang/rust#95819 [95841]: rust-lang/rust#95841 [96042]: rust-lang/rust#96042 [96150]: rust-lang/rust#96150 [96268]: rust-lang/rust#96268 [96279]: rust-lang/rust#96279 [96393]: rust-lang/rust#96393 [96436]: rust-lang/rust#96436 [96557]: rust-lang/rust#96557 [`bool::then_some`]: https://doc.rust-lang.org/stable/std/primitive.bool.html#method.then_some [`f32::total_cmp`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.total_cmp [`f64::total_cmp`]: https://doc.rust-lang.org/stable/std/primitive.f64.html#method.total_cmp [`Stdin::lines`]: https://doc.rust-lang.org/stable/std/io/struct.Stdin.html#method.lines [`impl<T: Default> Default for AssertUnwindSafe<T>`]: https://doc.rust-lang.org/stable/std/panic/struct.AssertUnwindSafe.html#impl-Default [rc-u8-from-str]: https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#impl-From%3CRc%3Cstr%3E%3E [arc-u8-from-str]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#impl-From%3CArc%3Cstr%3E%3E [stdarch/1285]: rust-lang/stdarch#1285 [`windows::CommandExt::raw_arg`]: https://doc.rust-lang.org/stable/std/os/windows/process/trait.CommandExt.html#tymethod.raw_arg [`FusedIterator for EncodeWide`]: https://doc.rust-lang.org/stable/std/os/windows/ffi/struct.EncodeWide.html#impl-FusedIterator Version 1.61.0 (2022-05-19) ========================== Language -------- - [`const fn` signatures can now include generic trait bounds][93827] - [`const fn` signatures can now use `impl Trait` in argument and return position][93827] - [Function pointers can now be created, cast, and passed around in a `const fn`][93827] - [Recursive calls can now set the value of a function's opaque `impl Trait` return type][94081] Compiler -------- - [Linking modifier syntax in `#[link]` attributes and on the command line, as well as the `whole-archive` modifier specifically, are now supported][93901] - [The `char` type is now described as UTF-32 in debuginfo][89887] - The [`#[target_feature]`][target_feature] attribute [can now be used with aarch64 features][90621] - X86 [`#[target_feature = "adx"]` is now stable][93745] Libraries --------- - [`ManuallyDrop<T>` is now documented to have the same layout as `T`][88375] - [`#[ignore = "#"]` messages are printed when running tests][92714] - [Consistently show absent stdio handles on Windows as NULL handles][93263] - [Make `std::io::stdio::lock()` return `'static` handles.][93965] Previously, the creation of locked handles to stdin/stdout/stderr would borrow the handles being locked, which prevented writing `let out = std::io::stdout().lock();` because `out` would outlive the return value of `stdout()`. Such code now works, eliminating a common pitfall that affected many Rust users. - [`Vec::from_raw_parts` is now less restrictive about its inputs][95016] - [`std::thread::available_parallelism` now takes cgroup quotas into account.][92697] Since `available_parallelism` is often used to create a thread pool for parallel computation, which may be CPU-bound for performance, `available_parallelism` will return a value consistent with the ability to use that many threads continuously, if possible. For instance, in a container with 8 virtual CPUs but quotas only allowing for 50% usage, `available_parallelism` will return 4. Stabilized APIs --------------- - [`Pin::static_mut`] - [`Pin::static_ref`] - [`Vec::retain_mut`] - [`VecDeque::retain_mut`] - [`Write` for `Cursor<[u8; N]>`][cursor-write-array] - [`std::os::unix::net::SocketAddr::from_pathname`] - [`std::process::ExitCode`] and [`std::process::Termination`]. The stabilization of these two API s now makes it possible for programs to return errors from `main` with custom exit codes. - [`std::thread::JoinHandle::is_finished`] These APIs are now usable in const contexts: - [`<*const T>::offset` and `<*mut T>::offset`][ptr-offset] - [`<*const T>::wrapping_offset` and `<*mut T>::wrapping_offset`] [ptr-wrapping_offset] - [`<*const T>::add` and `<*mut T>::add`][ptr-add] - [`<*const T>::sub` and `<*mut T>::sub`][ptr-sub] - [`<*const T>::wrapping_add` and `<*mut T>::wrapping_add`][ptr-wrapping_add] - [`<*const T>::wrapping_sub` and `<*mut T>::wrapping_sub`][ptr-wrapping_sub] - [`<[T]>::as_mut_ptr`][slice-as_mut_ptr] - [`<[T]>::as_ptr_range`][slice-as_ptr_range] - [`<[T]>::as_mut_ptr_range`][slice-as_mut_ptr_range] Cargo ----- No feature changes, but see compatibility notes. Compatibility Notes ------------------- - Previously native static libraries were linked as `whole-archive` in some cases, but now rustc tries not to use `whole-archive` unless explicitly requested. This [change][93901] may result in linking errors in some cases. To fix such errors, native libraries linked from the command line, build scripts, or [`#[link]` attributes][link-attr] need to - (more common) either be reordered to respect dependencies between them (if `a` depends on `b` then `a` should go first and `b` second) - (less common) or be updated to use the [`+whole-archive`] modifier. - [Catching a second unwind from FFI code while cleaning up from a Rust panic now causes the process to abort][92911] - [Proc macros no longer see `ident` matchers wrapped in groups][92472] - [The number of `#` in `r#` raw string literals is now required to be less than 256][95251] - [When checking that a dyn type satisfies a trait bound, supertrait bounds are now enforced][92285] - [`cargo vendor` now only accepts one value for each `--sync` flag] [cargo/10448] - [`cfg` predicates in `all()` and `any()` are always evaluated to detect errors, instead of short-circuiting.][94295] The compatibility considerations here arise in nightly-only code that used the short-circuiting behavior of `all` to write something like `cfg(all(feature = "nightly", syntax-requiring-nightly))`, which will now fail to compile. Instead, use either `cfg_attr(feature = "nightly", ...)` or nested uses of `cfg`. - [bootstrap: static-libstdcpp is now enabled by default, and can now be disabled when llvm-tools is enabled][94832] Internal Changes ---------------- These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc and related tools. - [debuginfo: Refactor debuginfo generation for types][94261] - [Remove the everybody loops pass][93913] [88375]: rust-lang/rust#88375 [89887]: rust-lang/rust#89887 [90621]: rust-lang/rust#90621 [92285]: rust-lang/rust#92285 [92472]: rust-lang/rust#92472 [92697]: rust-lang/rust#92697 [92714]: rust-lang/rust#92714 [92911]: rust-lang/rust#92911 [93263]: rust-lang/rust#93263 [93745]: rust-lang/rust#93745 [93827]: rust-lang/rust#93827 [93901]: rust-lang/rust#93901 [93913]: rust-lang/rust#93913 [93965]: rust-lang/rust#93965 [94081]: rust-lang/rust#94081 [94261]: rust-lang/rust#94261 [94295]: rust-lang/rust#94295 [94832]: rust-lang/rust#94832 [95016]: rust-lang/rust#95016 [95251]: rust-lang/rust#95251 [`+whole-archive`]: https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#linking-modifiers-whole-archive [`Pin::static_mut`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_mut [`Pin::static_ref`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_ref [`Vec::retain_mut`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.retain_mut [`VecDeque::retain_mut`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.retain_mut [`std::os::unix::net::SocketAddr::from_pathname`]: https://doc.rust-lang.org/stable/std/os/unix/net/struct.SocketAddr.html#method.from_pathname [`std::process::ExitCode`]: https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html [`std::process::Termination`]: https://doc.rust-lang.org/stable/std/process/trait.Termination.html [`std::thread::JoinHandle::is_finished`]: https://doc.rust-lang.org/stable/std/thread/struct.JoinHandle.html#method.is_finished [cargo/10448]: rust-lang/cargo#10448 [cursor-write-array]: https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#impl-Write-4 [link-attr]: https://doc.rust-lang.org/stable/reference/items/external-blocks.html#the-link-attribute [ptr-add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.add [ptr-offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset [ptr-sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.sub [ptr-wrapping_add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_add [ptr-wrapping_offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_offset [ptr-wrapping_sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_sub [slice-as_mut_ptr]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr [slice-as_mut_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr_range [slice-as_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_ptr_range [target_feature]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute
Since rust 1.61, the underlying const functions are available in stable rust, and lock_api >= 0.4.7 automatically uses them. (Feature const_fn_trait_bound, rust-lang/rust#93827) To avoid a breaking change, the features are still listed in Cargo.toml, but have no effect and are marked as deprecated. This bumps the minimum supported rust version to 1.61.
Since rust 1.61, the underlying const functions are available in stable rust, and lock_api >= 0.4.7 automatically uses them. (Feature const_fn_trait_bound, rust-lang/rust#93827) To avoid a breaking change, the features are still listed in Cargo.toml, but have no effect and are marked as deprecated. This bumps the minimum supported rust version to 1.61.
2988: Remove const_fn_trait_bound feature and update nightly (Mar 2022) r=lschuermann a=bradjc ### Pull Request Overview rust-lang/rust#93827 was merged, so there should soon be a nightly that allows us to remove `const_fn_trait_bound` feature. It seems like some of the tools we use aren't working right now, but this PR is a placeholder for when we can update to a new enough nightly. After this, our list of features looks like: ``` arch/cortex-m/src/lib.rs:#![feature(asm_sym)] arch/cortex-m/src/lib.rs:#![feature(naked_functions)] arch/cortex-m0/src/lib.rs:#![feature(asm_sym, naked_functions)] arch/cortex-m0p/src/lib.rs:#![feature(naked_functions)] arch/rv32i/src/lib.rs:#![feature(asm_sym, naked_functions)] boards/esp32-c3-devkitM-1/src/main.rs:#![feature(custom_test_frameworks)] boards/nano_rp2040_connect/src/main.rs:#![feature(naked_functions)] boards/opentitan/src/main.rs:#![feature(custom_test_frameworks)] boards/pico_explorer_base/src/main.rs:#![feature(naked_functions)] boards/raspberry_pi_pico/src/main.rs:#![feature(naked_functions)] chips/earlgrey/src/lib.rs:#![feature(naked_functions)] chips/esp32-c3/src/lib.rs:#![feature(naked_functions)] chips/litex_vexriscv/src/lib.rs:#![feature(asm_const)] chips/lowrisc/src/lib.rs:#![feature(const_mut_refs)] chips/swervolf-eh1/src/lib.rs:#![feature(naked_functions)] doc/courses/rustconf/application.md:#![feature(alloc)] kernel/src/lib.rs:#![feature(core_intrinsics)] libraries/riscv-csr/src/lib.rs:#![feature(asm_const)] libraries/tock-cells/src/lib.rs:#![feature(const_mut_refs)] ``` ### Testing Strategy travis ### TODO or Help Wanted Need a version of nightly with all valid tools. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Brad Campbell <[email protected]>
Stabilization Report
This PR serves as a request for stabilization for three const evaluation features:
const_fn_fn_ptr_basics
const_fn_trait_bound
const_impl_trait
These are being stabilized together because they are relatively minor and related updates to existing functionality.
const_fn_fn_ptr_basics
Allows creating, passing, and casting function pointers in a
const fn
.The following is an example of what is now allowed:
Casts between function pointer types are allowed, as well as transmuting from integers:
However, casting from a function pointer to an integer is not allowed:
Calling function pointers is also not allowed.
Test Coverage
The following tests include code that exercises this feature:
src/test/ui/consts/issue-37550.rs
src/test/ui/consts/issue-46553.rs
src/test/ui/consts/issue-56164.rs
src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs
src/test/ui/consts/min_const_fn/cast_fn.rs
src/test/ui/consts/min_const_fn/cmp_fn_pointers.rs
const_fn_trait_bound
Allows trait bounds in
const fn
. Additionally, this feature allows creating and passingdyn Trait
objects.Examples such as the following are allowed by this feature:
Previously only
Sized
was allowed as a trait bound.There is no way to call methods from the trait because trait methods cannot currently be marked as const. Allowing trait bounds in const functions does allow the const function to use the trait's associated types and constants.
This feature also allowes
dyn Trait
types. These work equivalently to non-const code. Similar to other pointers in const code, the value of adyn Trait
pointer cannot be observed.Note that due to #90912, it was already possible to do the example above as follows:
Test Coverage
The following tests include code that exercises
const_fn_trait_bound
:src/test/ui/consts/const-fn.rs
src/test/ui/consts/issue-88071.rs
src/test/ui/consts/min_const_fn/min_const_fn.rs
src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs
src/test/ui/nll/issue-55825-const-fn.rs
src/test/ui/rfc-2632-const-trait-impl/
also exercise this feature.const_impl_trait
Allows argument and return position
impl Trait
in aconst fn
, such as in the following example:Similar to generic parameters and function pointers, this allows the creation of such opaque types, but not doing anything with them beyond accessing associated types and constants.
Test Coverage
The following tests exercise this feature:
src/test/ui/type-alias-impl-trait/issue-53096.rs
src/test/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs
Documentation
These features are documented along with the other const evaluation features in the Rust Reference at https://doc.rust-lang.org/stable/reference/const_eval.html.
There is a PR that updates this documentation to reflect the capabilities enabled by these features at rust-lang/reference#1166.
Tracking issues: #57563, #63997, #93706