Skip to content

Conversation

folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Sep 4, 2025

Putting this lint in /methods is simpler and probably slightly more efficient.

changelog: [ptr_offset_with_cast]: respect MSRV when suggesting fix, and lint even more cases

@rustbot
Copy link
Collaborator

rustbot commented Sep 4, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 4, 2025
Copy link

github-actions bot commented Sep 4, 2025

Lintcheck changes for f981739

Lint Added Removed Changed
clippy::ptr_offset_with_cast 0 0 2

This comment will be updated if you push new changes

@rustbot rustbot added S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work A-lint Area: New lints and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 4, 2025
@folkertdev
Copy link
Contributor Author

Hmm this time rustbot is mistaken, I'm moving a lint here, not adding a new one.

@ada4a
Copy link
Contributor

ada4a commented Sep 4, 2025

Yeah that's a bit annoying..

Here's the incantation to restore the order:
@rustbot label -A-lint -S-blocked S-waiting-on-review
@rustbot note remove Feature-freeze

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed A-lint Area: New lints S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work labels Sep 4, 2025
@folkertdev folkertdev force-pushed the cleanup-ptr-offset-with-cast branch 3 times, most recently from 117f43c to cdca4f4 Compare September 4, 2025 21:53
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Since this is a refactoring, some things might be made better as well.

For example:

  • ptr.offset(…) is available since 1.0.0, while ptr.add(…) is available only since 1.26.0. A MSRV check is necessary in order not to suggest unapplicable fixes.
  • Same happens with ptr.wrapping_offset(…) (1.16.0) and ptr.wrapping_add(…) (1.26.0).

Fortunately, all of those methods are const since the same version, so no special handling is necessary for const contexts.

Also, it would be preferable and more robust to use a multipart suggestion rather than building the new expression as a string:

  • Get the method span and replace it with the new method name
  • Compute the span of the as … part by truncating the cast expression span after the lhs and remove it

What do you think?

r? samueltardieu @rustbot author

View changes since this review

@rustbot rustbot assigned samueltardieu and unassigned Alexendoo Sep 14, 2025
@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 Sep 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 14, 2025

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

@folkertdev folkertdev force-pushed the cleanup-ptr-offset-with-cast branch 4 times, most recently from f1d9e61 to 5c0827f Compare September 14, 2025 10:31
@folkertdev
Copy link
Contributor Author

That all sounds good to me.

@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 Sep 14, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Looks good, except for the MSRV constant name which is too general. Also, could you add an example with &*const T so that we can ensure that this is properly detected and that the suggestion is sound?

View changes since this review

@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 Sep 14, 2025
@samueltardieu
Copy link
Member

samueltardieu commented Sep 14, 2025

I have edited the top-level comment to include a proper changelog as it will be included in the merge commit. For reference, the previous content was:

based on some comments by @ada4a in #15606. I copied the structure of this lint in that PR, so if that can be cleaned up, this can too.

Putting this lint in /methods is simpler and probably slightly more efficient.

changelog: none

@folkertdev folkertdev force-pushed the cleanup-ptr-offset-with-cast branch from 5c0827f to 4e2f5ea Compare September 14, 2025 13:30
@folkertdev
Copy link
Contributor Author

Went with POINTER_ADD_SUB_METHODS, that should be clear and also covers the subtraction for later.

@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 Sep 14, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

It looks good to me, except for the test which is not isolated (even though it is nice to see that this works fine with the double fix!).

View changes since this review

@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 Sep 14, 2025
@folkertdev folkertdev force-pushed the cleanup-ptr-offset-with-cast branch from 4e2f5ea to f981739 Compare September 14, 2025 14:49
@folkertdev
Copy link
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 Sep 14, 2025
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

@samueltardieu samueltardieu added this pull request to the merge queue Sep 14, 2025
Merged via the queue into rust-lang:master with commit 7a12684 Sep 14, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 14, 2025
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