0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cargo install cargo-editにおけるビルドエラー error[E0277]: expected a `FnMut<(char,)>` closure, found `[char; 2]`

Posted at

環境

Date: 2022/04/19
OS: macOS Big Sur 11.6

$ rustc --version
rustc 1.57.0 (f1edd0429 2021-11-29)

$ cargo --version                     
cargo 1.57.0 (b2e52d7ca 2021-10-21)

現象

cargo install cargo-edit実行時にエラー発生。

エラー
   Compiling cargo-edit v0.9.0
error[E0277]: expected a `FnMut<(char,)>` closure, found `[char; 2]`
   --> /Users/****/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-edit-0.9.0/src/bin/add/add.rs:479:19
    |
479 |     feature.split([' ', ',']).filter(|s| !s.is_empty())
    |             ----- ^^^^^^^^^^ expected an `FnMut<(char,)>` closure, found `[char; 2]`
    |             |
    |             required by a bound introduced by this call
    |
    = help: the trait `FnMut<(char,)>` is not implemented for `[char; 2]`
    = note: required because of the requirements on the impl of `Pattern<'_>` for `[char; 2]`

error[E0599]: the method `filter` exists for struct `std::str::Split<'_, [char; 2]>`, but its trait bounds were not satisfied
   --> /Users/****/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-edit-0.9.0/src/bin/add/add.rs:479:31
    |
479 |       feature.split([' ', ',']).filter(|s| !s.is_empty())
    |                                 ^^^^^^ method cannot be called on `std::str::Split<'_, [char; 2]>` due to unsatisfied trait bounds
    |
   ::: /Users/****/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/str/iter.rs:730:1
    |
730 | / generate_pattern_iterators! {
731 | |     forward:
732 | |         /// Created with the method [`split`].
733 | |         ///
...   |
745 | |     delegate double ended;
746 | | }
    | |_- doesn't satisfy `std::str::Split<'_, [char; 2]>: Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `[char; 2]: Pattern<'_>`
            which is required by `std::str::Split<'_, [char; 2]>: Iterator`
            `std::str::Split<'_, [char; 2]>: Iterator`
            which is required by `&mut std::str::Split<'_, [char; 2]>: Iterator`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `cargo-edit` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-edit v0.9.0`, intermediate artifacts can be found at `/var/folders/dn/jcwnk8wd19b_48cn2z3g4xyh0000gn/T/cargo-installZu95sK`

Caused by:
  build failed

解決

cargoのバージョンが古かったのが原因。rustup-initでcargoのバージョンを上げる。

$ rustup-init
Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

...

Current installation options:


   default host triple: x86_64-apple-darwin
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

...

Rust is installed now. Great!

...

To configure your current shell, run:
$ exec $SHELL -l
update後のversion
$ rustc --version
rustc 1.60.0 (7737e0b5c 2022-04-04)

$ cargo --version
cargo 1.60.0 (d1fd9fe2c 2022-03-01)

これでもう一度`cargo install cargo-edit`をしたら無事成功しました。

使用コマンド(コピペ用)

rustc --version
cargo --version
rustup-init後のshell再起動用
exec $SHELL -l
cargo install cargo-edit
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?