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

unused_braces lint in Deserialize macro with braced GAT type conversion #2414

Closed
teor2345 opened this issue Mar 22, 2023 · 2 comments · Fixed by dtolnay/syn#1482
Closed

unused_braces lint in Deserialize macro with braced GAT type conversion #2414

teor2345 opened this issue Mar 22, 2023 · 2 comments · Fixed by dtolnay/syn#1482

Comments

@teor2345
Copy link

When I derive Deserialize on a struct containing a generic associated type with a braced type conversion, I get an unused_braces warning.

This started happening in my CI when I upgraded to serde 1.0.158 with Rust 1.68. I can reproduce it locally with older serde versions, but I can't reproduce it in a playground with older versions. So I might be missing a reproduction step.

Here is the code:

#[derive(Deserialize)]
struct FooDeserializable {
    item: Generic<{ BAR as u8 }>,
}

And the warning I get:

    warning: unnecessary braces around block return value
      --> src/main.rs:16:19
       |
    16 |     item: Generic<{ BAR as u8 }>,
       |                   ^^         ^^
       |
       = note: `#[warn(unused_braces)]` on by default
    help: remove these braces
       |
    16 -     item: Generic<{ BAR as u8 }>,
    16 +     item: Generic<BAR as u8>,
       |

The fix itself is wrong, so I'll also report a Rust bug.

Here's the full (local) reproduction code, but the playground itself doesn't show the warning:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=98ec53a2a8de5c14af46d88f45feda1c

@teor2345
Copy link
Author

Here's the corresponding Rust bug for the incorrect fix suggestion:
rust-lang/rust#109473

@dtolnay
Copy link
Member

dtolnay commented Jul 9, 2023

Fixed in serde_derive 1.0.169.

crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Jul 10, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [serde](https://serde.rs) ([source](https://github.com/serde-rs/serde)) | dependencies | patch | `1.0.167` -> `1.0.171` |

---

### Release Notes

<details>
<summary>serde-rs/serde (serde)</summary>

### [`v1.0.171`](https://github.com/serde-rs/serde/releases/tag/v1.0.171)

[Compare Source](serde-rs/serde@v1.0.170...v1.0.171)

-   Support `derive(Deserialize)` on unit structs that have const generics ([#&#8203;2500](serde-rs/serde#2500), thanks [@&#8203;Baptistemontan](https://github.com/Baptistemontan))

### [`v1.0.170`](https://github.com/serde-rs/serde/releases/tag/v1.0.170)

[Compare Source](serde-rs/serde@v1.0.169...v1.0.170)

-   Produce error message on suffixed string literals inside serde attributes ([#&#8203;2242](serde-rs/serde#2242))
-   Support single identifier as unbraced default value for const generic parameter ([#&#8203;2449](serde-rs/serde#2449))

### [`v1.0.169`](https://github.com/serde-rs/serde/releases/tag/v1.0.169)

[Compare Source](serde-rs/serde@v1.0.168...v1.0.169)

-   Add Deserializer::deserialize_identifier support for adjacently tagged enums ([#&#8203;2475](serde-rs/serde#2475), thanks [@&#8203;Baptistemontan](https://github.com/Baptistemontan))
-   Fix unused_braces lint in generated Deserialize impl that uses braced const generic expressions ([#&#8203;2414](serde-rs/serde#2414))

### [`v1.0.168`](https://github.com/serde-rs/serde/releases/tag/v1.0.168)

[Compare Source](serde-rs/serde@v1.0.167...v1.0.168)

-   Allow `serde::de::IgnoredAny` to be the type for a `serde(flatten)` field ([#&#8203;2436](serde-rs/serde#2436), thanks [@&#8203;Mingun](https://github.com/Mingun))
-   Allow larger preallocated capacity for smaller elements ([#&#8203;2494](serde-rs/serde#2494))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi42LjAiLCJ1cGRhdGVkSW5WZXIiOiIzNi42LjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1959
Reviewed-by: crapStone <crapstone01@gmail.com>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants