Skip to content

Makes Clippy beta happy #5032

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

Merged
merged 3 commits into from
Apr 4, 2025
Merged

Makes Clippy beta happy #5032

merged 3 commits into from
Apr 4, 2025

Conversation

Tpt
Copy link
Contributor

@Tpt Tpt commented Apr 2, 2025

Makes Clippy happy

Use also Into::into instead of explicit cast

@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label Apr 2, 2025
@Tpt Tpt force-pushed the tpt/ptr-eq branch 3 times, most recently from fecf688 to 27ab224 Compare April 2, 2025 11:56
@@ -53,6 +53,7 @@ pub struct PyArg<'a> {
pub ty: &'a syn::Type,
}

#[allow(clippy::large_enum_variant)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to make Clippy happy

Copy link
Member

@mejrs mejrs Apr 2, 2025

Choose a reason for hiding this comment

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

We should consider addressing it. It seems that RegularArg is the big one here. We can probably put it or most of its fields behind a reference like the other variants.

Anyway that shouldn't block this PR, but please file an issue for it if we merge this as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can probably put it or most of its fields behind a reference like the other variants.

Yes, but it does not seems trivial and will require some refactoring. I have open #5039 about it.
Anyway, this is a structure we do not keep in memory for a while, I am not sure how much we care about its size.

@davidhewitt
Copy link
Member

Is this a clippy beta bug? It looks to me like this probably came from rust-lang/rust-clippy#14339

But this seems like a lot of ptr equality here is being needlessly modified when there is no references involved. Reference to ptr coercion seemed to be the original motivation of the lint... https://rust-lang.github.io/rust-clippy/stable/index.html#ptr_eq

Maybe we should report upstream?

@davidhewitt
Copy link
Member

Filed rust-lang/rust-clippy#14525, let's see the outcome of that...

@mejrs
Copy link
Member

mejrs commented Apr 2, 2025

I'd prefer to globally allow this lint. I find the increase in parentheses make it harder to read.

@davidhewitt
Copy link
Member

I agree, at least for pyo3-ffi. I think also similar to #4994 I would argue that there's no good reason for us to write this differently to the C implementations that we're replicating here.

@Tpt
Copy link
Contributor Author

Tpt commented Apr 3, 2025

Thank you for your feedback. I have reverted the changes in pyo3-ffi and allowed there the clippy::ptr_eq lint.

Reference to ptr coercion seemed to be the original motivation of the lint.

Yes! However, imho there is still value to use ptr::eq instead of ==: it makes cristal clear we are using pointer equality and not value equality via the PartialEq trait. If it's not obvious that arguments are pointers it increases readability.

Anyway, happy to revert the changes in pyo3 crate and add a global allow if you feel it's better.

@Tpt Tpt changed the title Use std::ptr::eq where relevant Makes Clippy beta happy Apr 3, 2025
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Yes! However, imho there is still value to use ptr::eq instead of ==: it makes cristal clear we are using pointer equality and not value equality via the PartialEq trait. If it's not obvious that arguments are pointers it increases readability.

I guess that's a reasonable argument. TBH I'm used to the fact that pointers don't do value equality, but I can see why clippy might want to encourage users to think about that.

@davidhewitt davidhewitt added this pull request to the merge queue Apr 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 4, 2025
@davidhewitt davidhewitt added this pull request to the merge queue Apr 4, 2025
Merged via the queue into PyO3:main with commit 90d5f56 Apr 4, 2025
53 checks passed
@Tpt Tpt deleted the tpt/ptr-eq branch April 4, 2025 15:19
davidhewitt pushed a commit that referenced this pull request Apr 4, 2025
* Use std::ptr::eq where relevant

* allow(clippy::ptr_eq) in pyo3-ffi

* Add ref for allow(clippy::large_enum_variant)
davidhewitt pushed a commit that referenced this pull request Apr 21, 2025
* Use std::ptr::eq where relevant

* allow(clippy::ptr_eq) in pyo3-ffi

* Add ref for allow(clippy::large_enum_variant)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants