Skip to content

Divergent case: rustfmt increases indentation on each invocation in rustfmt::skip'd block #5555

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

Open
horazont opened this issue Oct 2, 2022 · 2 comments

Comments

@horazont
Copy link

horazont commented Oct 2, 2022

In the following example, rustfmt increases the indentation of the line with }); by one level each time it is run:

macro_rules! pwm_timer_init {
    ($tim:expr) => {{
        let tim = $tim;
        #[rustfmt::skip]
        tim.ccmr1_output().write(|w| {
            w
                .oc1pe().enabled()
                .oc1m().pwm_mode1()
                .oc2pe().enabled()
                .oc2m().pwm_mode1()
        });
    }};
}

This is also visible in the nightly version of the playground, though I found it with rustfmt 1.5.1-stable (4b91a6e 2022-08-08).

@ytmimi
Copy link
Contributor

ytmimi commented Oct 4, 2022

looking into this a little more, and I think this issue might have to do with the #[rustfmt::skip] attribute.

Input

macro_rules! pwm_timer_init {
    ($tim:expr) => {{
        let tim = $tim;
        tim.ccmr1_output().write(|w| {
            w
                .oc1pe().enabled()
                .oc1m().pwm_mode1()
                .oc2pe().enabled()
                .oc2m().pwm_mode1()
        });
    }};
}

Note: the }); is not indented in the following output after formatting with rustfmt 1.5.1-nightly (ef911542 2022-09-19)

Output

macro_rules! pwm_timer_init {
    ($tim:expr) => {{
        let tim = $tim;
        tim.ccmr1_output().write(|w| {
            w.oc1pe()
                .enabled()
                .oc1m()
                .pwm_mode1()
                .oc2pe()
                .enabled()
                .oc2m()
                .pwm_mode1()
        });
    }};
}

@ytmimi
Copy link
Contributor

ytmimi commented Oct 4, 2022

Similar issue (#5489), but might not be the same underlying problem.

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

No branches or pull requests

2 participants