Skip to content

New lint: nonnull_unchecked_on_box_ptr#17336

Open
ArhanChaudhary wants to merge 1 commit into
rust-lang:masterfrom
ArhanChaudhary:lint-nonnull_unchecked_on_box_ptr
Open

New lint: nonnull_unchecked_on_box_ptr#17336
ArhanChaudhary wants to merge 1 commit into
rust-lang:masterfrom
ArhanChaudhary:lint-nonnull_unchecked_on_box_ptr

Conversation

@ArhanChaudhary

@ArhanChaudhary ArhanChaudhary commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

changelog: [nonnull_unchecked_on_box_ptr]: implement new lint

Now that NonNull::from_mut is stable, we can check and suggest a fix against a common pattern: using unsafe { NonNull::new_unchecked(Box::into_raw(x)) } instead of NonNull::from_mut(Box::leak(x)). This was first mentioned in this comment.

  • Followed [lint naming conventions][lint_naming]
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 3, 2026
@rustbot

rustbot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

r? @Jarcho

rustbot has assigned @Jarcho.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@ArhanChaudhary ArhanChaudhary force-pushed the lint-nonnull_unchecked_on_box_ptr branch 2 times, most recently from 31e604e to d5ef013 Compare July 3, 2026 02:19

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can suggest NonNull::from instead of NonNull::from_mut which will bring the MSRV down to 1.26 (for Box::leak).

View changes since this review

Comment thread clippy_lints/src/nonnull_unchecked_on_box_ptr.rs Outdated
Comment thread clippy_lints/src/nonnull_unchecked_on_box_ptr.rs Outdated
Comment thread clippy_lints/src/nonnull_unchecked_on_box_ptr.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 4, 2026
@rustbot

rustbot commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Jarcho

Jarcho commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

@rustbot label lint-nominated

@rustbot rustbot added the lint-nominated Create an FCP-thread on Zulip for this PR label Jul 4, 2026
@rustbot

rustbot commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

This lint has been nominated for inclusion.

A FCP topic has been created on Zulip.

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

Note: this implementation will need to be updated to suggest Box::from_non_null (rust-lang/rust#130364) once that is merged.

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

@Jarcho How does this look?

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

I suggest from_mut if the MSRV matches. Do you think the lint description should mention from or from_mut?

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Lintcheck changes for 3a1e8f6

Lint Added Removed Changed
clippy::nonnull_unchecked_on_box_ptr 1 0 0

This comment will be updated if you push new changes

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 5, 2026
@rustbot

This comment has been minimized.

@ArhanChaudhary ArhanChaudhary force-pushed the lint-nonnull_unchecked_on_box_ptr branch from 698355c to 25f3a7e Compare July 6, 2026 17:50
@rustbot

This comment has been minimized.

@Jarcho Jarcho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implementation looks fine bar one nit. Can you squash the commits down please.

I'll leave this FCP open for a few more days before merging.

View changes since this review

Comment thread clippy_lints/src/nonnull_unchecked_on_box_ptr.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 11, 2026
@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

@rustbot squash

@ArhanChaudhary

Copy link
Copy Markdown
Contributor Author

Oh, this isn't bors, forgot

@ArhanChaudhary ArhanChaudhary force-pushed the lint-nonnull_unchecked_on_box_ptr branch from 96e70a6 to 05132ba Compare July 11, 2026 03:19
@rustbot

This comment has been minimized.

@ArhanChaudhary ArhanChaudhary force-pushed the lint-nonnull_unchecked_on_box_ptr branch from 05132ba to 3a1e8f6 Compare July 11, 2026 18:19
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lint-nominated Create an FCP-thread on Zulip for this PR needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants