-
Notifications
You must be signed in to change notification settings - Fork 908
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
rustfmt overwriting other files with contents of target file #1229
Comments
|
Thanks for the bug report. If you could make a minimal test case that reproduces the behaviour that would be extremely helpful. Do you get the same behaviour running rustfmt on other files, or only that one (or some subset of files)? |
$ ls -R
.:
foo.rs targets/
./targets:
bar.rs mod.rs
$ cat foo.rs
mod targets;
fn main() {}
$ cat targets/mod.rs
#[cfg(feature="bar")]
pub mod bar;
$ cat targets/bar.rs
fn lib() {}
$ rustfmt foo.rs
$ cat targets/bar.rs
mod targets;
fn main() {} |
Re your question: I remember seeing it on one other file, but can't remember what that was. I thought it was just a fluke at the time, so did a swift |
Note also that this does not trigger if the |
I keep forgetting this, and am constantly finding myself having to do a |
I am able to reproduce the error here. Using rustfmt as of 56469a8. |
Still present in 0.7.0 |
I investigated this today, it is due to cfg'ed modules being stripped in the parser (rust-lang/rust#36482). This will need a fix in rustc and that will need to propagate to Syntex before it can have an effect in Rustfmt, but hopefully a fix should be coming up soon-ish. In the meantime, work-around is to ensure all cfgs resolve to true, or comment them out. |
@nrc Ah, good catch! That's a pretty painful work-around, but I guess there's not that much we can do about it until a fix percolates down the chain. |
Syntex 0.56.0 contains the fix from rust-lang/rust#39145. |
@nrc I tried just bumping syntex to 0.56.2 and build |
After upgrading to
d3eba76e4d63c08fa0c4406745d1f0cc0e576758
, I'm seeing some truly bizarre (and quite disturbing) behavior of rustfmt. Specifically, when I format a particular file in my project,rustfmt
overwrites a bunch of other files with the contents of that file! A console example will likely be most helpful:This is a somewhat large codebase that isn't public (yet), and so I unfortunately can't point you at the source. The basic structure is as follows though:
The other files that are overwritten are all of the same form as
benchmarks/targets/memcached.rs
(i.e., they are compiled under a#[cfg(feature = ...)]
directive). I have other modules that work the same way, but that are not conditionally compiled, and they are not overwritten byrustfmt
.The text was updated successfully, but these errors were encountered: