Skip to content

clippy: Add safety documentation and clean up unsafe methods#33748

Merged
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:safety-docs
Oct 16, 2024
Merged

clippy: Add safety documentation and clean up unsafe methods#33748
mrobinson merged 1 commit intoservo:mainfrom
mrobinson:safety-docs

Conversation

@mrobinson
Copy link
Copy Markdown
Member

This change:

  1. Adds safety documentation where it was missing.
  2. Limits the scope of unsafe code in some cases to where it is actually
    unsafe.
  3. Converts some free functions to associated functions and methods,
    thereby making them more likely to be called safely.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because it should not change behavior.

///
/// # Safety
///
/// The address pointed to by `address` should point to a valid node in memory.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems redundant given that the documenation for TrustedNodeAddress claims that it represents a valid Node address. Perhaps this is still needed since the field in TrustedNodeAddress is public, but I wonder if that should be made private?

Also, are there no other conditions that need to be highlighted in this safety section? As an example (I'm not really familiar with this code), is there anything to be said about whether or not the DOM node is already rooted?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately, I don't think we can make those kind of guarantees as TrustedNodeAddress is sent over IPC channels. This is all very bad, of course, and we should remove TrustedNodeAddress entirely, but that's a much larger task.

This change:

1. Adds safety documentation where it was missing.
2. Limits the scope of unsafe code in some cases to where it is actually
   unsafe.
3. Converts some free functions to associated functions and methods,
   thereby making them more likely to be called safely.

Signed-off-by: Martin Robinson <[email protected]>
@mrobinson mrobinson added this pull request to the merge queue Oct 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 16, 2024
@mrobinson mrobinson added this pull request to the merge queue Oct 16, 2024
Merged via the queue into servo:main with commit 30abb99 Oct 16, 2024
@mrobinson mrobinson deleted the safety-docs branch October 16, 2024 09:04
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.

3 participants