fix(build): Remove ambiguity in service method call#327
Merged
LucioFranco merged 1 commit intohyperium:masterfrom Apr 9, 2020
Merged
fix(build): Remove ambiguity in service method call#327LucioFranco merged 1 commit intohyperium:masterfrom
LucioFranco merged 1 commit intohyperium:masterfrom
Conversation
When calling methods on Arc<MyService> where the method is also defined on Arc (e.g. drop and clone), calling inner.#method_ident(request) will actually attempt to call the Arc method instead of the method on the service, resulting in a compile error. This change removes the ambiguity by dereferencing the inner Arc.
LucioFranco
approved these changes
Apr 9, 2020
Member
LucioFranco
left a comment
There was a problem hiding this comment.
Great catch! and nice fix! I will get a bump release out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I have an existing proto with a method that was unfortunately named
Drop, and the tonic stub did not compile. When calling methods on Arc where the method is also defined onArc(e.g.dropandclone), callinginner.#method_ident(request)will actually attempt to call theArcmethod instead of the method on the service, resulting in a compile error when building the generated rust file.Here is an excerpt from a test proto, which I have added as tests/ambiguous_methods/proto/ambiguous_methods.proto:
Solution
This change removes the ambiguity by dereferencing the inner
Arc.An alternative fix would be to use the fully qualified syntax for method calls. I believe that this change should be good enough because
#server_traitis only known to be#server_trait : Send + Sync + 'static, andSyncandSenddefine no other methods.See also: my PR to grpc-rust for the exact same issue a year ago stepancheg/grpc-rust#142