-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve safety warning on ptr::swap #38910
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
Conversation
@@ -74,7 +74,10 @@ pub const fn null_mut<T>() -> *mut T { 0 as *mut T } | |||
/// | |||
/// # Safety | |||
/// | |||
/// This is only unsafe because it accepts a raw pointer. | |||
/// This function copies the memory through the raw pointers passed to it | |||
/// as arguments, which means they will be dereferenced. |
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.
I don't think the warning is clear enough. I'd state something like:
"If the pointer is null or points to invalid data, the program will crash or have an undefined behaviour."
It seems very important to me to indicate the consequences.
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.
This is already defined at the language level; repeating it here feels extraneous.
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.
To say that it reads and writes through the raw pointers should be enough.
@bluss updated |
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.
LGTM. r=me if @bluss is satisfied.
@bors r=eddyb |
📌 Commit 95fe6ac has been approved by |
☀️ Test successful - status-appveyor, status-travis |
r? @eddyb @bluss , who I asked about this on IRC