syntect icon indicating copy to clipboard operation
syntect copied to clipboard

Improve error message when regex engine unspecified

Open kornelski opened this issue 5 years ago • 4 comments

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.

kornelski avatar May 09 '20 15:05 kornelski

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

keith-hall avatar May 09 '20 17:05 keith-hall

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 ❤️

trishume avatar May 09 '20 19:05 trishume

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.

kornelski avatar May 10 '20 12:05 kornelski

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.

Keats avatar May 16 '20 10:05 Keats