Skip to content

OS discrepancy in how RUSTUP_TOOLCHAIN is set #3050

Description

@smoelius

Problem

There seems to be a discrepancy in how RUSTUP_TOOLCHAIN is set on Windows versus Mac and Linux.

Steps

  1. Create a Cargo project in a directory called env. Give it the following main.rs:
    fn main() {
        println!("{}", env!("RUSTUP_TOOLCHAIN"));
    }
    And the following rust-toolchain:
    [toolchain]
    channel = "nightly-2022-06-30"
  2. In a sibling directory, create another Cargo project with the following main.rs:
    fn main() {
        std::process::Command::new("cargo")
            .env_remove("RUSTUP_TOOLCHAIN")
            .current_dir("../env")
            .arg("run")
            .status()
            .unwrap();
    }
  3. cargo run the latter. On Linux and Mac, the toolchain is printed as one might expect. But on Windows, one gets:
    error: environment variable `RUSTUP_TOOLCHAIN` not defined
     --> src\main.rs:2:20
      |
    2 |     println!("{}", env!("RUSTUP_TOOLCHAIN"));
      |                    ^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: could not compile `env` due to previous error

Possible Solution(s)

Sorry, I don't have any.

Notes

I'm not sure if this is related to #3036.

Rustup version

rustup 1.25.1 (bb60b1e89 2022-07-12)

Installed toolchains

Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\User\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-msvc (default)
nightly-2022-06-30-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.62.1 (e092d0b6b 2022-07-16)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions