Skip to content

Conversation

filipeom
Copy link

@filipeom filipeom commented Aug 4, 2025

Previously, enabling with-tokio would also activate the default feature (with-futures), because Cargo includes default features by design. This would lead to a compilation error due to duplicate definitions from both use statements. Example:

$ cargo build --features with-tokio
error[E0252]: the name `AsyncRead` is defined multiple times
 --> src/ascii.rs:8:34
  |
5 | use futures::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                    --------- previous import of the trait `AsyncRead` here
...
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                  ^^^^^^^^^ `AsyncRead` reimported here
  |
  = note: `AsyncRead` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead as OtherAsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                            +++++++++++++++++

error[E0252]: the name `AsyncReadExt` is defined multiple times
 --> src/ascii.rs:8:45
  |
5 | use futures::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                               ------------ previous import of the trait `AsyncReadExt` here
...
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                             ^^^^^^^^^^^^ `AsyncReadExt` reimported here
  |
  = note: `AsyncReadExt` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt as OtherAsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                          ++++++++++++++++++++

error[E0252]: the name `AsyncWrite` is defined multiple times
 --> src/ascii.rs:8:59
  |
5 | use futures::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                             ---------- previous import of the trait `AsyncWrite` here
...
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                           ^^^^^^^^^^ `AsyncWrite` reimported here
  |
  = note: `AsyncWrite` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite as OtherAsyncWrite, AsyncWriteExt, BufReader};
  |                                                                      ++++++++++++++++++

error[E0252]: the name `AsyncWriteExt` is defined multiple times
 --> src/ascii.rs:8:71
  |
5 | use futures::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                                         ------------- previous import of the trait `AsyncWriteExt` here
...
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                                       ^^^^^^^^^^^^^ `AsyncWriteExt` reimported here
  |
  = note: `AsyncWriteExt` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt as OtherAsyncWriteExt, BufReader};
  |                                                                                     +++++++++++++++++++++

error[E0252]: the name `BufReader` is defined multiple times
 --> src/ascii.rs:8:86
  |
5 | use futures::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                                                        --------- previous import of the type `BufReader` here
...
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                                                                                      ^^^^^^^^^ `BufReader` reimported here
  |
  = note: `BufReader` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader as OtherBufReader};
  |                                                                                                +++++++++++++++++

warning: unused imports: `AsyncBufReadExt`, `AsyncReadExt`, `AsyncRead`, `AsyncWriteExt`, `AsyncWrite`, and `BufReader`
 --> src/ascii.rs:8:17
  |
8 | use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader};
  |                 ^^^^^^^^^^^^^^^  ^^^^^^^^^  ^^^^^^^^^^^^  ^^^^^^^^^^  ^^^^^^^^^^^^^  ^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0252`.
warning: `memcache-async` (lib) generated 1 warning
error: could not compile `memcache-async` (lib) due to 6 previous errors; 1 warning emitted

This commit replaces the separate #[cfg] blocks with a single cfg_if macro. This creates a prioritized selection for the io backend.

Previously, enabling `with-tokio` would also activate the `default` feature
(`with-futures`), because Cargo includes default features by design.
This would lead to a compilation error due to duplicate definitions from both
`use` statements.

This commit replaces the separate `#[cfg]` blocks with a single `cfg_if`
macro. This creates a prioritized selection for the io backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant