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

[proc_macros]: _ as ident doesn't work #609

Closed
driftluo opened this issue Dec 14, 2021 · 3 comments · Fixed by #611
Closed

[proc_macros]: _ as ident doesn't work #609

driftluo opened this issue Dec 14, 2021 · 3 comments · Fixed by #611

Comments

@driftluo
Copy link

use jsonrpsee_proc_macros::rpc;
use bytes::Bytes;

#[rpc(server)]
pub trait ARpc {

    #[method(name = "a")]
    async fn a(&self, _: Bytes);
}

will report:

error: custom attribute panicked
   |
14 | #[rpc(server)]
   | ^^^^^^^^^^^^^^
   |
   = help: message: Identifier in signature must be an ident
@niklasad1
Copy link
Member

niklasad1 commented Dec 14, 2021

Indeed, _: Bytes as identifier doesn't work but _a: Bytes or __: Bytes works.

//cc @maciejhirsz

@niklasad1 niklasad1 changed the title proc_macros bug [proc_macros]: _ as idenitifer doesn't work Dec 14, 2021
@niklasad1 niklasad1 changed the title [proc_macros]: _ as idenitifer doesn't work [proc_macros]: _ as ident doesn't work Dec 14, 2021
dvdplm added a commit that referenced this issue Dec 14, 2021
* Better error messages for method arguments ignored with a `_`

Relates to #609

* Fix typo

* typo 2

* Update proc-macros/src/rpc_macro.rs

Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>

* Use proper span

* Use proper span (2)

Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
@dvdplm
Copy link
Contributor

dvdplm commented Dec 14, 2021

@driftluo Thank you for the report. We landed on not supporting _ as method argument name but improved the error handling to explain to users what happened a bit better.

@niklasad1
Copy link
Member

FYI, because the servers currently support both the params to be passed as array or JSON object these identifiers are used to generate named fields in the JSON objects.

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 a pull request may close this issue.

3 participants