Skip to content
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

x fmt tries to format non-rust files #106261

Closed
Noratrieb opened this issue Dec 29, 2022 · 12 comments · Fixed by #106263
Closed

x fmt tries to format non-rust files #106261

Noratrieb opened this issue Dec 29, 2022 · 12 comments · Fixed by #106263
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-high High priority regression-untriaged Untriaged performance or correctness regression. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@Noratrieb
Copy link
Member

Noratrieb commented Dec 29, 2022

formatting modified file compiler/rustc_error_messages/locales/en-US/borrowck.ftl
error: unknown start of token: `
 --> /home/nilsh/projects/rust/compiler/rustc_error_messages/locales/en-US/borrowck.ftl:2:33
  |
2 |     cannot move a value of type `{$ty}`
  |                                 ^
  |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
  |
2 |     cannot move a value of type '{$ty}`
  |                                 ~

error: unknown start of token: `

When there was a change in a .ftl or other non-rust file, bootstrap tries to format it, which makes rustfmt very sad.

cc @albertlarsan68 and @jyn514 who broke this in #105702

@Noratrieb Noratrieb added the C-bug Category: This is a bug. label Dec 29, 2022
@jyn514 jyn514 added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Dec 29, 2022
@jyn514
Copy link
Member

jyn514 commented Dec 29, 2022

I think we just need to filter .rs files before passing them to rustfmt.

@Noratrieb
Copy link
Member Author

This will probably be hit a lot by contributors so I'll pin it for better visibility.

@Noratrieb Noratrieb pinned this issue Dec 29, 2022
@Noratrieb Noratrieb changed the title x fmt tries to format ftl and stderr files x fmt tries to format non-rust files Dec 29, 2022
@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. regression-untriaged Untriaged performance or correctness regression. labels Dec 29, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 29, 2022
@chenyukang
Copy link
Member

@rustbot claim

@albertlarsan68
Copy link
Member

Normally, the walker already filters for .rs files, per https://docs.rs/ignore/latest/ignore/struct.WalkBuilder.html. Maybe the ignore crate docs are not fully up to date, or I didn't understand them correctly.

@albertlarsan68
Copy link
Member

The workaround is to run x fmt . (notice the dot at the end of the command).

@chenyukang
Copy link
Member

I think if we add it like this:

ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);

ignore will always not ignore it anymore.

@albertlarsan68
Copy link
Member

albertlarsan68 commented Dec 29, 2022

Maybe try to put the part I added before the ignore part, maybe this makes the ignore list work again?

The thing that intrigues me the most is the fact that the .stderr files are not ignored later by the file type filter.

@chenyukang
Copy link
Member

For any Rust files we changed locally, our current solution will try to format it, in some scenarios we may not want to format it, such as some files in UI?

@chenyukang
Copy link
Member

Maybe try to put the part I added before the ignore part, maybe this makes the ignore list work again?

The thing that intrigues me the most is the face that the .stderr files are not ignored later by the file type filter.

Seems right, my current fix is not completed.

@jyn514
Copy link
Member

jyn514 commented Dec 29, 2022

Normally, the walker already filters for .rs files, per https://docs.rs/ignore/latest/ignore/struct.WalkBuilder.html. Maybe the ignore crate docs are not fully up to date, or I didn't understand them correctly.

I think since you explicitly add the files to ignore_fmt, that overrides the types filter.

@chenyukang
Copy link
Member

chenyukang commented Dec 29, 2022

from my local experiment, seems rustfmt.toml is still expected, I changed some files which ignored in rustfmt.toml, they are actually not sent to formatter:

cat@LAPTOP-V6U0QKD4:~/code/rust$ x fmt
Building rustbuild
   Compiling bootstrap v0.0.0 (/home/cat/code/rust/src/bootstrap)
    Finished dev [unoptimized] target(s) in 5.25s
formatting modified file library/portable-simd/crates/core_simd/src/vendor/arm.rs
formatting modified file src/bootstrap/format.rs
formatting modified file src/tools/miri/src/bin/miri.rs
really try to format: DirEntry { dent: Raw(DirEntryRaw { path: "/home/cat/code/rust/src/bootstrap/format.rs", follow_link: false, depth: 3 }), err: None }
Build completed successfully in 0:00:07

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 29, 2022
…ter, r=jyn514

Formatter should not try to format non-Rust files

Fixes rust-lang#106261
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 29, 2022
@bors bors closed this as completed in 7ebcc78 Dec 29, 2022
@Noratrieb Noratrieb unpinned this issue Jan 2, 2023
jyn514 added a commit to jyn514/rust that referenced this issue Mar 5, 2023
Previously, `x fmt` would only format modified files, while `x fmt .`
and `x fmt --check` would still look at all files. After this change, `x
fmt --check` only looks at modified files locally.

I feel pretty confident in this change - other than
rust-lang#106261, no one has reported
bugs in `get_modified_rs_files` since it was added in
rust-lang#105702.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 5, 2023
…rsan68

x fmt: Only check modified files locally

Previously, `x fmt` would only format modified files, while `x fmt .` and `x fmt --check` would still look at all files. After this change, `x fmt --check` only looks at modified files locally.

I feel pretty confident in this change - other than rust-lang#106261, no one has reported bugs in `get_modified_rs_files` since it was added in rust-lang#105702.

Combined with the changes in rust-lang#108772, this brings the time for me to run `x t tidy` with a hot FS cache down from 5 to 2 seconds (and moves the majority of the time spent back to `tidy check`, which means it can be sped up more in the future).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-high High priority regression-untriaged Untriaged performance or correctness regression. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants