rust-lang / rust-lang/rfcs

Macro to run a macro over each tuple type

Open
#1,365 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Originally filed by @joshtriplett:


In the course of implementing the Bounded trait for tuples (https://github.com/rust-lang/num/pull/89), I implemented a generic macro that runs the macro passed as its argument over every tuple type up to 20:

macro_rules! for_each_tuple_ {
 ( $m:ident !! ) => (
 $m! { }
 );
 ( $m:ident !! $h:ident, $($t:ident,)* ) => (
 $m! { $h $($t)* }
 for_each_tuple_! { $m !! $($t,)* }
 );
}
macro_rules! for_each_tuple {
 ( $m:ident ) => (
 for_each_tuple_! { $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, }
 );
}

There are other instances of this pattern in Rust libraries; for instance, see https://github.com/rust-lang/rust/blob/8f5b5f94dcdb9884737dfbc8efd893d1d70f0b14/src/libcore/hash/mod.rs#L239 and https://github.com/rust-lang/rust/blob/8f5b5f94dcdb9884737dfbc8efd893d1d70f0b14/src/libcore/hash/mod.rs#L259 . The latter could be replaced with for_each_tuple!(impl_hash_tuple);

Would it make sense to put something like this somewhere in the Rust standard libraries, marked as unstable since it depends on defining macros? This would be useful for anyone implementing traits on tuples.

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

Review the proposed macro pattern and the related tuple implementations in libcore/hash/mod.rs referenced by the issue. Determine whether a reusable standard-library facility for applying macros to tuple types is appropriate, including its unstable status and placement. Done means reaching and documenting a clear implementation or rejection decision.

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.