Closed Doineann closed 4 months ago
This is a rustup issue (the toolchain manager) and not caused by rust itself. See: https://github.com/rust-lang/rustup/issues/3635
What is the alternative? Have it report an error to the user that they need to manually invoke rustup to update their toolchain? That is a lot less ergonomic and likely breaks tools that invoke rustc or cargo and don't expect this error and may not even have a good way to show the error.
I expect rustc --version
to just output version information, like how --version
would behave in any application.
In my humble opinion rustc --version
should not be responsible for upgrading toolchains, the user should do that either explicitly or maybe when running rustc
with any other flags that -actually- require the updates to be performed.
The --version
argument should really just be a 'request' for version information and not trigger any other actions.
To be clear... I think it's ok to trigger updates for calls to rustc
with different arguments, but I believe --version
should really only output the version.
That justification makes sense, but it would also mean that if you run rustc --version
in a Cargo project with rust-toolchain.toml
, it would return X
, but then pretty much any other rustc/cargo
command in that directory would download the different toolchain Y
anyway. So rustc --version
would give you a version without doing anything else, but it would not be the actual version used for a given Cargo project.
Note that when the toolchain is managed by rustup, the rustc command is a rustup proxy. rustc itself will never download or install toolchains (it wouldn't even know how to).
So discussion should move to the rustup repository. Discussing it here will not affect changes to rustup.
I can even imagine this behavior to pose a security risk, as users would not expect --version
to perform any installation/updates. I don't know what kind of actions a call to rustc --version
actually performs, so I cannot tell if this is the case, but in the very least, it is unexpected behavior.
That justification makes sense, but it would also mean that if you run
rustc --version
in a Cargo project withrust-toolchain.toml
, it would returnX
, but then pretty much any otherrustc/cargo
command in that directory would download the different toolchainY
anyway. Sorustc --version
would give you a version without doing anything else, but it would not be the actual version used for a given Cargo project.
If I run rustc --version
I honestly expect to see the version of the 'currently active' or default
rustc. I understand your argument that this may not match with the version of the project and maybe needs an update...
So maybe then it should indeed also report that the versions do not match... and how to update. Or maybe an extra flag to also trigger an update if necessary.
Note that when the toolchain is managed by rustup, the rustc command is a rustup proxy. rustc itself will never download or install toolchains (it wouldn't even know how to).
So discussion should move to the rustup repository. Discussing it here will not affect changes to rustup.
I understand. Should I repeat this Issue on the rustup repo, or did you effectively do that already with your first reply?
(thanks for the quick response, by the way)
It looks like there is already a related PR https://github.com/rust-lang/rustup/pull/2658.
You could mention rustc --version
explicitly in the issue I linked in my first post.
If you invoke a rustc
directly rather that via rustup's proxy, then rustc --version
will behave exactly as you expect.
But since you may well have many versions of rustc installed, the question then becomes which of those many rustc's do you want to invoke? The proxy decided (from the rust-toolchain.toml
) that the one you intended to invoke was one that wasn't yet installed, and it went ahead and installed it for you. However if you knew that you wanted to invoke some other (already installed) version then you could have specified that in the command eg rustc +1.79 --version
(but I guess that's kinda pointless unless you're using +stable
, +beta
or +nightly
).
It looks like there is already a related PR rust-lang/rustup#2658.
@ChrisDenton Err not quite; that's not about the shim but about rustup
itself.
Anyway https://github.com/rust-lang/rustup/issues/3635 has already covered this even before this issue's appearance, so I suggest we close this issue in favor of that one.
Ah thanks! Ok then, closing this in favour of the rustup issue.
@ChrisDenton Thanks! BTW can you transfer the issue to Rustup so that we might keep the conversation history while keeping this sub-task tracked individually? (Don't worry if you don't have the permission, I'll make a new issue there instead if that is the case.)
Yeah sorry, I don't have any permissions on the rustup repo.
(@ChrisDenton you can use @rustbot transfer rustup
for that)
rustc --version
should, in my humble opinion, not perform any unexpected behavior like initiating toolchain updates.As a user I expect just the current active version of rustc to be returned and nothing else to happen.
Instead running
rustc --version
within a newly cloned rust-project triggers installation of a toolchain.I ran into this issue within an application like oh-my-posh which uses
rustc --version
to display rustc's version number in the command prompt.The issue can easily be replicated by cloning a project that require a toolchain update and then running
rustc --version
:output:
Meta
rustc --version --verbose
: