rust-lang / rust-lang/rfcs

Extend macro_rules! to make macros with pre-bracket items

Open
#2,334 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Currently the macro_rules macro is used as the following:

macro_rules! name {
    pattern => code;
    ...
}

Which produces a macro that is used: name!{pattern}.

This proposal would allow for syntax within the macro_rules! macro creator for macros that have some patterns before the initial brackets. I think that it would also be nice if it was possible to control which of the three {}, [], () bracket types were allowed to be used with the with the macro, by default all three would be allowed.

As more information was requested, read below:

Motivation:
For some macros it would make sense for there to be a visual distinction between some parts of the macro. These are generally identifiers or other similar overarching aspects of them.

Explanation:
This is a proposal to facilitate both allowing some pattern matching before the start of the main brackets as well as which type(s) of brackets are allowed to be used. This would act similarly to how the macro_rules macro works where the identifier of the new macro is situated before the start of the brackets that contain the pattern branches.

Example:
Maybe not the best example but I believe that it shows the point rather well

unless! item.is_empty() { continue; }

Instead of something like the following (what is currently available easily):

unless! { item.is_empty() -> { continue; } }

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start with the issue's macro_rules! syntax examples and compare the proposed pre-bracket patterns and bracket restrictions with the current Rust macro behavior. The issue names no files or tests; done would require a settled proposal for the syntax and its allowed delimiters.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.