frozenlib / parse-display

Procedural macro to implement Display and FromStr using common settings.
Apache License 2.0
182 stars 14 forks source link

using crate without regex, once_cell fails #24

Closed classabbyamp closed 2 years ago

classabbyamp commented 2 years ago

when using parse-display without the default features (i.e. parse-display = {version = "0.5.5", default-features = false, features=["std"]}), compilation fails despite those dependencies being marked optional. I think this may be related to #2 or possibly missing #[cfg] attributes.

minimal reproducible example:

cargo.toml

[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
parse-display = {version = "0.5.5", default-features = false, features=["std"]}

src/main.rs

use parse_display as pd;

#[derive(Debug, Clone, pd::Display, pd::FromStr)]
enum EntryType {
    Application,
    Link,
    Directory,
    #[display("{0}")]
    Unknown(String),
}

fn main() {
    println!("Hello, world!");
}
compilation log ```rs Compiling parse-display v0.5.5 Compiling foo v0.1.0 (/tmp/foo) error[E0433]: failed to resolve: could not find `helpers` in `parse_display` --> src/main.rs:3:37 | 3 | #[derive(Debug, Clone, pd::Display, pd::FromStr)] | ^^^^^^^^^^^ could not find `helpers` in `parse_display` | = note: this error originates in the derive macro `pd::FromStr` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0433]: failed to resolve: could not find `helpers` in `parse_display` --> src/main.rs:3:37 | 3 | #[derive(Debug, Clone, pd::Display, pd::FromStr)] | ^^^^^^^^^^^ not found in `parse_display::helpers::once_cell::sync` | = note: this error originates in the derive macro `pd::FromStr` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these items | 1 | use core::lazy::Lazy; | 1 | use std::lazy::Lazy; | help: if you import `Lazy`, refer to it directly | 3 - #[derive(Debug, Clone, pd::Display, pd::FromStr)] 3 + #[derive(Debug, Clone, pd::Display, pd::FromStr)] | For more information about this error, try `rustc --explain E0433`. error: could not compile `foo` due to 2 previous errors ```
frozenlib commented 2 years ago

Thanks for the report.

There were some inconsistencies in features dependencies and #[cfg], which were corrected in 491d6a626f785ccc154c5654f033cee0da7cf706.

classabbyamp commented 2 years ago

hm, my intention was to not depend on the regex and once_cell crates (I don't need that functionality for what I'm doing). the errors persist with parse-display = { git = "https://github.com/frozenlib/parse-display", branch = "master", default-features = false }

frozenlib commented 2 years ago

hm, my intention was to not depend on the regex and once_cell crates (I don't need that functionality for what I'm doing).

For now, code generated by #[derive(FromStr)] requires regex and once_cell crates even if it does not use #[from_str(regex = "...")].

So, to solve that problem, we need to add a function to generate code that does not use regex.

the errors persist with parse-display = { git = "https://github.com/frozenlib/parse-display", branch = "master", default-features = false }

We are getting the errors with the above configuration because parse-display-derive before the change is used. If you use the settings below instead, compile errors will disappear.

[dependencies]
parse-display = { version = "0.5.5", default-features = false, features = [ "std" ] }

[patch.crates-io]
parse-display = { git = 'https://github.com/frozenlib/parse-display', branch = 'master' }