Skip to content

attribute macro arguments #7172

Open

Description

@sarah-quinones

zulip thread: #t-rustfmt > attribute macro args

Feature Request

add an unstable option for formatting attribut macro arguments following the same rules as function-like macro arguments
i.e. #[my_macro<DELIMITED_TOKENS>] would be formatted similarly to my_macro!<DELIMITED_TOKENs> (i.e. try parsing as an expr/type/pattern if possible)

Motivation

most verification tools for rust take function contracts in the form of attribute macros (#[verus_spec(...)], #[creusot_std::macros::requires(...)] are the first examples that come to mind). their input syntax slightly differs from rust code (e.g. ==> for implication), but that's out of the scope for this issue, and can be addressed by the macro authors if needed. im currently working with creusot devs to improve the situation on this front.

because rustfmt currently skips formatting of complex expressions, the burden of formatting the specification code falls on the user and quickly becomes a chore

Related configuration options

none, to my knowledge

Activity

  1. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Oct 10, 2026
  2. added
    A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)
    P-lowLow priority
    and removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Oct 10, 2026
  3. ytmimi commented on Oct 14, 2026

    @ytmimi
    Contributor

    @sarah-quinones can you post an example code snippet of code you'd like rustfmt to be able to format? I'm also not sure if this is a feature request or just a current limit in rustfmt that could be addressed.

  4. sarah-quinones commented on Oct 14, 2026

    @sarah-quinones
    Author

    example code

    #[requires(x    + 3 == 10)]
    fn add(x: u32) {}

    should format the requires-clause

    #[requires(x + 3 == 10)]
    fn add(x: u32) {}
  5. sarah-quinones commented on Oct 15, 2026

    @sarah-quinones
    Author

    would it be okay for me to open a pr with an implementation for this?

  6. ytmimi commented on Oct 15, 2026

    @ytmimi
    Contributor

    Sure, I can take a look

  7. sarah-quinones commented on Oct 15, 2026

    @sarah-quinones
    Author

    sweet! i'll get working on it after work

  8. ytmimi commented on Oct 15, 2026

    @ytmimi
    Contributor

    sweet! i'll get working on it after work

    Before you get started, I was wondering if you're still thinking of adding a new option for this or not? If so, could you outline how you'd expect that to work?

    My initial thought is that we don't need a new option for this, but I'd like to better understand what you're thinking.

  9. sarah-quinones commented on Oct 15, 2026

    @sarah-quinones
    Author

    the reason i was thinking of adding a new option is for backward compatibility but i'm fine with just making it unconditional if that's preferable

  10. ytmimi commented on Oct 15, 2026

    @ytmimi
    Contributor

    @sarah-quinones we'd likely need to add a style_edition gate so that we don't introduce breaking formatting changes on a stable release channel.

    In addition to the style-edition gate we could also consider adding a nightly-only check that could enable the formatting too. We have a similar nightly-only check in place for cfg_select! while we're trying to nail down that formatting implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: attributesA-macrosArea: macros (procedural macros, macro_rules! macros, etc.)C-feature-requestCategory: a feature request (not decided/implemented)P-lowLow priority

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions