Skip to content

Completing support for trailing commas in std macros #46241

Closed
@ExpHP

Description

@ExpHP

I really want to see complete support for trailing commas in std macros.

As I described on Internals, all (stable) "variadic" macros correctly support trailing commas for sufficiently long argument lists. It is only a few, select, specific argument counts that trip them up.

Here is a check list of all test cases that currently fail to compile:

Failing cases that obviously need fixing

These macros already support trailing commas when given longer argument lists, they just fail for these specific lengths:

  • {debug_,}assert!(true, );
  • {debug_,}assert!(true, "hello",);
  • {debug_,}assert_{eq,ne}!(1, 1,);
    • Status: Fixed in Beta
  • panic!("hello",);
  • writeln!(&mut stdout,);
  • unreachable!("hello",);

Worth discussion

These macros technically have not yet committed to the "function-call-like" syntax and we still currently have the option to extend these with an entirely different syntax. Like, I don't know, compile_error!("a" => b) or something.

  • include{,_bytes,_str}!("dumdum.rs",);
  • compile_error!("lel",);
  • try!(Ok(()),);
  • option_env!("PATH",);
    • note: env! handles the trailing comma so we might want this just for consistency's sake
  • cfg!(unix,);

Oddball cases

  • the unstable mpsc select! does not support trailing commas in general...
    • ...but it also contains numerous other papercuts and probably deserves an issue all of its own.

I offer to help with at least those macros which are implemented via macro_rules!.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions