Rust 和 Flamegraph:使用 cargo 安装时出现一堆错误

Posted

技术标签:

【中文标题】Rust 和 Flamegraph:使用 cargo 安装时出现一堆错误【英文标题】:Rust and Flamegraph: Bunch of errors when installing using cargo 【发布时间】:2021-05-06 14:14:57 【问题描述】:

我想为Rust 安装flamegraph。按照自述文件中的说明运行cargo install flamegraph。但是,在某些时候它会引发一堆错误:

Compiling env_logger v0.8.3
Compiling atty v0.2.14
Compiling num_cpus v1.13.0
Compiling signal-hook-registry v1.3.0
Compiling quick-xml v0.20.0
Compiling clap v2.33.3
error[E0277]: the trait bound `K: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:36:18
   |
34 | impl<K, V> AHashMap<K, V, RandomState> 
   |      - help: consider restricting this bound: `K: std::cmp::Eq`
35 |     pub fn new() -> Self 
36 |         AHashMap(HashMap::with_hasher(RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_hasher`

error[E0277]: the trait bound `K: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:36:18
   |
34 | impl<K, V> AHashMap<K, V, RandomState> 
   |      - help: consider restricting this bound: `K: std::hash::Hash`
35 |     pub fn new() -> Self 
36 |         AHashMap(HashMap::with_hasher(RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_hasher`

error[E0277]: the trait bound `K: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:40:18
   |
34 | impl<K, V> AHashMap<K, V, RandomState> 
   |      - help: consider restricting this bound: `K: std::cmp::Eq`
...
40 |         AHashMap(HashMap::with_capacity_and_hasher(capacity, RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `K: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:40:18
   |
34 | impl<K, V> AHashMap<K, V, RandomState> 
   |      - help: consider restricting this bound: `K: std::hash::Hash`
