Repository navigation
fix(toolchain): stop the PATH fallback from re-running the proxy itself - #5295
harshitsaini17 wants to merge 2 commits into
Conversation
When a tool is missing from the toolchain, the proxy runs the bare name from PATH, which is usually the same proxy again. Check if the first match on PATH is the running executable and report the missing tool right away, instead of after hitting the recursion limit. Fixes rust-lang#4355.
|
Welcome, and thank you for contributing to rustup! A reviewer will take a look at your PR, typically within a week or two. Please see the contribution instructions and our LLM policy for more information. |
| env::split_paths(&path) | ||
| .map(|dir| dir.join(binary)) | ||
| .find(|candidate| candidate.is_file()) | ||
| .is_some_and(|candidate| is_same_file(&me, &candidate).unwrap_or(false)) |
There was a problem hiding this comment.
I think this map().find().is_some_and(|_| _.unwrap_or()) contraption is not easy enough to understand.
Also I think this function should be detached from Toolchain since it only reads from process as far as I can see, and it should be defined its calling function.
There was a problem hiding this comment.
Thanks, I learned something good here. I changed it to a plain loop and moved it out of Toolchain as a free function below create_command. I havent squashed the commits yet, so the change is easy for you to see. I will squash once you're done reviewing.
Fixes #4355
When a tool like rustfmt is missing from the toolchain, rustup falls back to the one on PATH and it run itself repeatedly untill recursion limit exhuasted and then show error.
Now, before falling back, rustup checks if the first match on PATH is the running rustup binary. If it is, it shows the error right away. This is the first idea ChrisDenton suggested in the issue, and PATH is not changed.
Before: 21 runs, about 350 ms. After: 1 run, about 19 ms. The error message is the same.
I added a test that counts the runs (3 on main, 1 with the fix). A real rustfmt earlier on PATH still runs as before.
cargo fmt,cargo clippyandcargo test --features testpass. I am using Arch linux, so, I havent tested on Windows.