Skip to content

codegen: qualify prelude names in generated service code - #329

Open
iainmcgin wants to merge 1 commit into
mainfrom
codegen-name-deconflict
Open

iainmcgin wants to merge 1 commit into
mainfrom
codegen-name-deconflict

Conversation

@iainmcgin

Copy link
Copy Markdown
Collaborator

Generated service code shares a Rust module with the package's service traits and, in connectrpc-build output, its messages and enums, and each generated module has use super::*;. A proto item named after a prelude item, in the package or a parent package, therefore shadows it. The templates wrote Result, Option, Box, Send, Sync, Clone and Into without a path, so Arrow Flight's message Result fails on every client method:

error[E0107]: struct takes 0 generic arguments but 2 generic arguments were supplied

The templates now write a ::std::… path for everything the stubs do not declare, Some, None and Ok included. Users with checked-in stubs regenerate: every *.__connect.rs file changes in that form only, and the generated API stays the same.

A message, service or sub-package named S or T resolved to a generic parameter of the generated impl blocks, and is now written self::S. The alternative is renaming the parameters to __S and __T, which changes the rustdoc of every generated client and server.

A glob import of such a package still shadows Result in the user's own module; the guide now says to import the module under an alias. The guide's rule for colliding service names said "differ only in case", which Xget and XGet disprove, and is reworded.

Conflicts with #324 in one hunk of codegen.rs and two test files. The second to merge regenerates the checked-in stubs.

Generated service code shares a Rust module with the package's service
traits and, in connectrpc-build output, its messages and enums, and each
generated module has `use super::*;`. A proto item named after a prelude
item, in the package or a parent package, therefore shadows it. The
templates wrote `Result`, `Option`, `Box`, `Send`, `Sync`, `Clone` and
`Into` without a path, so `message Result` (as in Arrow Flight) failed
with E0107 on every client method.

The templates now write a `::std::...` path for everything the stubs do
not declare, `Some`, `None` and `Ok` included. A message, service or
sub-package named `S` or `T`, the generic parameters of the generated
`impl` blocks, is written `self::S`.

`stubs_resolve_only_their_own_names` fails when a template names a type,
trait or module that the stubs do not declare without a `::` root.

Signed-off-by: Iain McGinniss <309153+iainmcgin@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant