Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining generics in a macro inside macro causes infinite indentation #6299

Open
maxcabrajac opened this issue Aug 29, 2024 · 1 comment
Open
Labels
a-macros bug Panic, non-idempotency, invalid code, etc.

Comments

@maxcabrajac
Copy link
Contributor

maxcabrajac commented Aug 29, 2024

macro_rules! example {
    (good) => {
        macro_rules! good {
            () => {
                A
            };
        }
    };
    (bad) => {
        macro_rules! bad {
            () => {
                A<'a>
            };
        }
    };
    (alsobad) => {
        macro_rules! bad {
            () => {
                A<B>
            };
        }
    };
}

Running multiple rounds of fmt in this causes both versions of bad's body to be indented indefinitely, but not good's.
Might be related to #4609, #5044 and other issues involving infinite indentation, but none of them mentioned generics.

@maxcabrajac maxcabrajac changed the title Defining lifetimes in a macro inside macro causes infinite indentation Defining generics in a macro inside macro causes infinite indentation Aug 29, 2024
@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. a-macros labels Aug 29, 2024
@Jhynjhiruu
Copy link

Jhynjhiruu commented Dec 6, 2024

It seems like it's related to parsing of things that aren't valid expressions going haywire; the same bug occurs with this example:

macro_rules! bug {
    () => {
        macro_rules! whee {
            () => {
                mut
            };
        }
    };
}

but also with ref, pub, &, @, #, =, | and various other punctuation characters in place of the mut. Essentially, if the body is a valid expression, no bug occurs, otherwise it will.

(Looks like almost this has been noticed before: #4609 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

3 participants