Skip to content

Rustfmt break macros which match on empty angle brackets #7136

Description

@JulianKnodt

Summary

If a macro needs empty angle brackets after an ident, rustfmt may end up deleting them.

I tried to format this code:

macro_rules! example {
    ($func: ident <>) => {{
        $func();
    }};
}

fn log() {
    println!("Hi");
}

fn main() {
    example!(log<>);
}

Expected behavior

The angle brackets should remain.

Actual behavior

The angle brackets are deleted, leading the code to no longer compile after formatting.

Configuration

Reproduces on the playground.

Reproduction Steps

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=4787f0b7d4242108cd3982d5c7748ba1

Meta

I checked if this bug was reported previously by looking for "angle brackets", and I didn't see any similar threads.

Activity

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-genericsArea: genericsA-macrosArea: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-invalid-codeIssue: formatting causes compile-pass code to compile-failI-unexpectedly-removes-codeIssue: unexpectedly removes code that we should not be removing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions