20

My Rust project no longer builds after some conflicts between my RLS plugin and terminal build. I searched around the web and found suggestion of removing my ~/.cargo/registry/index/*, but after that I can't even build any project.

Now the build always stops at

Updating crates.io index

Passing in the --verbose option doesn't help so I don't even know whether it's dying. What should I do next? How to debug this issue?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Fei
  • 1,450
  • 1
  • 17
  • 30
  • 1
    Restore the files you deleted. You **did** remember to back them up before following the advice of a random site on the internet that told you to delete them, right? If you don't have a backup, try deleting all of `~/.cargo`. – Shepmaster Nov 18 '18 at 13:33
  • I'm not an expert on cargo, but you could just try reinstalling it, if you don't mind removing `.cargo`. – rudib Nov 18 '18 at 13:35
  • 9
    You can set `RUST_LOG` to `cargo=debug`: `RUST_LOG=cargo=debug cargo update`. More specific to your problem would be `RUST_LOG=cargo::sources=debug cargo update`. – user2722968 Nov 18 '18 at 13:50
  • I had a different error, and moving my ~/.cargo/registry to a backup at ~/.cargo/registry.backup worked. Next I did `Cargo build --release` and my project updated my crates.io index. – qxotk Apr 28 '19 at 01:39
  • 2
    I'm having this issue with a clean install, on Windows, on a slow internet connection. Takes ~12 hours. I wonder if this is related to Windows' anti-virus that causes building rust docs to take a while, or the way crates is fetching files. It makes progress, but very very slowly. (incommensurate with the connection speed for other things) – Turtles Are Cute Aug 10 '19 at 14:54
  • 1
    @qxotk. That didn't work for me. Thanks for sharing your results anyways. – Prajwal Aug 22 '19 at 05:57
  • @rudib That did not work. I uninstalled rust with `rustup self uninstall` and deleted the C:\Users\my_username\.cargo folder and then installed rust again with rust-init.exe – Prajwal Aug 22 '19 at 06:01
  • 3
    @Fei Did you find any solution? In my case, it was because github.com was blocked on my system. – Prajwal Aug 22 '19 at 06:17
  • 1
    I encountered same problem I deleted .package-cache in .cargo/ . It worked for me you can try It. Take backup first – RajkumarG Apr 11 '20 at 16:33
  • @PrajwalDhatwalia I believe it should be bug of the toolset - upgrading to newer version of rust fixed that. – Fei Jun 09 '20 at 13:57

2 Answers2

6

Delete the ~/.cargo/.package-cache file.

Kaplan
  • 2,572
  • 13
  • 14
2

Change cargo source in ~/.cargo/config. This works for me.

For example:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
Tianyi Liu
  • 36
  • 2
  • This looks suspicious. You should at least explain that this sends cargo requests to a server based in China, so it might help with firewall issues from within China but not for users outside of China. – alter_igel Aug 31 '23 at 04:14