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

Could not compile some features without default features turned on #237

Closed
vjtch opened this issue Aug 19, 2024 · 2 comments
Closed

Could not compile some features without default features turned on #237

vjtch opened this issue Aug 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@vjtch
Copy link

vjtch commented Aug 19, 2024

Describe the bug
When selecting only _deflate-any or deflate-flate2 feature with default-features turned off it's not possible to compile zip crate. Both features are missing some flate2 dependencies.

To Reproduce
In Cargo.toml use this dependency settings

zip = { version = "2.1.6", default-features = false, features = ["_deflate-any"] }

Expected behavior
Feature should enable all necessary components to successfully compile or at least provide compilation error with message which features user should add.

Temporary solution
In Cargo.toml use this dependency settings (with added deflate feature)

zip = { version = "2.1.6", default-features = false, features = ["_deflate-any", "deflate"] }

Possible fix
For _deflate-any add deflate-flate2 and for deflate-flate2 add flate2/rust_backend (produces unused import warning).

[features]
_deflate-any = ["deflate-flate2"]
deflate-flate2 = ["flate2/any_impl", "flate2/rust_backend", "_deflate-any"]

Produced errors (_deflate-any, for deflate-flate2 are different)

error[E0433]: failed to resolve: use of undeclared crate or module `flate2`
   --> /zip2/src/compression.rs:195:14
    |
195 |     Deflated(flate2::bufread::DeflateDecoder<R>),
    |              ^^^^^^ use of undeclared crate or module `flate2`

error[E0433]: failed to resolve: use of undeclared crate or module `flate2`
   --> /zip2/src/compression.rs:234:40
    |
234 |                 Decompressor::Deflated(flate2::bufread::DeflateDecoder::new(reader))
    |                                        ^^^^^^ use of undeclared crate or module `flate2`

warning: unused import: `core::num::NonZeroU64`
  --> /zip2/src/write.rs:19:5
   |
19 | use core::num::NonZeroU64;
   |     ^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error[E0433]: failed to resolve: use of undeclared type `Compression`
    --> /zip2/src/write.rs:1597:25
     |
1597 |                         Compression::default().level() as i64
     |                         ^^^^^^^^^^^ use of undeclared type `Compression`

error[E0308]: mismatched types
    --> /zip2/src/write.rs:1590:48
     |
1590 |                   CompressionMethod::Deflated => {
     |  ________________________________________________^
1591 | |                     let default = if cfg!(all(
1592 | |                         feature = "deflate-zopfli",
1593 | |                         not(feature = "deflate-flate2")
...    |
1644 | |                     }
1645 | |                 }
     | |_________________^ expected `Result<Box<...>, ...>`, found `()`
     |
     = note:   expected enum `Result<Box<(dyn FnOnce(MaybeEncrypted<W>) -> write::GenericZipWriter<W> + 'static)>, ZipError>`
             found unit type `()`

error[E0433]: failed to resolve: use of undeclared type `Compression`
    --> /zip2/src/write.rs:1761:9
     |
1761 |         Compression::fast().level() as i64
     |         ^^^^^^^^^^^ use of undeclared type `Compression`

error[E0433]: failed to resolve: use of undeclared type `Compression`
    --> /zip2/src/write.rs:1763:9
     |
1763 |         Compression::best().level() as i64 + 1
     |         ^^^^^^^^^^^ use of undeclared type `Compression`

error[E0433]: failed to resolve: use of undeclared type `Compression`
    --> /zip2/src/write.rs:1766:15
     |
1766 |     let max = Compression::best().level() as i64
     |               ^^^^^^^^^^^ use of undeclared type `Compression`
@vjtch vjtch added the bug Something isn't working label Aug 19, 2024
@CommanderStorm
Copy link

features starting with _ are private features. They are not to be relied on by external users.
See the relevant cargo issue for the discussion rust-lang/cargo#10882

They are not listed on docs.rs like f.ex. here: https://docs.rs/crate/zip/2.1.6/features

@Pr0methean
Copy link
Member

As well, README.md states (emphasis added):

  • deflate-flate2: Combine this with any flate2 feature flag that enables a back-end, to support deflate compression at quality 1..=9.

Pr0methean added a commit that referenced this issue Sep 2, 2024
… when missing a back-end is more readable

Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants