File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -149,8 +149,32 @@ pub const fn forget<T>(t: T) {
149
149
150
150
/// Like [`forget`], but also accepts unsized values.
151
151
///
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
154
178
#[ inline]
155
179
#[ unstable( feature = "forget_unsized" , issue = "none" ) ]
156
180
pub fn forget_unsized < T : ?Sized > ( t : T ) {
Original file line number Diff line number Diff line change @@ -653,7 +653,6 @@ fn thin_box() {
653
653
// if `{size,align}_of_for_meta<T: ?Sized>(T::Metadata)` are added.
654
654
// * Constructing a `ThinBox` without consuming and deallocating a `Box`
655
655
// requires either the unstable `Unsize` marker trait,
656
- // or the unstable `unsized_locals` language feature,
657
656
// or taking `&dyn T` and restricting to `T: Copy`.
658
657
659
658
use std:: alloc:: * ;
You can’t perform that action at this time.
0 commit comments