...
40 |         AHashMap(HashMap::with_capacity_and_hasher(capacity, RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `K: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:47:18
   |
44 | impl<K, V, S> AHashMap<K, V, S> where S: BuildHasher 
   |                                                     - help: consider further restricting type parameter `K`: `, K: std::cmp::Eq`
...
47 |         AHashMap(HashMap::with_hasher(hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_hasher`

error[E0277]: the trait bound `K: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:47:18
   |
44 | impl<K, V, S> AHashMap<K, V, S> where S: BuildHasher 
   |                                                     - help: consider further restricting type parameter `K`: `, K: std::hash::Hash`
...
47 |         AHashMap(HashMap::with_hasher(hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_hasher`

error[E0277]: the trait bound `K: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:51:18
   |
44 | impl<K, V, S> AHashMap<K, V, S> where S: BuildHasher 
   |                                                     - help: consider further restricting type parameter `K`: `, K: std::cmp::Eq`
...
51 |         AHashMap(HashMap::with_capacity_and_hasher(capacity, hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `K: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:51:18
   |
44 | impl<K, V, S> AHashMap<K, V, S> where S: BuildHasher 
   |                                                     - help: consider further restricting type parameter `K`: `, K: std::hash::Hash`
...
51 |         AHashMap(HashMap::with_capacity_and_hasher(capacity, hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `K`
   |
   = note: required by `std::collections::HashMap::<K, V, S>::with_capacity_and_hasher`

error[E0599]: no method named `fmt` found for struct `std::collections::HashMap<K, V, S>` in the current scope
   --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_map.rs:258:16
    |
258 |         self.0.fmt(fmt)
    |                ^^^ method not found in `std::collections::HashMap<K, V, S>`
    |
    = note: the method `fmt` exists but the following trait bounds were not satisfied:
            `std::collections::HashMap<K, V, S> : std::fmt::Debug`

error[E0277]: the trait bound `T: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:34:18
   |
32 | impl<T> AHashSet<T, RandomState> 
   |      - help: consider restricting this bound: `T: std::cmp::Eq`
33 |     pub fn new() -> Self 
34 |         AHashSet(HashSet::with_hasher(RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_hasher`

error[E0277]: the trait bound `T: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:34:18
   |
32 | impl<T> AHashSet<T, RandomState> 
   |      - help: consider restricting this bound: `T: std::hash::Hash`
33 |     pub fn new() -> Self 
34 |         AHashSet(HashSet::with_hasher(RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_hasher`

error[E0277]: the trait bound `T: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:38:18
   |
32 | impl<T> AHashSet<T, RandomState> 
   |      - help: consider restricting this bound: `T: std::cmp::Eq`
...
38 |         AHashSet(HashSet::with_capacity_and_hasher(capacity, RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `T: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:38:18
   |
32 | impl<T> AHashSet<T, RandomState> 
   |      - help: consider restricting this bound: `T: std::hash::Hash`
...
38 |         AHashSet(HashSet::with_capacity_and_hasher(capacity, RandomState::default()))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `T: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:45:18
   |
42 | impl<T, S> AHashSet<T, S> where S: BuildHasher 
   |                                               - help: consider further restricting type parameter `T`: `, T: std::cmp::Eq`
...
45 |         AHashSet(HashSet::with_hasher(hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_hasher`

error[E0277]: the trait bound `T: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:45:18
   |
42 | impl<T, S> AHashSet<T, S> where S: BuildHasher 
   |                                               - help: consider further restricting type parameter `T`: `, T: std::hash::Hash`
...
45 |         AHashSet(HashSet::with_hasher(hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_hasher`

error[E0277]: the trait bound `T: std::cmp::Eq` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:49:18
   |
42 | impl<T, S> AHashSet<T, S> where S: BuildHasher 
   |                                               - help: consider further restricting type parameter `T`: `, T: std::cmp::Eq`
...
49 |         AHashSet(HashSet::with_capacity_and_hasher(capacity, hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_capacity_and_hasher`

error[E0277]: the trait bound `T: std::hash::Hash` is not satisfied
  --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:49:18
   |
42 | impl<T, S> AHashSet<T, S> where S: BuildHasher 
   |                                               - help: consider further restricting type parameter `T`: `, T: std::hash::Hash`
...
49 |         AHashSet(HashSet::with_capacity_and_hasher(capacity, hash_builder))
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `T`
   |
   = note: required by `std::collections::HashSet::<T, S>::with_capacity_and_hasher`

error[E0599]: no method named `fmt` found for struct `std::collections::HashSet<T, S>` in the current scope
   --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:217:16
    |
217 |         self.0.fmt(fmt)
    |                ^^^ method not found in `std::collections::HashSet<T, S>`
    |
    = note: the method `fmt` exists but the following trait bounds were not satisfied:
            `std::collections::HashSet<T, S> : std::fmt::Debug`

error[E0277]: the trait bound `T: std::cmp::Eq` is not satisfied
   --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:274:18
    |
270 | impl<T> Default for AHashSet<T, RandomState> 
    |      - help: consider restricting this bound: `T: std::cmp::Eq`
...
274 |         AHashSet(HashSet::default())
    |                  ^^^^^^^^^^^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `T`
    |
    = note: required because of the requirements on the impl of `std::default::Default` for `std::collections::HashSet<T, random_state::RandomState>`
    = note: required by `std::default::Default::default`

error[E0277]: the trait bound `T: std::hash::Hash` is not satisfied
   --> /Users/ania/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.6.3/src/hash_set.rs:274:18
    |
270 | impl<T> Default for AHashSet<T, RandomState> 
    |      - help: consider restricting this bound: `T: std::hash::Hash`
...
274 |         AHashSet(HashSet::default())
    |                  ^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` is not implemented for `T`
    |
    = note: required because of the requirements on the impl of `std::default::Default` for `std::collections::HashSet<T, random_state::RandomState>`
    = note: required by `std::default::Default::default`

error: aborting due to 20 previous errors

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `ahash`.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `flamegraph v0.4.0`, intermediate artifacts can be found at `/var/folders/fl/dr1_kh0d5xjdsxcd5x8pvb_w0000gn/T/cargo-installllCFHI`

Caused by:
  build failed

有人可以帮忙吗?我应该先安装其他东西吗?

【问题讨论】:

你有一个相当旧的编译器版本吗?它似乎需要relaxed a while ago 的界限。 @mcarton 我有rustc 1.42.0 【参考方案1】:

flamegraph 似乎正在利用Hashmap 上的宽松特征界限,即released in Rust 1.43:

版本 1.43.0 (2020-04-23)

Relaxed some of the trait bounds on HashMap and HashSet.

如果你想使用火焰图,你必须更新你的 rustc 版本。

【讨论】:

以上是关于Rust 和 Flamegraph:使用 cargo 安装时出现一堆错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 Msys2 为 mingw 安装 Rust 和 Cargo 的分步说明?

使用perf + FlameGraph生成进程火焰图

Docker中使用FlameGraph分析JVM应用性能

Golang FlameGraph(火焰图)

honest-profiler+hprof2flamegraph 基础的扩展

性能工具之 FlameGraph 火焰图