Skip to content

Regression: spurious "error: expected ," in serde::Serialize on macro_rules-variable path enum discriminant #72608

Closed

Description

Somewhat minimized test case: (still involves serde_derive and syn)

[dependencies]
serde = {version = "1", features = ["derive"]}
syn = { version = "1", features = ["full"] }
mod gl {
    pub const DEPTH_COMPONENT: isize = 0;
}

macro_rules! gl_enums {
    ($mod:ident) => {
        #[derive(serde::Serialize)]
        pub enum TexFormat {
            DepthComponent = $mod::DEPTH_COMPONENT
        }
    }
}

gl_enums!(gl);

Compiles in nightly-2020-05-24, errors in nightly-2020-05-25:

$ cargo +nightly-2020-05-25 rustc -- -Z macro-backtrace
   Compiling proc-macro2 v1.0.17
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.25
   Compiling serde v1.0.110
   Compiling quote v1.0.6
   Compiling serde_derive v1.0.110
   Compiling aa v0.1.0 (/tmp/aa)
error: expected `,`
  --> src/lib.rs:9:34
   |
5  | / macro_rules! gl_enums {
6  | |     ($mod:ident) => {
7  | |         #[derive(serde::Serialize)]
8  | |         pub enum TexFormat {
9  | |             DepthComponent = $mod::DEPTH_COMPONENT
   | |                                  ^^
10 | |         }
11 | |     }
12 | | }
   | |_- in this expansion of `gl_enums!`
13 | 
14 |   gl_enums!(gl);
   |   -------------- in this macro invocation

error: aborting due to previous error

Any of these changes makes compilation succeed:

  • Removing use of serde::Serialize
  • Disabling the syn/full feature
  • Replacing $mod with a non-variable module name
  • Replacing the path expression with a { use $mod::DEPTH_COMPONENT; DEPTH_COMPONENT } block

Regression range: 8970e8b...46e85b4. Merges:

Excluding those that seem unrelated to me leaves:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleP-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions