-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Document explicitly that Weak::from_raw(ptr::null()) is ub #114525
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2776,8 +2776,16 @@ impl<T: ?Sized> Weak<T> { | |
/// | ||
/// # Safety | ||
/// | ||
/// The pointer must have originated from the [`into_raw`] and must still own its potential | ||
/// weak reference, and `ptr` must point to a block of memory allocated by the global allocator. | ||
/// The pointer must have originated from the [`into_raw`] or [`into_raw_and_alloc`] functions | ||
/// and must still own its potential weak reference, and `ptr` must point to a block of | ||
/// memory allocated by `alloc`. | ||
/// | ||
/// Note that `from_raw` expects values that actually originated from a call to one of these | ||
/// functions and have not been used with `from_raw` yet, not what these functions can maybe | ||
/// return, or are documented to potentially return. | ||
/// For example, [`into_raw`] can return dangling pointers, but this doesn't allow you to create | ||
/// a dangling pointer yourself and pass it to `from_raw`. Even if it has the same address | ||
/// as a pointer created by [`into_raw`], use [`Weak::new`] instead. | ||
/// | ||
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this | ||
/// takes ownership of one weak reference currently represented as a raw pointer (the weak | ||
|
@@ -2806,6 +2814,7 @@ impl<T: ?Sized> Weak<T> { | |
/// ``` | ||
/// | ||
/// [`into_raw`]: Weak::into_raw | ||
/// [`into_raw_and_alloc`]: Weak::into_raw_and_alloc | ||
/// [`upgrade`]: Weak::upgrade | ||
/// [`new`]: Weak::new | ||
#[inline] | ||
|
@@ -2942,8 +2951,16 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> { | |
/// | ||
/// # Safety | ||
/// | ||
/// The pointer must have originated from the [`into_raw`] and must still own its potential | ||
/// weak reference, and `ptr` must point to a block of memory allocated by `alloc`. | ||
/// The pointer must have originated from the [`into_raw`] or [`into_raw_and_alloc`] functions | ||
/// and must still own its potential weak reference, and `ptr` must point to a block of | ||
/// memory allocated by `alloc`. | ||
/// | ||
/// Note that `from_raw` expects values that actually originated from a call to one of these | ||
/// functions and have not been used with `from_raw` yet, not what these functions can maybe | ||
/// return, or are documented to potentially return. | ||
/// For example, [`into_raw`] can return dangling pointers, but this doesn't allow you to create | ||
/// a dangling pointer yourself and pass it to `from_raw`. Even if it has the same address | ||
/// as a pointer created by [`into_raw`], use [`Weak::new`] instead. | ||
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. same diff as above |
||
/// | ||
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this | ||
/// takes ownership of one weak reference currently represented as a raw pointer (the weak | ||
|
@@ -2972,6 +2989,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> { | |
/// ``` | ||
/// | ||
/// [`into_raw`]: Weak::into_raw | ||
/// [`into_raw_and_alloc`]: Weak::into_raw_and_alloc | ||
/// [`upgrade`]: Weak::upgrade | ||
/// [`new`]: Weak::new | ||
#[inline] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2686,8 +2686,15 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> { | |
/// | ||
/// # Safety | ||
/// | ||
/// The pointer must have originated from the [`into_raw`] and must still own its potential | ||
/// weak reference, and must point to a block of memory allocated by `alloc`. | ||
/// The pointer must have originated from the [`into_raw`] function and must still own its | ||
/// potential weak reference, and must point to a block of memory allocated by `alloc`. | ||
/// | ||
/// Note that `from_raw_in` expects values that actually originated from a call to [`into_raw`] | ||
/// and have not been used with `from_raw` yet, not what [`into_raw`] can maybe return, | ||
/// or is documented to potentially return. | ||
/// For example, [`into_raw`] can return dangling pointers, but this doesn't allow you to create | ||
/// a dangling pointer yourself and pass it to `from_raw`. Even if it has the same address | ||
/// as a pointer created by [`into_raw`], use [`Weak::new`] instead. | ||
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. and yet another time |
||
/// | ||
/// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this | ||
/// takes ownership of one weak reference currently represented as a raw pointer (the weak | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.