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

nanoserde: fix compile error when using proxy as a struct annotation #115

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

Adjective-Object
Copy link
Contributor

It looks like proxying structs was originally intended to be implemented, but when I tried it out, it produced code that failed to compile with the following warning:

error[E0308]: mismatched types
   --> crates/nanoserde/tests/json.rs:960:14
    |
960 |     #[derive(DeJson, SerJson, PartialEq, Debug)]
    |              ^^^^^^
    |              |
    |              expected `&str`, found `&mut Chars<'_>`
    |              arguments to this function are incorrect
    |
    = note:      expected reference `&str`
            found mutable reference `&mut Chars<'_>`
note: associated function defined here
   --> /workspaces/macroquad-test/crates/nanoserde/src/serde_json.rs:82:8
    |
82  |     fn deserialize_json(input: &str) -> Result<Self, DeJsonErr> {
    |        ^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `DeJson` (in Nightly builds, run with -Z macro-backtrace for more info)

This change fixes the issue, and adds a test to defend it against future breaks.

It looks like json object proxying was originally intended to be implemented, but it wasn't by tests, and produced code that failed to compile with the following warning:

```
error[E0308]: mismatched types
   --> crates/nanoserde/tests/json.rs:960:14
    |
960 |     #[derive(DeJson, SerJson, PartialEq, Debug)]
    |              ^^^^^^
    |              |
    |              expected `&str`, found `&mut Chars<'_>`
    |              arguments to this function are incorrect
    |
    = note:      expected reference `&str`
            found mutable reference `&mut Chars<'_>`
note: associated function defined here
   --> /workspaces/macroquad-test/crates/nanoserde/src/serde_json.rs:82:8
    |
82  |     fn deserialize_json(input: &str) -> Result<Self, DeJsonErr> {
    |        ^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `DeJson` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This change should fix that.
@knickish
Copy link
Collaborator

knickish commented Oct 7, 2024

Thanks, this is a good catch

@knickish knickish merged commit 48aa068 into not-fl3:master Oct 7, 2024
16 checks passed
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.

2 participants