Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 5, 2025

Add a method Box::as_non_null which returns a NonNull pointer to the Box's contents.

Implemented as a static method Box::as_non_null(boxed) instead of boxed.as_non_null(), to avoid clashing with any as_non_null method on T, available via deref. This pattern follows stdlib.

@github-actions github-actions bot added the C-enhancement Category - New feature or request label Nov 5, 2025
Copy link
Member Author

overlookmotel commented Nov 5, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review November 5, 2025 12:38
Copilot AI review requested due to automatic review settings November 5, 2025 12:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new method as_non_null to the Box type that provides a non-consuming way to obtain a NonNull pointer to the box's contents.

Key Changes:

  • Added Box::as_non_null method that takes a reference to a Box and returns a NonNull pointer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 5, 2025

CodSpeed Performance Report

Merging #15321 will not alter performance

Comparing 11-05-feat_allocator_add_box_as_non_null_method (4114c3b) with main (70bf817)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (e0edaef) during the generation of this report, so 70bf817 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel force-pushed the 11-05-feat_allocator_add_box_as_non_null_method branch from d806f3c to f42e703 Compare November 5, 2025 12:44
@overlookmotel overlookmotel self-assigned this Nov 5, 2025
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 5, 2025

Merge activity

graphite-app bot pushed a commit that referenced this pull request Nov 5, 2025
Add a method `Box::as_non_null` which returns a `NonNull` pointer to the `Box`'s contents.

Implemented as a static method `Box::as_non_null(boxed)` instead of `boxed.as_non_null()`, to avoid clashing with any `as_non_null` method on `T`, available via deref. This pattern follows stdlib.
@graphite-app graphite-app bot force-pushed the 11-05-feat_allocator_add_box_as_non_null_method branch from f42e703 to 1274291 Compare November 5, 2025 13:46
graphite-app bot pushed a commit that referenced this pull request Nov 5, 2025
#15322)

Use `Box::as_non_null` method (added in #15321) to ensure that creating an `Address` from a `Box`, no intermediate reference to the contents of the `Box` is created. This is important in `Traverse` which has tight aliasing constraints.

Possibly `addr_of!` macro we used previously already ensured this, but I'm not 100% sure due to the double deref (`**`). Using `Box::as_non_null` is unambiguously safe.
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
@overlookmotel overlookmotel force-pushed the 11-05-feat_allocator_add_box_as_non_null_method branch 2 times, most recently from f93b292 to 4114c3b Compare November 5, 2025 15:26
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
Add a method `Box::as_non_null` which returns a `NonNull` pointer to the `Box`'s contents.

Implemented as a static method `Box::as_non_null(boxed)` instead of `boxed.as_non_null()`, to avoid clashing with any `as_non_null` method on `T`, available via deref. This pattern follows stdlib.
@graphite-app graphite-app bot force-pushed the 11-05-feat_allocator_add_box_as_non_null_method branch from 4114c3b to b401708 Compare November 5, 2025 15:41
graphite-app bot pushed a commit that referenced this pull request Nov 5, 2025
#15322)

Use `Box::as_non_null` method (added in #15321) to ensure that creating an `Address` from a `Box`, no intermediate reference to the contents of the `Box` is created. This is important in `Traverse` which has tight aliasing constraints.

Possibly `addr_of!` macro we used previously already ensured this, but I'm not 100% sure due to the double deref (`**`). Using `Box::as_non_null` is unambiguously safe.
@graphite-app graphite-app bot merged commit b401708 into main Nov 5, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 11-05-feat_allocator_add_box_as_non_null_method branch November 5, 2025 15:47
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants