trishume / syntect

Rust library for syntax highlighting using Sublime Text syntax definitions.
https://docs.rs/syntect
MIT License
1.89k stars 131 forks source link

Improve error message when regex engine unspecified #291

Open kornelski opened 4 years ago

kornelski commented 4 years ago

If I add dependency like this:

syntect = { version = "4", default-features = false, features = ["parsing"] }

it doesn't compile:

error[E0282]: type annotations needed
  --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/syntect-4.1.1/src/parsing/regex.rs:30:20
   |
30 |             regex: AtomicLazyCell::new(),
   |                    ^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`

I'm deliberately avoiding pulling in onig-sys, because it has heavy bindgen dependency that I can't get to work.

keith-hall commented 4 years ago

probably you need to explicitly reference the fancy-regex feature instead then - if you want parsing features, you need a regex engine :)

trishume commented 4 years ago

Darn that's definitely a crappy error message. Because of the way features work we need to make you specify a regex engine feature if you use the "parsing" feature, but I think it's definitely possible to have a better error message that tells you this. In the mean time try

syntect = { version = "4", default-features = false, features = ["parsing", "regex-fancy"] }

You may also want "dump_load", "assets" or even just "default-fancy" depending on your use case.

I'm normally even slower at responding to issues but I consider you to have priority support because I like http://lib.rs/ and ImageOptim so much ❤️

kornelski commented 4 years ago

Oh, I see. Exclusive features in Cargo are not great.

Two ideas for you:

Instead of #[cfg(feature = "fancy-regex")] use a bit more verbose #[cfg(all(feature = "parsing"), not(feature = "regex-onig"))] to make one engine enable itself when necessary.

or add somewhere early in the crate:

#[cfg(all(feature = "parsing"), not(any(feature = "regex-onig", feature = "fancy-regex"))]
type Oops = PleaseEnableAtLeastOneRegexEngine;

to cause a compilation error that looks more intentional.

Keats commented 4 years ago

I've made a PR updating onig to not use the bindgen dependencies: https://github.com/trishume/syntect/pull/293 which would solve the original issue.