Can't add latest version of a crate as dependency

Hi all, I'm trying to add the urlencoding crate as a dependency to a fresh project generated by cargo. Right now, this is the only dependency listed in my Cargo.toml.

[dependencies]
urlencoding = "2.1.0"

cargo search urlencoding shows the latest version is indeed 2.1.0 (and web UI indicates this version is not yanked):

❯ cargo search urlencoding --limit 1
urlencoding = "2.1.0"    # A Rust library for doing URL percentage encoding.
... and 47 crates more (use --limit N to see more)

However, running cargo fetch/cargo build results in this error:

error: failed to select a version for the requirement `urlencoding = "^2.1.0"`
candidate versions found which didn't match: 1.1.1, 1.1.0, 1.0.0, ...
location searched: crates.io index

It looks like more recent versions of the crate cannot be added to project as a dependency. I can indeed change my requested version to 1.1.1 and that will get added fine. Any ideas for what's causing this behavior?

That seems weird. I fail to reproduce your problem, I’m also not really sure what could be a problem to begin with. The failure is happening on the same machine as the cargo search, right?

Yes, same machine, user account, and terminal instance.

Well, I don't know what the actual issue was but deleting the ~/.cargo folder and then trying again allowed for the crate to be pulled successfully.

I’m currently trying to understand the situation on my own machine. I thought that the registry is the git repo at ~/.cargo/registry/index/github.com-1ecc6299db9ec823, but that folder is super out-of-date for me (last commit on May March 16) while cargo seems to operate fine, and a fresh project using e.g. urlencoding works without problems.

It even somehow fits your problem, the relevant file

$ cd ~/.cargo/registry/index/github.com-1ecc6299db9ec823
$ cat ur/le/urlencoding 
{"name":"urlencoding","vers":"0.1.0","deps":[],"cksum":"0b0c0679a8fbe40729514e2da9f04750d8c3a906c927e14dc98254fc1c1bc446","features":{},"yanked":true}
{"name":"urlencoding","vers":"0.1.1","deps":[],"cksum":"9683b4770331cf92ddd0e142ad866d4aa957d1bffe27b9f7147b5e2ed7a666d2","features":{},"yanked":false}
{"name":"urlencoding","vers":"0.2.0","deps":[],"cksum":"2efeddd37779aad98b8c4f0dd6b885b5cddd893ddd3b30d0b9b647296be0d276","features":{},"yanked":false}
{"name":"urlencoding","vers":"1.0.0","deps":[],"cksum":"3df3561629a8bb4c57e5a2e4c43348d9e29c7c29d9b1c4c1f47166deca8f37ed","features":{},"yanked":false}
{"name":"urlencoding","vers":"1.1.0","deps":[],"cksum":"1bc81aa2abb51f47653952060bce3ce15181accb7cef1ba36e5c42b7e250f182","features":{},"yanked":false,"links":null}
{"name":"urlencoding","vers":"1.1.1","deps":[],"cksum":"c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593","features":{},"yanked":false,"links":null}

only contains version up to 1.1.1.

1 Like

Hmm, maybe it’s using the thing as a bare repository… in that case I’m not sure why a particular version is checked out at all, unless that was done by myself at some point, or they changed it at some point.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.