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

Missing indentation if using hard_tabs #3151

Open
boozook opened this issue Oct 29, 2018 · 5 comments
Open

Missing indentation if using hard_tabs #3151

boozook opened this issue Oct 29, 2018 · 5 comments
Labels
only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@boozook
Copy link

boozook commented Oct 29, 2018

Version: rustfmt 0.99.5-nightly (90692a59 2018-09-26).

In match-blocks only first line is indented. All following lines should indented too but not.

rustfmt-issue-tab-indent mov


Example to reproduce:

enum Foo { A, B, C }

fn main() {
	let extra_indent = |v: Foo| {
		(|v| {
			 match v {
				 Foo::A => println!("A"),
			    Foo::B => println!("B"),
			    Foo::C => println!("C"),
			 }
			},
		 v)
	};
}

Example rustfmt config

I can reproduce only in the any list (tuple/union/array/...).

@boozook
Copy link
Author

boozook commented Oct 29, 2018

Another example.

Current rustfmt result (with same config) :

fn main() {
	let extra_indent = |v: Foo| {
		(|v| {
			 match v {
				 Foo::A => {
				   println!("A");
				  },
			   Foo::B => {
				   println!("B");
				  },
			   Foo::C => println!("C"),
			 }
			},
		 v)
	};
}

Expected result:

fn main() {
	let extra_indent = |v: Foo| {
		(|v| {
			 match v {
				 Foo::A => {
				   println!("A");
				  },
				 Foo::B => {
				   println!("B");
				  },
				 Foo::C => println!("C"),
			 }
			},
		 v)
	};
}

@topecongiro topecongiro added poor-formatting only-with-option requires a non-default option value to reproduce labels Oct 29, 2018
@workingjubilee
Copy link
Member

workingjubilee commented Apr 6, 2021

Current result with the same config but #fn_args_density commented out:

fn main() {
	let extra_indent = |v: Foo| {
		(|v| {
			 match v {
				 Foo::A => {
				    println!("A");
			    },
			    Foo::B => {
				    println!("B");
			    },
			    Foo::C => println!("C"),
			 }
		 },
		 v)
	};
}

Perhaps more instructive to look at this screenshot of the same with the tabs and spaces highlighted, for those who aren't already running that through a screenreader:
image

Currently:

>rustfmt --version
rustfmt 1.4.36-nightly (7de6968e 2021-02-07) # from rustup

@calebcartwright

This comment has been minimized.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 19, 2022

Confirming I can reproduce the main issue where only the first match arm is indented with rustfmt 1.5.1-nightly (a7bf0090 2022-07-17) when using hard_tabs=true and indent_style=Visual.

run rustfmt --emit stdout --config=hard_tabs=true,indent_style=Visual issue_3151.rs

input

enum Foo {
    A,
    B,
    C,
}

fn main() {
    let extra_indent = |v: Foo| {
        (
            |v| match v {
                Foo::A => println!("A"),
                Foo::B => println!("B"),
                Foo::C => println!("C"),
            },
            v,
        )
    };
}

output

enum Foo {
	A,
	B,
	C,
}

fn main() {
	let extra_indent = |v: Foo| {
		(|v| match v {
			 Foo::A => println!("A"),
		     Foo::B => println!("B"),
		     Foo::C => println!("C"),
		 },
		 v)
	};
}

@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

Linking the tracking issues for indent_style (#3346). hard_tabs is a stable option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
Development

No branches or pull requests

5 participants