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

Incorrect pattern binding mode in generated code for Rust 2024 edition #69

Open
nikht0 opened this issue Feb 3, 2025 · 1 comment
Open

Comments

@nikht0
Copy link

nikht0 commented Feb 3, 2025

Hello there,

Great crate, thanks ! I'm working with a nightly compiler, and I noticed the crate relies on implicit default binding modes, which has changed in Rust 2024 (the compiler error is unclear, see rust-lang/rust#136456 ).

Actual behavior :

For a struct Foo { x: u32 } the structure.each_variant(...) and structure.each(...) produces code that looks like

match self {
    Foo { x: ref __binding_0  } => { ... }
}

Resulting in the compiler error like :

error: this pattern relies on behavior which may change in edition 2024
  |
4 | #[derive(SomeDeriveMacro)]
  |          ^
  |          |
  |          default binding mode is reset within expansion
  |          default binding mode is reset within expansion
  |
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
  = note: this error originates in the derive macro `derive_debug::Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this pattern relies on behavior which may change in edition 2024
    |
109 |             Foo { x: ref __binding_0 } => { Ok(()) }
    |                      ^^^ cannot override to bind by-reference when that is the implicit default
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
help: make the implied reference patterns explicit

Expected behavior :

Just need to add the &.

match self {
    &Foo { x: ref __binding_0  } => { ... }
}

Cheers,

@DCNick3
Copy link

DCNick3 commented Feb 20, 2025

You can also change self to *self in the match expression. With this I was able to make the code compile in 2024 edition without any changes to synstructure.

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

No branches or pull requests

2 participants