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

Indentation in macros is handled oddly #4611

Closed
delbonis opened this issue Dec 28, 2020 · 4 comments
Closed

Indentation in macros is handled oddly #4611

delbonis opened this issue Dec 28, 2020 · 4 comments
Assignees

Comments

@delbonis
Copy link

Input

    tokio::select! {
	result = reader => {
            match result {
		Ok(v) => {
		    eprintln!(
                    "message: {}",
                    v
                    );
                },
		Err(_) => {
		    eprintln!(
                        "error: {}",
                        e
                    );
                },
            }
	},
	_ = writer => {
            // Comment
            eprintln!(
                "completed: {}",
                some_other_field
            );
	}
    }

This is basically what company-mode gives us. I edited it slightly from the actual code but preserved the indentation.

Output

    tokio::select! {
    result = reader => {
            match result {
        Ok(v) => {
            eprintln!(
            "message: {}",
            v
            );
        },
        Err(e) => {
            eprintln!(
            "error: {}",
            e
            );
        }
            }
    },
    _ = writer => {
            // Comment
            eprintln!(
                "completed: {}",
                some_other_field
            );
    }
    }

Expected output

Something that resembles the input.

Meta

  • rustfmt version: rustfmt 1.4.30-nightly (acd9486 2020-12-20)
  • From where did you install rustfmt?: rustup
@calebcartwright
Copy link
Member

Could you check to see if you have hard tabs in your original source (or more likely a mix of tabs/spaces) that are being converted to all spaces? rustfmt doesn't really format macro calls (outside a few cases with calls using parens instead of braces), so tabs --> spaces seems like the most likely cause

@alvatar
Copy link

alvatar commented Jan 27, 2023

Where was this completed @delbonis ? How can I use it? Formatting still doesn't work for the select macro.

@alishir
Copy link

alishir commented Sep 5, 2023

@alvatar I have the same issue, do you have any workaround?

@calebcartwright
Copy link
Member

rustfmt does not apply formatting rules to args when the call sites use brace delims, and the output should generally match the input. This particular issue was not about rustfmt applying formatting rules to the contents of the select macro, but that rustfmt was seemingly modifying the leading indentation of the input (though given the closure of the issue, I assume the cause of this was differing whitespace strategy of tabs vs. spaces in the input vs. the configuration values for e.g. hard_tabs).

There's no point in asking for macro-specific formatting here (you can subscribe/follow along at #8 for those discussions), and if you're seeing the exact behavior described in the original description of this issue while 100% confident you don't have the referenced tabs vs. spaces cause, then please open a new issue with a minimal, complete repro

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

5 participants