Skip to content

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

@nikht0

Description

@nikht0

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions