-
Notifications
You must be signed in to change notification settings - Fork 898
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
add --check flag to cargo fmt #3890
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
@@ -104,6 +108,12 @@ fn execute() -> i32 { | |||
|
|||
let strategy = CargoFmtStrategy::from_opts(&opts); | |||
let mut rustfmt_args = opts.rustfmt_options; | |||
if opts.check { | |||
let check_flag = String::from("--check"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we can defer the allocation of a String
until we absolutely need it:
let check_flag = "--check";
if !rustfmt_args.contains(check_flag) {
rustfmt_args.push(check_flag.to_owned());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I believe the limitations with Vec::contains that we ran into in #3752 (comment) still exist which prevent using a literal as an arg.
On a related note, I was going to volunteer to work on #3587 and while working on that I'll also look into consolidating the way cargo fmt
is transforming/passing flags (like --message-format
--> --emit
, --check
, etc.) to rustfmt
which I think may help remove some of these Vec::contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my god, I am so dumb 😩 Sorry about that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries!
703fa71
to
0a9ec7e
Compare
backported in #4993 |
Resolves #3888