Skip to content

Commit a19aee9

Browse files
authored
Rollup merge of rust-lang#141811 - mejrs:bye_locals, r=compiler-errors
Unimplement unsized_locals Implements rust-lang/compiler-team#630 Tracking issue here: rust-lang#111942 Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`. There may be more that should be removed (possibly in follow up prs) - the `forget_unsized` function and `forget` intrinsic. - the `unsized_locals` test directory; I've just fixed up the tests for now - various codegen support for unsized values and allocas cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3`` ``@rustbot`` label F-unsized_locals Fixes rust-lang#79409
2 parents 2506df3 + 1b28bd0 commit a19aee9

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/src/mem/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,32 @@ pub const fn forget<T>(t: T) {
149149

150150
/// Like [`forget`], but also accepts unsized values.
151151
///
152-
/// This function is just a shim intended to be removed when the `unsized_locals` feature gets
153-
/// stabilized.
152+
/// While Rust does not permit unsized locals since its removal in [#111942] it is
153+
/// still possible to call functions with unsized values from a function argument
154+
/// or in-place construction.
155+
///
156+
/// ```rust
157+
/// #![feature(unsized_fn_params, forget_unsized)]
158+
/// #![allow(internal_features)]
159+
///
160+
/// use std::mem::forget_unsized;
161+
///
162+
/// pub fn in_place() {
163+
/// forget_unsized(*Box::<str>::from("str"));
164+
/// }
165+
///
166+
/// pub fn param(x: str) {
167+
/// forget_unsized(x);
168+
/// }
169+
/// ```
170+
///
171+
/// This works because the compiler will alter these functions to pass the parameter
172+
/// by reference instead. This trick is necessary to support `Box<dyn FnOnce()>: FnOnce()`.
173+
/// See [#68304] and [#71170] for more information.
174+
///
175+
/// [#111942]: https://github.com/rust-lang/rust/issues/111942
176+
/// [#68304]: https://github.com/rust-lang/rust/issues/68304
177+
/// [#71170]: https://github.com/rust-lang/rust/pull/71170
154178
#[inline]
155179
#[unstable(feature = "forget_unsized", issue = "none")]
156180
pub fn forget_unsized<T: ?Sized>(t: T) {

coretests/tests/ptr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ fn thin_box() {
653653
// if `{size,align}_of_for_meta<T: ?Sized>(T::Metadata)` are added.
654654
// * Constructing a `ThinBox` without consuming and deallocating a `Box`
655655
// requires either the unstable `Unsize` marker trait,
656-
// or the unstable `unsized_locals` language feature,
657656
// or taking `&dyn T` and restricting to `T: Copy`.
658657

659658
use std::alloc::*;

0 commit comments

Comments
 (0)