3
votes

When I use my fork of async-trait as a dependency, it fails to compile due to syn::* types equality. All is green in async-trait CI checks. To reproduce, start a new cargo lib project and add to Cargo.toml:

[dependencies]
syn = { version = "1.0.39", features = ["full"] }

And in lib.rs:

pub fn cmp(a: syn::Path, b: syn::Path) -> bool {
    a == b
}

Compiling on Rust 1.46.0 results in an error:

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

syn::Path implements Eq/PartialEq with feature "full" or "derive":

use syn; // 1.0.33

fn cmp(a: syn::Path, b: syn::Path) -> bool {
    a == b
}

I explored that syn's PartialEq and Eq trait implementations are behind the "full" or "derive" feature gate, but I still have no clue.

Tried version 1.0.33 explicitly, that works in playground, same result on my PC.

I've gone through the hurdle of ripping async-trait apart and folding it back together, but this is above my skills.

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

cargo tree on a fresh project with syn:

tmp v0.1.0 (/home/debian/Documents/Projects/tmp)
└── syn v1.0.39
    ├── proc-macro2 v1.0.19
    │   └── unicode-xid v0.2.1
    ├── quote v1.0.7
    │   └── proc-macro2 v1.0.19 (*)
    └── unicode-xid v0.2.1
1

1 Answers

8
votes

While the type syn::Path is available when either the feature full or derive is enabled, some of the traits implemented for that type aren't.

In particular, as per syn's documentation of optional features, the extra-traits feature is required to get PartialEq:

extra-traits — Debug, Eq, PartialEq, Hash impls for all syntax tree types.

Therefore you only need adjust your Cargo.toml with

syn = { version = "1.0.39", features = ["full", "extra-traits"] }