cpubits: single 16 => { ... } macro arm fails expansion with error: no rules expected ','

Open Beginner friendly
#1,597 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start by locating the cpubits! macro definition in the cpubits crate and compare the expansion path for 16 => { ... } with the working 32 and 64 single-branch forms. The reproduction in the issue is the first thing to compile; done means it compiles while the listed working forms continue to compile.

Written by the indexing model from the issue text.

Description

Component

cpubits (v0.1.1)

Description

Calling the cpubits! macro with only the 16-bit branch (single 16) fails to expand at compile time with a syntax error. Other single-branch forms (32 => { ... } and 64 => { ... }), pairs, and the full triple compile as expected.

Minimal Reproduction Example
use cpubits::cpubits;

cpubits! {
    16 => {
        pub type Word = u16;
    }
}

fn main() {}
Compiler Output
error: no rules expected `,`
 --> src/main.rs:3:1
  |
3 | / cpubits! {
4 | |     16 => {
5 | |         pub type Word = u16;
6 | |     }
7 | | }
  | |_^ no rules expected this token in macro call
  |
  = note: this error originates in the macro `cpubits::cpubits`
Root Cause

During macro expansion of the single 16 => { ... } pattern, the macro inserts a comma after its first generated branch, but the internal two-branch/downstream matcher in cpubits! does not accept a comma at that position.

Observed shapes probe results:

  • single16: ❌ exit 1 (error: no rules expected ',')
  • single32: ✅ exit 0
  • single64: ✅ exit 0
  • group16_32: ✅ exit 0
  • group32_64: ✅ exit 0
  • pair16_32: ✅ exit 0
  • pair32_64: ✅ exit 0
  • triple: ✅ exit 0
Dominant language
Rust
Stars
688
Forks
177
Avg merge
2h 31m
Merged PRs (30d)
31

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RustCrypto/utils

All issues in RustCrypto/utils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.