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

Feature Request: Change and add new configurations to properly support tabs_spaces when using "hard tabs" #5546

Open
BenjaminBrienen opened this issue Sep 21, 2022 · 4 comments

Comments

@BenjaminBrienen
Copy link

BenjaminBrienen commented Sep 21, 2022

Please refer to the linked project below

2 tabs of indentation are being interpreted as more than 2 characters/width, causing rustfmt to think that the line is overflowing.
On the line in main(), 2 * tab_spaces + 26 = 110 > max_width, and error reporting is turned on, so it reports panicking in stdout. (26 is the width of the statement)
Why would someone set such a ridiculous value for tabs_spaces?
One reason might be to make it super obvious when the wrong indentation is being used if for some reason rustfmt fails to work properly in that respect.

rustfmt would panic on a more reasonable value in extremely nested scopes or longer statements as long as max_width is exceeded.
This should not be an error because tabs_spaces does not inform how many spaces a tab is rendered as (its width), especially since "hard tabs" aren't a fixed width.
It should only describe how many spaces to use for indentation when the indentation style is "soft".
Tabs should be treated as one character - or a configurable number of characters - for the purposes of checking against max_width.
tab_spaces should only be used in the process of overwriting the current line-leading indentation (including doc comments)
The whole point of using "hard tabs" is allowing the developer to configure their visual indentation size
preferences as an editor setting instead of enforcing a fixed width by using a set number of spaces in the source file.
Hard vs soft tabs are fundementally different, and should be treated as such by a formatter.

The needed fixes are:
Clarity: tab_spaces should be renamed to soft_indentation_size.
Clarity: hard_tabs should be renamed to use_hard_indentation or intendation_style (with options "hard" or "soft").
Implementation: soft_indentation_size should only come into effect if use_hard_indentation/intendation_style is true/"hard".
New: Create a config called hard_indentation_size to allow developers to enforce the current behavior.

Minimal example here:
https://github.com/BenjaminBrienen/rustfmt-crash

@ytmimi
Copy link
Contributor

ytmimi commented Sep 21, 2022

Is this not a duplicate of #5431?

@BenjaminBrienen
Copy link
Author

Do you see tabs_spaces or use_hard_indentation referred to anywhere in #4968? I don't know why you marked this as a duplicate the first time, and I thought this issue put the problem in more clear terms for you to understand. This could even be considered a feature request, so how can it be a duplicate of a bug in annotated_snippets? The line of code in the minimal example in that issue doesn't even use tabs for indentation! If you want to reopen #5431 I'd be glad to move my post there.

@ytmimi
Copy link
Contributor

ytmimi commented Sep 21, 2022

I don't see tab_spaces or hard_tabs explicitly mentioned, but the output from both panics seems similar and the comment #4968 (comment) leads me to believe that the original open issue and this one are the same.

Please let me know if you disagree with my assessment, and if so could you help me understand how these issues are different?

@ytmimi
Copy link
Contributor

ytmimi commented Sep 21, 2022

If this is a feature request could you update the title of the issue to reflect that

@BenjaminBrienen BenjaminBrienen changed the title rustfmt panics due to mishandling of tabs_spaces Feature Request: Change and add new configurations to properly support tabs_spaces when using "hard tabs" Sep 21, 2022
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