Skip to content

Incorrect indentation when using return in a macro #3936

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

Closed
stevenroose opened this issue Nov 21, 2019 · 6 comments · Fixed by #4189
Closed

Incorrect indentation when using return in a macro #3936

stevenroose opened this issue Nov 21, 2019 · 6 comments · Fixed by #4189
Labels
a-macros only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@stevenroose
Copy link

This macros is formatted using rustfmt:

macro_rules! m {
	($a:expr) => {
		if $a {
			return;
			}
	};
}

That closing curly bracket under the return clearly has to be one indented one level less.

Config used:

hard_tabs = true
use_small_heuristics = "Off"
@calebcartwright
Copy link
Member

I can reproduce this one with the latest rustfmt version, but only when hard_tabs is set to true

@scampi scampi added a-macros only-with-option requires a non-default option value to reproduce poor-formatting labels Nov 22, 2019
@stevenroose
Copy link
Author

Seriously? That's not a good sign.. I would expect rustfmt internally to just specify levels of indentation and afterwards convert that into actual tabs/spaces. Does rustfmt have an option to specify the number of spaces for one level of indentation?

@calebcartwright
Copy link
Member

Does rustfmt have an option to specify the number of spaces for one level of indentation

https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#tab_spaces

@ayazhafiz
Copy link
Contributor

This was fixed by 2836f9b

@calebcartwright
Copy link
Member

Thanks for confirming @ayazhafiz! Would you be willing to open a PR with a corresponding test case to cover this (and the other relevant issues you noted were fixed by that commit)?

It's always super helpful for us to have test cases for past issues to prevent regressions

@ayazhafiz
Copy link
Contributor

ayazhafiz commented May 19, 2020 via email

ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue May 19, 2020
The cases with `hard_tabs: true` were fixed in 2836f9b.
Not sure about the rest, but this suggests a number of open issues are
already resolved.

Closes rust-lang#3608
Closes rust-lang#3550
Closes rust-lang#3638
Closes rust-lang#3858
Closes rust-lang#3936
ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue May 20, 2020
The cases with `hard_tabs: true` were fixed in 2836f9b.
Not sure about the rest, but this suggests a number of open issues are
already resolved.

Closes rust-lang#3608
Closes rust-lang#3550
Closes rust-lang#3638
Closes rust-lang#3858
Closes rust-lang#3936
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants