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

Allow shortcuts to directories to be used for ./x.py fmt #107948

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

jieyouxu
Copy link
Member

Fixes #107944.

Maximum recursive search depth is 3 and only accepts shortcuts for directories. If there are no shortcut candidates, the previous behavior to panic is preserved. If there are multiple candidates, the shortcut candidates are ignored.

After this change, ./x.py fmt std no longer panics and formats library/std instead.

@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2023

r? @ozkanonur

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Feb 12, 2023
@onur-ozkan
Copy link
Member

This change breaks the backwards compatibility of x fmt command.

~/devspace/personal/rust-dist/tools  $ ../../rust/x.py fmt ../../rust/library/std

thread 'thread 'main' panicked at 'path is expected to be under the root', main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs/cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs::227227::99

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'thread 'main' panicked at 'mainpath is expected to be under the root' panicked at '', path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs/cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs::227227::99

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'thread 'mainmain' panicked at '' panicked at 'path is expected to be under the rootpath is expected to be under the root', ', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs/cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs::227:2279
:note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Running `"/home/nimda/devspace/personal/rust-dist/tools/build/x86_64-unknown-linux-gnu/rustfmt/bin/rustfmt" "--config-path" "/home/nimda/devspace/personal/rust2" "--edition" "2021" "--unstable-features" "--skip-children" "../../rust/library/std/src/rt.rs" "../../rust/library/std/src/time.rs" "../../rust/library/std/src/sync/once/tests.rs" "../../rust/library/std/src/net/ip_addr.rs" "../../rust/library/std/src/net/mod.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
Build completed unsuccessfully in 0:00:56
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'thread 'mainmain' panicked at '' panicked at 'path is expected to be under the rootpath is expected to be under the root', ', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs/cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs::227:9
227note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'thread 'mainmain' panicked at '' panicked at 'path is expected to be under the rootpath is expected to be under the root', ', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs/cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs::227227::99

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'path is expected to be under the root', /cargo/registry/src/github.com-1ecc6299db9ec823/ignore-0.4.18/src/gitignore.rs:227:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

src/bootstrap/format.rs Outdated Show resolved Hide resolved
src/bootstrap/format.rs Outdated Show resolved Hide resolved
@onur-ozkan onur-ozkan added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2023
for candidate in WalkBuilder::new(src.clone()).max_depth(Some(3)).build() {
if let Ok(entry) = candidate {
if let Some(dir_name) = p.file_name() {
if entry.path().is_dir() && entry.file_name() == dir_name {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this style is better:

 if let Ok(entry) = candidate &&
    let Some(dir_name) = p.file_name() &&
    entry.path().is_dir() && entry.file_name() == dir_name {
   ...
}

Copy link
Member Author

@jieyouxu jieyouxu Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to use that, but for src/bootstrap/format.rs if-let chains features aren't already enabled

error[E0658]: `let` expressions in this position are unstable
   --> format.rs:199:24
    |
199 |                     if let Ok(entry) = candidate
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

I've been using if-let chains in compiler/ and it's been really nice. Should I enable the feature or have the code remain as-is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's out of scope for this particular PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bootstrap itself is rarely (ever?) built with nightly.
The only thing to do is maybe leave a FIXME, but do not enable nightly features.

Copy link
Member

@jyn514 jyn514 Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please don't use nightly in bootstrap, if we start doing that we have to add cfg(bootstrap) to bootstrap itself and that will not be fun

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right I forgot bootstrap needed to work with stable 😄, the PR was squashed as-is without touching nightly features.

@onur-ozkan
Copy link
Member

Thanks for the quick fix! Please also consider review suggestion from @chenyukang, and then squash your commits into single one so we can take this into master.

@onur-ozkan onur-ozkan added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2023
Fixes rust-lang#107944.

Maximum recursive search depth is 3 and only accepts shortcuts for
directories (single component paths, such as `./x.py fmt std`). If
there are no shortcut candidates but single componenet path(s) are
given, it falls back to the previous behavior to panic with unable to
find directory. If there are multiple shortcut candidates for a given
single component path, the shortcut candidates are considered
ambiguous, are then ignored, and the single component path is accepted
as-is.

After this change, `./x.py fmt std` no longer panics and formats
`library/std` instead.
@onur-ozkan onur-ozkan added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2023
@onur-ozkan
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 13, 2023

📌 Commit b10d744 has been approved by ozkanonur

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107902 (fix: improve the suggestion on future not awaited)
 - rust-lang#107913 (Update broken link in cargo style guide)
 - rust-lang#107942 (Tighter spans for bad inherent `impl` self types)
 - rust-lang#107948 (Allow shortcuts to directories to be used for ./x.py fmt)
 - rust-lang#107971 (Clearly document intentional UB in mir-opt tests)
 - rust-lang#107985 (Added another error to be processed in fallback)
 - rust-lang#108002 (Update books)
 - rust-lang#108013 (rustdoc: use a string with one-character codes for search index types)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7efb884 into rust-lang:master Feb 14, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 14, 2023
@jieyouxu jieyouxu deleted the issue-107944 branch February 14, 2023 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.\x fmt std panics
7 participants