rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

rustfmt does not respect brace_style when formatting imports

Open BenjaminBrienen opened this issue 2 years ago • 2 comments

With:

hard_tabs = true
braces_style = "AlwaysNextLine"
control_brace_style = "AlwaysNextLine"
group_imports = "StdExternalCrate"
imports_granularity = "One"
imports_indent = "Block"
imports_layout = "Vertical"
indent_style = "Block"
newline_style = "Unix"
trailing_comma = "Vertical"

Current output:

use {
	colored::{
		ColoredString,
		Colorize,
	},
	std::{
		cmp::Ordering,
		fmt::{
			Display,
			Formatter,
		},
		io::{
			Read,
			Write,
		},
		ops::{
			ControlFlow,
			RangeInclusive,
		},
		result::Result,
	},
};

Expected output:

use
{
	colored::
	{
		ColoredString,
		Colorize,
	},
	std::
	{
		cmp::Ordering,
		fmt::
		{
			Display,
			Formatter,
		},
		io::
		{
			Read,
			Write,
		},
		ops::
		{
			ControlFlow,
			RangeInclusive,
		},
		result::Result,
	},
};

BenjaminBrienen avatar Sep 21 '22 01:09 BenjaminBrienen

Probably controversial, but having braces on the same line makes 0 sense with "AlwaysNextLine"

BenjaminBrienen avatar Sep 21 '22 01:09 BenjaminBrienen

Is this a feature request?

I don't think the brace_style config option was intended to be used with imports. The docs only give examples for functions, enums, and structs.

ytmimi avatar Sep 21 '22 03:09 ytmimi