Skip to content
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

tonic-build: use unified syntax to clone Arcs #1182

Merged
merged 1 commit into from
Dec 13, 2022
Merged

tonic-build: use unified syntax to clone Arcs #1182

merged 1 commit into from
Dec 13, 2022

Conversation

teskje
Copy link
Contributor

@teskje teskje commented Dec 9, 2022

This PR changes the generated code to use the unified function syntax for cloning Arc values (Arc::clone(foo) instead of foo.clone()).

Motivation

In https://github.com/MaterializeInc/materialize, we use tonic, and we also enforce the clippy lint clone_on_ref_ptr. This lint currently triggers on code generated by tonic, which forces us to disable it for modules that import tonic-generated code.

The main motivation for this PR is that we don't have to disable the lint anymore. Using unified function syntax when cloning Arcs also makes the code more obvious, which is nice.

Solution

Adjust the generated code to conform with the style clippy proposes.

@teskje teskje marked this pull request as ready for review December 9, 2022 17:20
@teskje
Copy link
Contributor Author

teskje commented Dec 9, 2022

This changes generated code, so I'm expecting some tests to break. I'm relying on CI to run the tests and tell me which break, so I can fix them. LMK if I should figure out how to run them myself instead!

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@LucioFranco
Copy link
Member

Youll need to run the bootstrap test and commit the generated code to get CI to pass. then we can merge thanks!

@teskje
Copy link
Contributor Author

teskje commented Dec 12, 2022

Thanks @LucioFranco! I've done that now, but I'm not entirely sure my changes are correct. They are different from what the CI output showed, and they are not related to the code changes I made either.

Edit: I get the same diffs after running the tests on master, which definitely seems wrong!

@LucioFranco
Copy link
Member

how are you running the tests?

@davidpdrsn
Copy link
Member

nitpick: Its called "Fully Qualified Syntax" rather than "Unified Syntax". See https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name

@teskje
Copy link
Contributor Author

teskje commented Dec 13, 2022

how are you running the tests?

On a clean checkout, I simply run cargo test. I'm on macOs, in case that matters, with protobuf (3.21.11) installed via homebrew.

nitpick: Its called "Fully Qualified Syntax" rather than "Unified Syntax".

I suppose you are right. I took the term from the clippy lint, no idea where they got it from. It was called "universal function call syntax" at one point.

@davidpdrsn
Copy link
Member

I suppose you are right. I took the term from the clippy lint, no idea where they got it from. It was called "universal function call syntax" at one point.

Ah I see. I guess it has several names :P

@tottoto
Copy link
Collaborator

tottoto commented Dec 13, 2022

The diffs (alerted in the ci) are caused by new version of prost-build 0.11.4. I think it will be fixed in #1181.

@tottoto
Copy link
Collaborator

tottoto commented Dec 13, 2022

And some docs changes in a684e51 might be caused by lack of cleanup-markdown feature of tonic-build in reflection manifest. It will be fixed in #1181 too.

@LucioFranco
Copy link
Member

I had to run cargo update locally as well to get the new version of prost but that should be fixed now that #1181 is merged.

The purpose is to prevent the `clone_on_ref_ptr` clippy lint from
triggering on code generated by tonic.
@teskje
Copy link
Contributor Author

teskje commented Dec 13, 2022

Thanks, removing the second commit, cargo updateing, and rebasing on the latest master made the checks pass for me locally.

@LucioFranco LucioFranco merged commit 25ea473 into hyperium:master Dec 13, 2022
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.

4 participants