magiclen / whois-rust

This is a WHOIS client library for Rust, inspired by https://github.com/hjr265/node-whois
MIT License
20 stars 9 forks source link

`whois-rust` relies on the fact that `validators-derive` activates all of `validators` features, breaking projects using the Rust 2021 edition feature resolver #4

Closed daboross closed 2 years ago

daboross commented 2 years ago

Hi,

This bug report stems from this users.rust-lang.org issue.

The Rust 2021 edition enables a new cargo feature resolver which resolves features separately for build dependencies - such as derive crates - and regular dependencies. It looks like this is a rare case of a project's edition affecting everything in its dependency tree, so projects depending on whois-rust using Rust 2021 edition will enable this different resolver for whois-rust as well.

whois-rust uses types only present in validators when the "host" feature is enabled. However, it only declares a dependency on validators-derive/host, not validators/host.

This was never an issue, as validators-derive/host depends on validators/host, but with the new feature resolver, validators-derive and its dependencies compiled for the build process are treated completely separately from validators for the compiled library, so the validators imported into whois-rust no longer has the host feature enabled.

The end result is this, for any project depending on whois-rust using the 2021 edition:

$ cargo check
    Checking tokio v1.16.1
    Checking validators v0.23.1
    Checking trust-dns-proto v0.20.4
    Checking trust-dns-client v0.20.4
    Checking whois-rust v1.4.0
error[E0432]: unresolved import `crate::validators::models::Host`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:1:5
  |
1 | use crate::validators::models::Host;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Host` in `models`

error[E0432]: unresolved import `crate::validators::models::Host`
  --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is.rs:22:5
   |
22 | use crate::validators::models::Host;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Host` in `models`

error[E0432]: unresolved import `crate::validators::HostError`
  --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_error.rs:10:5
   |
10 | use crate::validators::HostError;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `HostError` in the root

error[E0432]: unresolved import `crate::validators::models::Host`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:1:5
  |
1 | use crate::validators::models::Host;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Host` in `models`

error[E0433]: failed to resolve: could not find `HostError` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `HostError` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `Host` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `Host` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `idna` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `idna` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `HostError` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `HostError` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `Host` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `Host` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `idna` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ could not find `idna` in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Host` in module `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: there is an enum variant `trust_dns_client::rr::rdata::key::KeyUsage::Host`; try using the variant's enum
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, trust_dns_client::rr::rdata::key::KeyUsage)]
  |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `HostError` in module `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: there is an enum variant `crate::WhoIsError::HostError`; try using the variant's enum
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, crate::WhoIsError)]
  |                                             ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: could not find `Ipv6Addr` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
1 | use std::net::Ipv6Addr;
  |

error[E0433]: failed to resolve: could not find `Ipv4Addr` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/target.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
1 | use std::net::Ipv4Addr;
  |

error[E0412]: cannot find type `Host` in module `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: there is an enum variant `trust_dns_client::rr::rdata::key::KeyUsage::Host`; try using the variant's enum
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, trust_dns_client::rr::rdata::key::KeyUsage)]
  |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `HostError` in module `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: there is an enum variant `crate::WhoIsError::HostError`; try using the variant's enum
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, crate::WhoIsError)]
  |                                             ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: could not find `Ipv6Addr` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
1 | use std::net::Ipv6Addr;
  |

error[E0433]: failed to resolve: could not find `Ipv4Addr` in `validators_prelude`
 --> /home/daboross/.cargo/registry/src/github.com-1ecc6299db9ec823/whois-rust-1.4.0/src/who_is_host.rs:4:45
  |
4 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
  |                                             ^^^^^^^^^ not found in `validators_prelude`
  |
  = note: this error originates in the derive macro `Validator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
  |
1 | use std::net::Ipv4Addr;
  |

Some errors have detailed explanations: E0412, E0432, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `whois-rust` due to 18 previous errors

I suggest a simple fix of replacing validators = "0.23" in Cargo.toml with:

[dependencies.validators]
version = "0.23"
features = ["host"]

I'd submit a PR, but I can't seem to find the sources for whois-rust 1.4.0, so I hope this will do.

Esc4iCEscEsc commented 2 years ago

@magiclen any interest in having this fixed? Or at least publish the source-code for 1.4.0 so others could fork it to have a maintained library?

magiclen commented 2 years ago

@daboross @Esc4iCEscEsc

Sorry, I have been busy recently. I will update this crate and validators in the next 3 days.

magiclen commented 2 years ago

validators has been updated to 0.24 now. It can be compiled in Rust 2021 edition.

daboross commented 2 years ago

Awesome, thanks so much for the quick fix for this!