Skip to content

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

Merged
merged 2 commits into from
Jan 9, 2017
Merged

Conversation

steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Jan 7, 2017

r? @eddyb @bluss , who I asked about this on IRC

@@ -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.
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@steveklabnik
Copy link
Member Author

@bluss updated

Copy link
Member

@eddyb eddyb left a 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.

@bluss
Copy link
Member

bluss commented Jan 7, 2017

@bors r=eddyb

@bors
Copy link
Collaborator

bors commented Jan 7, 2017

📌 Commit 95fe6ac has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Jan 9, 2017

⌛ Testing commit 95fe6ac with merge aee21e2...

bors added a commit that referenced this pull request Jan 9, 2017
Improve safety warning on ptr::swap

r? @eddyb @bluss , who I asked about this on IRC
@bors
Copy link
Collaborator

bors commented Jan 9, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing aee21e2 to master...

@bors bors merged commit 95fe6ac into rust-lang:master Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants