二元运算 == 不能应用于类型 syn::Path

Rbj*_*bjz 3 dependencies compiler-errors rust rust-cargo

当我使用async-trait 的分支作为依赖项时,由于syn::*类型相等,它无法编译。所有在 async-trait CI checks 中都是绿色的。要重现,请启动一个新的货物库项目并添加到 Cargo.toml:

[dependencies]
syn = { version = "1.0.39", features = ["full"] }
Run Code Online (Sandbox Code Playgroud)

在 lib.rs 中:

pub fn cmp(a: syn::Path, b: syn::Path) -> bool {
    a == b
}
Run Code Online (Sandbox Code Playgroud)

在 Rust 1.46.0 上编译会导致错误:

[dependencies]
syn = { version = "1.0.39", features = ["full"] }
Run Code Online (Sandbox Code Playgroud)

syn::Path实现Eq/PartialEq具有“完整”或“派生”功能

pub fn cmp(a: syn::Path, b: syn::Path) -> bool {
    a == b
}
Run Code Online (Sandbox Code Playgroud)

我探索了 synPartialEqEqtrait 实现是在“完整”或“派生”功能门之后,但我仍然不知道。

明确尝试了 1.0.33 版,它在操场上工作,在我的 PC 上结果相同。

我已经克服了将 async-trait 分开并将其重新组合在一起的障碍,但这超出了我的技能。

  • rustc 1.46.0 (04488afe3 2020-08-24)
  • 货物 1.46.0 (149022b1d 2020-07-17)

cargo tree 在使用 syn 的新项目中:

error[E0369]: binary operation `==` cannot be applied to type `syn::Path`
 --> src/lib.rs:4:7
  |
4 |     a == b
  |     - ^^ - syn::Path
  |     |
  |     syn::Path

error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)

mca*_*ton 8

虽然该类型 syn::Path在功能fullderive启用时可用,但为该类型实现的某些特征不可用。

特别是,根据syn可选功能的文档,该extra-traits功能需要获得PartialEq

extra-traits — Debug、Eq、PartialEq、Hash impls 适用于所有语法树类型。

因此你只需要调整你Cargo.toml

syn = { version = "1.0.39", features = ["full", "extra-traits"] }
Run Code Online (Sandbox Code Playgroud)