rustubuntu-12.04rust-cargo

cargo-generate install fail on Ubuntu 20.04


Trying to install cargo-generate on Ubuntu 20.04.1 LTS, first it complained about ssl, installed libssl with this command sudo apt-get install -y libssl-dev but now getting the error below.

How can I install cargo-generate on Ubuntu 20.04?

rustc --version
rustc 1.49.0 (e1884a8e3 2020-12-29)

cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)

cargo install cargo-generate
.....
   Compiling crypto-hash v0.3.4
   Compiling crates-io v0.31.1
   Compiling git2 v0.13.17
   Compiling git2-curl v0.14.1
   Compiling cargo v0.46.1
        error[E0283]: type annotations needed
           --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-0.46.1/src/cargo/util/config/de.rs:471:63
            |
        471 |                 seed.deserialize(Tuple2Deserializer(1i32, env.as_ref()))
            |                                                           ----^^^^^^--
            |                                                           |   |
            |                                                           |   cannot infer type for type parameter `T` declared on the trait `AsRef`
            |                                                           this method call resolves to `&T`
            |
            = note: cannot satisfy `std::string::String: AsRef<_>`
        
        error: aborting due to previous error
        
        For more information about this error, try `rustc --explain E0283`.
        error: failed to compile `cargo-generate v0.5.1`, intermediate artifacts can be found at `/tmp/cargo-installtb5LHS`
        
        Caused by:
          could not compile `cargo`
        
        To learn more, run the command again with --verbose.

Solution

  • This should (hopefully) be a temporary failure fixed in the cargo upstream (issue already closed).

    Workaround:

    cargo install cargo-generate --locked cargo
    

    Failure and workaround described here: https://github.com/rust-lang/cargo/issues/9101