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

Use compile_error! when both flate2_zlib and flate2_rust features are disabled #53

Closed
LoganDark opened this issue Jan 16, 2022 · 2 comments

Comments

@LoganDark
Copy link
Contributor

LoganDark commented Jan 16, 2022

Currently, when both flate features are disabled, you get piles of cryptic error messages like this:

error[E0433]: failed to resolve: use of undeclared crate or module `miniz_oxide`
 --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:6:5
  |
6 | use miniz_oxide::deflate::core::CompressorOxide;
  |     ^^^^^^^^^^^ use of undeclared crate or module `miniz_oxide`

error[E0433]: failed to resolve: use of undeclared crate or module `miniz_oxide`
 --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:7:5
  |
7 | use miniz_oxide::inflate::stream::InflateState;
  |     ^^^^^^^^^^^ use of undeclared crate or module `miniz_oxide`

error[E0432]: unresolved imports `miniz_oxide`, `crate::ffi::Backend`, `crate::ffi::Deflate`, `crate::ffi::DeflateBackend`, `crate::ffi::ErrorMessage`, `crate::ffi::In
flate`, `crate::ffi::InflateBackend`, `miniz_oxide::deflate::core::CompressorOxide`, `miniz_oxide::inflate::stream::InflateState`
 --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/mem.rs:6:24
  |
6 | use crate::ffi::{self, Backend, Deflate, DeflateBackend, ErrorMessage, Inflate, InflateBackend};
  |                        ^^^^^^^  ^^^^^^^  ^^^^^^^^^^^^^^  ^^^^^^^^^^^^  ^^^^^^^  ^^^^^^^^^^^^^^
  |
 ::: /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:6:5
  |
6 | use miniz_oxide::deflate::core::CompressorOxide;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | use miniz_oxide::inflate::stream::InflateState;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 | pub use miniz_oxide::*;
  |         ^^^^^^^^^^^ use of undeclared crate or module `miniz_oxide`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:10:32
   |
10 | pub const MZ_NO_FLUSH: isize = MZFlush::None as isize;
   |                                ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:11:37
   |
11 | pub const MZ_PARTIAL_FLUSH: isize = MZFlush::Partial as isize;
   |                                     ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:12:34
   |
12 | pub const MZ_SYNC_FLUSH: isize = MZFlush::Sync as isize;
   |                                  ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:13:34
   |
13 | pub const MZ_FULL_FLUSH: isize = MZFlush::Full as isize;
   |                                  ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:14:30
   |
14 | pub const MZ_FINISH: isize = MZFlush::Finish as isize;
   |                              ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared type `DataFormat`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:31:9
   |
31 |         DataFormat::Zlib
   |         ^^^^^^^^^^ use of undeclared type `DataFormat`

error[E0433]: failed to resolve: use of undeclared type `DataFormat`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:33:9
   |
33 |         DataFormat::Raw
   |         ^^^^^^^^^^ use of undeclared type `DataFormat`

error[E0433]: failed to resolve: use of undeclared type `InflateState`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:58:20
   |
58 |             inner: InflateState::new_boxed(format),
   |                    ^^^^^^^^^^^^ use of undeclared type `InflateState`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:70:21
   |
70 |         let flush = MZFlush::new(flush as i32).unwrap();
   |                     ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared crate or module `inflate`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:72:19
   |
72 |         let res = inflate::stream::inflate(&mut self.inner, input, output, flush);
   |                   ^^^^^^^ use of undeclared crate or module `inflate`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:78:17
   |
78 |                 MZStatus::Ok => Ok(Status::Ok),
   |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:79:17
   |
79 |                 MZStatus::StreamEnd => Ok(Status::StreamEnd),
   |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:80:17
   |
80 |                 MZStatus::NeedDict => {
   |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZError`
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:85:17
   |
85 |                 MZError::Buf => Ok(Status::BufError),
   |                 ^^^^^^^ use of undeclared type `MZError`

error[E0433]: failed to resolve: use of undeclared type `MZFlush`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:148:21
    |
148 |         let flush = MZFlush::new(flush as i32).unwrap();
    |                     ^^^^^^^ use of undeclared type `MZFlush`

error[E0433]: failed to resolve: use of undeclared crate or module `deflate`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:149:19
    |
149 |         let res = deflate::stream::deflate(&mut self.inner, input, output, flush);
    |                   ^^^^^^^ use of undeclared crate or module `deflate`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:155:17
    |
155 |                 MZStatus::Ok => Ok(Status::Ok),
    |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:156:17
    |
156 |                 MZStatus::StreamEnd => Ok(Status::StreamEnd),
    |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZStatus`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:157:17
    |
157 |                 MZStatus::NeedDict => mem::compress_failed(ErrorMessage),
    |                 ^^^^^^^^ use of undeclared type `MZStatus`

error[E0433]: failed to resolve: use of undeclared type `MZError`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:160:17
    |
160 |                 MZError::Buf => Ok(Status::BufError),
    |                 ^^^^^^^ use of undeclared type `MZError`

error[E0412]: cannot find type `DataFormat` in this scope
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:29:43
   |
29 | fn format_from_bool(zlib_header: bool) -> DataFormat {
   |                                           ^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `InflateState` in this scope
  --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:38:16
   |
37 | pub struct Inflate {
   |                   - help: you might be missing a type parameter: `<InflateState>`
38 |     inner: Box<InflateState>,
   |                ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `CompressorOxide` in this scope
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:111:16
    |
110 | pub struct Deflate {
    |                   - help: you might be missing a type parameter: `<CompressorOxide>`
111 |     inner: Box<CompressorOxide>,
    |                ^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `CompressorOxide` in this scope
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/ffi/rust.rs:131:28
    |
126 | impl DeflateBackend for Deflate {
    |     - help: you might be missing a type parameter: `<CompressorOxide>`
...
131 |         let mut inner: Box<CompressorOxide> = Box::default();
    |                            ^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `MZ_DEFAULT_WINDOW_BITS` in module `ffi`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/mem.rs:202:59
    |
202 |             inner: Deflate::make(level, zlib_header, ffi::MZ_DEFAULT_WINDOW_BITS as u8),
    |                                                           ^^^^^^^^^^^^^^^^^^^^^^ not found in `ffi`

error[E0425]: cannot find value `MZ_DEFAULT_WINDOW_BITS` in module `ffi`
   --> /home/logandark/.cargo/registry/src/github.com-1ecc6299db9ec823/flate2-1.0.22/src/mem.rs:382:52
    |
382 |             inner: Inflate::make(zlib_header, ffi::MZ_DEFAULT_WINDOW_BITS as u8),
    |                                                    ^^^^^^^^^^^^^^^^^^^^^^ not found in `ffi`

A compile_error! should probably be added somewhere to make it clear to the user why allsorts is imploding:

#[cfg(not(any(feature = "flate2_zlib", feature = "flate2_rust"))]
compile_error!("either the `flate2_zlib` or `flate2_rust` feature must be enabled");

The rest of the library should also probably be omitted to make it easier to find the custom message.

@wezm
Copy link
Contributor

wezm commented Jan 18, 2022

Good idea, I've opened a PR if you wanted to cast your eyes over it.

@wezm
Copy link
Contributor

wezm commented Jan 18, 2022

Fixed by 76f594c

@wezm wezm closed this as completed Jan 18, 2022
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 a pull request may close this issue.

2 participants