Skip to content

Missing backslash in printed CARGO_HOME path on Windows #2272

@Simran-B

Description

@Simran-B

Problem

I installed Rust using rustup under Windows 10 and noticed a missing backslash in the post install message which tells you the Cargo bin directory:

Rust is installed now. Great!

To get started you need Cargo's bin directory (%USERPROFILE%.cargo\bin) in your
PATH
environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.

Press the Enter key to continue.

It should be %USERPROFILE%\.cargo\bin with a backslash after %USERPROFILE% to be valid.

Note that it printed the following earlier:

It will add the cargo, rustc, rustup and other commands to
Cargo's bin directory, located at:

  C:\Users\Simran\.cargo\bin

And it added this to the PATH environment variable correctly.

Steps

  1. Download rustup-init.exe (64-bit)
  2. 1) Proceed with installation (default)
  3. Wait until installation completes and check the last block of messages

Possible Solution(s)

The message is coming from here:

src\cli\self_update.rs

macro_rules! post_install_msg_win {
    () => {
        r"# Rust is installed now. Great!

To get started you need Cargo's bin directory ({cargo_home}\\bin) in your `PATH`
environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.
"
    };
}

The backslash before bin (which shows correctly) is escaped, but the rest is coming from the variable cargo_home. Interestingly, a different variable is used for the other message, cargo_home_bin:

macro_rules! pre_install_msg_template {It will add the `cargo`, `rustc`, `rustup` and other commands to
Cargo's bin directory, located at:

    {cargo_home_bin}

It could be used instead of {cargo_home}\\bin I guess, but with the env var %USERPROFILE% resolved. I'm not sure how else to fix the problem. The following looks alright using a raw string, removing the need for escaping the backslash:

fn canonical_cargo_home() -> Result<String> {
…
            path_str = String::from(r"%USERPROFILE%\.cargo");

Or does it need to be double-escaped to r"%USERPROFILE%\\.cargo" (non-raw "%USERPROFILE%\\\\.cargo" I suppose)?

Notes

Output of rustup --version: rustup 1.21.1 (7832b2e 2019-12-20)

Output of rustup show:

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

stable-x86_64-pc-windows-msvc (default)
rustc 1.42.0 (b8cedc004 2020-03-09)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions