linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.52k stars 568 forks source link

Build error of an empty project: `syn::Type` doesn't implement `Debug` #2373

Closed gameraccoon closed 1 year ago

gameraccoon commented 1 year ago

I tried to add the druid crate to an empty binary (application) but it failed to build for me.

OS: Pop!_OS 22.04 LTS Rustc: 1.69.0

Repro steps:

cargo init my_app
cd my_app
cargo add druid
cargo run

Expected behavior: the default application builds and prints "Hello, world!"

Observed behavior: build fails with these errors:

error[E0277]: `syn::Type` doesn't implement `Debug`
  --> /home/gameraccoon/.cargo/registry/src/github.com-1ecc6299db9ec823/druid-derive-0.5.0/src/attr.rs:66:5
   |
63 | #[derive(Debug)]
   |          ----- in this derive macro expansion
...
66 |     pub ty: syn::Type,
   |     ^^^^^^^^^^^^^^^^^ `syn::Type` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |
   = help: the trait `Debug` is not implemented for `syn::Type`
   = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `ExprPath` doesn't implement `Debug`
  --> /home/gameraccoon/.cargo/registry/src/github.com-1ecc6299db9ec823/druid-derive-0.5.0/src/attr.rs:75:12
   |
71 | #[derive(Debug, PartialEq, Eq)]
   |          ----- in this derive macro expansion
...
75 |     SameFn(ExprPath),
   |            ^^^^^^^^ `ExprPath` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |
   = help: the trait `Debug` is not implemented for `ExprPath`
   = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0369]: binary operation `==` cannot be applied to type `ExprPath`
  --> /home/gameraccoon/.cargo/registry/src/github.com-1ecc6299db9ec823/druid-derive-0.5.0/src/attr.rs:75:12
   |
71 | #[derive(Debug, PartialEq, Eq)]
   |                 --------- in this derive macro expansion
...
75 |     SameFn(ExprPath),
   |            ^^^^^^^^
   |
   = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `ExprPath: std::cmp::Eq` is not satisfied
  --> /home/gameraccoon/.cargo/registry/src/github.com-1ecc6299db9ec823/druid-derive-0.5.0/src/attr.rs:75:12
   |
71 | #[derive(Debug, PartialEq, Eq)]
   |                            -- in this derive macro expansion
...
75 |     SameFn(ExprPath),
   |            ^^^^^^^^ the trait `std::cmp::Eq` is not implemented for `ExprPath`
   |
note: required by a bound in `AssertParamIsEq`
  --> /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/cmp.rs:315:1
   = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0369.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `druid-derive` due to 4 previous errors

Also tried: Update rust: rustup update

Clean rust caches:

cargo install cargo-cache
cargo-cache -r all

None of this helped.

What helps is to change druid version to "0.7.0", but I'm really interested to use 0.8.* features.

xStrom commented 1 year ago

What does cargo tree give?

waynr commented 1 year ago

I ran into this also, and figured out the problem is that the extra-traits feature needs to be enabled on the syn dependency in druid-derive. I was about to open a PR to address this, but then I noticed that this project has been discontinued by its maintainers. So I decided not to open the PR.

cyberdoors commented 1 year ago

syn 冲突 执行 cargo tree -d

syn v1.0.109
├── displaydoc v0.2.3 (proc-macro)
│   └── tinystr v0.7.1
│       └── unic-langid-impl v0.9.1
│           └── unic-langid v0.9.1
│               ├── druid v0.8.3
│               │   └── demo2 v0.1.0 (D:\Desktop\tcode\demo2)
│               ├── fluent-bundle v0.15.2
│               │   └── druid v0.8.3 (*)
│               ├── fluent-langneg v0.13.0
│               │   ├── druid v0.8.3 (*)
│               │   └── fluent-bundle v0.15.2 (*)
│               ├── intl-memoizer v0.5.1
│               │   └── fluent-bundle v0.15.2 (*)
│               └── intl_pluralrules v7.0.2
│                   └── fluent-bundle v0.15.2 (*)
└── druid-derive v0.5.0 (proc-macro)
    └── druid v0.8.3 (*)

syn v2.0.15
├── thiserror-impl v1.0.40 (proc-macro)
│   └── thiserror v1.0.40
│       └── fluent-syntax v0.11.0
│           ├── druid v0.8.3 (*)
│           └── fluent-bundle v0.15.2 (*)
└── tracing-attributes v0.1.24 (proc-macro)
    └── tracing v0.1.38
        ├── druid v0.8.3 (*)
        └── druid-shell v0.8.3
            └── druid v0.8.3 (*)
cyberdoors commented 1 year ago

可以通过 使用patch 暂时解决, Carto.toml

[dependencies]
druid = "0.8.3"

[patch.crates-io]
tracing = { git = "https://github.com/tokio-rs/tracing.git", package= "tracing", tag="tracing-0.1.37"}
thiserror = { git = "https://github.com/dtolnay/thiserror.git",  tag="1.0.39"}
jneem commented 1 year ago

I think this is the same as #2374, so closing as fixed. Please re-open if you still see the problem.

xStrom commented 1 year ago

It is the same indeed. Looks like the tracing crate enables the extra-traits feature on syn which is why our tests didn't catch this. Seems like a shortcoming of our testing methodology that it always builds with dev dependencies. Something to look into.

xStrom commented 1 year ago

The bugfix is now published as druid-derive v0.5.1 so the original repro is solved. :tada: