Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The derive feature can cause duplicate import errors #1587

Closed
felinira opened this issue Aug 11, 2024 · 1 comment · Fixed by #1672
Closed

The derive feature can cause duplicate import errors #1587

felinira opened this issue Aug 11, 2024 · 1 comment · Fixed by #1672
Labels
customer-request Documents customer requests.

Comments

@felinira
Copy link

The docs state the following:

However, you may experience better compile times if you instead directly depend on both zerocopy and zerocopy-derive in your Cargo.toml, since doing so will allow Rust to compile these crates in parallel. To do so, do not enable the derive feature, and list both dependencies in your Cargo.toml with the same leading non-zero version number; e.g:

However, this can lead to issues if another dependency in the chain imports zerocopy with the derive feature, as now you suddenly have two macros in scope.

error[E0252]: the name `AsBytes` is defined multiple times
 --> /run/build/abc/cargo/vendor/gvdb-0.7.0/src/read/hash.rs:9:23
  |
8 | use zerocopy::{AsBytes, FromBytes};
  |                ------- previous import of the macro `AsBytes` here
9 | use zerocopy_derive::{AsBytes, FromBytes, FromZeroes};
  |                       ^^^^^^^--
  |                       |
  |                       `AsBytes` reimported here
  |                       help: remove unnecessary import
  |
  = note: `AsBytes` must be defined only once in the macro namespace of this module

which is then only solveable within the dependency that imports zerocopy_derive in this way.

Therefore this usage should probably be discouraged, or warned against for anything other than binary crates.

@felinira felinira added the customer-request Documents customer requests. label Aug 11, 2024
@jswrenn
Copy link
Collaborator

jswrenn commented Aug 11, 2024

Perhaps we should recommend:

- use zerocopy_derive::{AsBytes, FromBytes, FromZeroes};
+ use zerocopy_derive::*;

...so the imports shadow without conflict.

joshlf added a commit that referenced this issue Sep 17, 2024
Clarify advice for how to speed up compile times by importing zerocopy
and zerocopy-derive separately. The updated advice avoids the risk of
duplicate import errors if one of a crate's transitive dependencies adds
zerocopy's `derive` feature.

Closes #1587
github-merge-queue bot pushed a commit that referenced this issue Sep 17, 2024
Clarify advice for how to speed up compile times by importing zerocopy
and zerocopy-derive separately. The updated advice avoids the risk of
duplicate import errors if one of a crate's transitive dependencies adds
zerocopy's `derive` feature.

Closes #1587
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-request Documents customer requests.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants