-
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
Add mem::forget_unsized() for forgetting unsized values #55785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,19 @@ pub fn forget<T>(t: T) { | |
ManuallyDrop::new(t); | ||
} | ||
|
||
/// Like [`forget`], but also accepts unsized values. | ||
/// | ||
/// This function is just a shim intended to be removed when the `unsized_locals` feature gets | ||
/// stabilized. | ||
/// | ||
/// [`forget`]: fn.forget.html | ||
#[inline] | ||
#[cfg(not(stage0))] | ||
#[unstable(feature = "forget_unsized", issue = "0")] | ||
pub fn forget_unsized<T: ?Sized>(t: T) { | ||
unsafe { intrinsics::forget(t) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, provided we implement support for unsized return values. The reason is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see, I was thinking in terms of construction. A There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, you're totally right. I think adding the pub fn forget_unsized<T: ?Sized>(t: T) {
ManuallyDrop { value: t };
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems I was wrong. It's still impossible to initialize structs with unsized fields, so we'll have to live with |
||
} | ||
|
||
/// Returns the size of a type in bytes. | ||
/// | ||
/// More specifically, this is the offset in bytes between successive elements | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in favor of making
mem::forget
support unsized types, I assume?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.