Skip to content

Nightly rejects some macro-generated doc attribute values accepted by stable #85432

Closed
@Erutuon

Description

@Erutuon

A version of my crate parse-mediawiki-sql with macro-generated docs builds on stable, but errors out on nightly, where the error suggests that I fix the error by enabling #![feature(extended_key_value_attributes)].

Stable is cargo 1.52.0 (rust-lang/cargo@69767412a 2021-04-21), rustc 1.52.1 (9bc8c42 2021-05-09), nightly is cargo 1.54.0-nightly (rust-lang/cargo@070e459c2 2021-05-11), rustc 1.54.0-nightly (3e99439 2021-05-17).

The error occurs in a macro that generates a struct declaration with an implementation of a trait and calls another macro to take a string generated by another set of macros and put it into a doc attribute above the struct. Here are the lines containing the macro declarations.

The error looks like this:

error[E0658]: arbitrary expressions in key-value attributes are unstable
   --> src/schemas.rs:152:13
    |
152 |               database_table_doc!($table_name $(, $page)?),
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
274 | / impl_row_from_sql! {
275 | |     image
276 | |     Image<'input> {
277 | |         name: PageTitle,
...   |
293 | |     }
294 | | }
    | |_- in this macro invocation
    |
    = note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
    = help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable
    = note: this error originates in the macro `impl_row_from_sql` (in Nightly builds, run with -Z macro-backtrace for more info)

There are 22 calls to the macro, but only 13 errors, for the calls those whose contents start with $table_name:ident $output_type:ident<$life:lifetime>. I tried to generate a minimal example by copying the macros and one of the failing calls, but failed: this reduced version compiled on both stable and nightly in the playground.

Somehow this sequence of tokens causes the error in the crate but not in the smaller playground example. I don't know much about the internals of the compiler here so have no idea how to change the playground example to generate the error.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-criticalCritical priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions