Skip to content
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

restate GlobalAlloc method safety preconditions in terms of what the caller has to do for greater clarity #123932

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adamse
Copy link
Contributor

@adamse adamse commented Apr 14, 2024

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2024

r? @m-ou-se

rustbot has assigned @m-ou-se.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 14, 2024
Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>
@@ -221,20 +222,21 @@ pub unsafe trait GlobalAlloc {
///
/// # Safety
///
/// This function is unsafe because undefined behavior can result
/// if the caller does not ensure all of the following:
/// The caller has to ensure that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The caller has to ensure that
/// The caller must ensure that:

@@ -157,14 +157,14 @@ pub unsafe trait GlobalAlloc {
///
/// # Safety
///
/// This function is unsafe because undefined behavior can result
/// if the caller does not ensure all of the following:
/// The caller has to ensure that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The caller has to ensure that
/// The caller must ensure that:

must is a bit stronger than has to

/// equal to `isize::MAX`).
///
/// Otherwise undefined behaviour can result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Otherwise undefined behaviour can result.
/// If these are not followed, undefined behaviour can result.

Just clarify what otherwise refers to.

Comment on lines +128 to +129
/// The caller has to ensure that `layout` has non-zero size. Zero sized
/// `layout` can result in undefined behaviour.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup is nice, but I don't think specifying "the caller" adds much here. Maybe something like:

    /// `layout` must have non-zero size. Attempting to allocate for a zero-sized
    /// `layout` may result in undefined behavior.

(optional nit)

@tgross35
Copy link
Contributor

@rustbot author

Thanks for these changes, a few suggestions. Just comment @rustbot ready when you are all set.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2024
@tgross35 tgross35 assigned tgross35 and unassigned m-ou-se Jul 16, 2024
@bors
Copy link
Contributor

bors commented Jul 28, 2024

☔ The latest upstream changes (presumably #128313) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants