Skip to content

If FILE.rs.bk exists, rustfmt will sometimes overwrite it with formatted FILE.rs, regardless of write-mode #399

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

Closed
constancebello opened this issue Sep 29, 2015 · 13 comments

Comments

@constancebello
Copy link

carloss-mbp:rustfmt aarzee$ touch /Users/aarzee/coreutils/src/common/c_types.rs.bk
carloss-mbp:rustfmt aarzee$ stat /Users/aarzee/coreutils/src/common/c_types.rs.bk
16777220 3360231 -rw-r--r-- 1 aarzee staff 0 0 "Sep 29 13:38:51 2015" "Sep 29 13:38:51 2015" "Sep 29 13:38:51 2015" "Sep 29 13:38:51 2015" 4096 0 0 /Users/aarzee/coreutils/src/common/c_types.rs.bk
carloss-mbp:rustfmt aarzee$ cargo run --release -- /Users/aarzee/coreutils/src/common/c_types.rs 
     Running `target/release/rustfmt /Users/aarzee/coreutils/src/common/c_types.rs`

carloss-mbp:rustfmt aarzee$ stat /Users/aarzee/coreutils/src/common/c_types.rs.bk
16777220 3360138 -rw-r--r-- 1 aarzee staff 0 7232 "Sep 29 13:39:14 2015" "Sep 29 13:36:57 2015" "Sep 29 13:36:57 2015" "Sep 29 13:36:57 2015" 4096 16 0 /Users/aarzee/coreutils/src/common/c_types.rs.bk

c_types.rs causes this issue. Notice the change in file size and modification date.

@constancebello constancebello changed the title --write-mode=replace sometimes results in formatted .rs.bk If FILE.rs.bk exists, rustfmt will sometimes overwrite it with formatted FILE.rs, regardless of write-mode Sep 29, 2015
@marcusklaas
Copy link
Contributor

Hmmm, I can't reproduce this. Could you post some extra context?

@constancebello
Copy link
Author

I just updated the issue with more details, could you try again?

@marcusklaas
Copy link
Contributor

Ah, thanks. Will play around with it a bit.

@marcusklaas
Copy link
Contributor

I am hitting this now. This is most curious. Thanks for the report!

@marcusklaas
Copy link
Contributor

Wait, doesn't it make sense?

@marcusklaas
Copy link
Contributor

When you run rustfmt in replace mode twice, it will overwrite the backup file with the output of the first run.

@marcusklaas
Copy link
Contributor

Not sure if this should be the behaviour.. maybe we should simply overwrite if the backup file is found, or abort?

@constancebello
Copy link
Author

You might be right. I only came into the issue by running a Python script to run it on all .rs files in a directory (recursively)... I may be running it on the same file more than once. I'm going to double check that everything in this script is working correctly.

@marcusklaas
Copy link
Contributor

Note that rustfmt automatically runs on all child modules, even when those are in separate files. For most libraries, running rustfmt on src/lib.rs formats all your code!

@constancebello
Copy link
Author

That would be the issue. Sorry for the confusion! Closing. On another note, however, is there a way to disable that? (I'm running it on a complicated project which consists of many crates with some common files).

@marcusklaas
Copy link
Contributor

Not as of this moment, no. But wait, crates having common files? That's madness, yo!

@constancebello
Copy link
Author

They're in fact not primarily crates. While building them with Cargo is an option, the normal method is using a Makefile. (The project is uutils/coreutils). Should I open an issue for having that as an option?

@marcusklaas
Copy link
Contributor

Sure, that sounds good. I'm curious to see what others think about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants