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.

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: 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/, 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/
$ cat ur/le/urlencoding 

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.