Rust Warning: The rustfmt Command Formats Referenced Source Code Files

I figured out why my the rustfmt commands in the build script for my rust program were reformatting certain .rs source code files repeatedly, including one that I was explicitly excluding from the command line. I was trying to pass each file to the rustfmt command individually, excluding the one that I need to format differently because it contains long lines of code.

As it turns out, the rustfmt command formats the file(s) specified on the command line as well as any files that those files reference, so it is not necessary to call rustfmt repeatedly or to pass all of the file paths on the command line. I do not think it is possible to exclude referenced files from formatting, but you can reformat those files afterwards.

To format all the files in a project requires a single short command.

cmd="time rustfmt -l -v ./src/main.rs ./src/lib.rs"

To reformat a specific file that has very long lines:

cmd="rustfmt -l -v --config max_width=2500 ./src/wsl/inv/invocablecategory.rs"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: