yeslogic / allsorts

Font parser, shaping engine, and subsetter implemented in Rust
https://yeslogic.com/blog/allsorts-rust-font-shaping-engine/
Apache License 2.0
706 stars 23 forks source link

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

Closed LoganDark closed 2 years ago

LoganDark commented 2 years ago

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 commented 2 years ago

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

wezm commented 2 years ago

Fixed by 76f594c