-
Notifications
You must be signed in to change notification settings - Fork 163
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
proptest-derive: #[inline] + no_cfg
Cargo feature gate
#106
base: proptest-derive
Are you sure you want to change the base?
Conversation
The PR is pretty much done and is working; The question now is whether this is the design we want. ( could probably use another test to ensure that when |
no_cfg
Cargo feature gateno_cfg
Cargo feature gate
I’ll try and give proptest-derive a spin tonight and see how I like this for my usecase. |
It does seem like a problem to me, unless I'm misunderstanding something. Crate [dependencies]
proptest-derive = { version = "xx", default-features = false }
[dev-dependencies]
proptest = "xx" Crate [dependencies]
proptest-derive = "xx"
proptest = "xx" Crate [dependencies]
dep-a = "yy"
dep-b = "zz"
|
Aw! bummer :( This problem could be fixed with: #[cfg(all(
any(test, feature = "prop"),
accessible(::proptest::prelude::Arbitrary)
// `dep-a` will not have `::proptest::*` accessible so you get no impl
// and thus also no error.
)]
impl Arbitrary for Foo { ... } but unfortunately we don't have At this point it might be best to just standardize on (We should also retain |
I'd still prefer it to "just work" for crates that don't want to / need to export their New proposal:
|
I think the new proposal works even for those who want to do: #[derive(Debug)]
#[cfg_attr(feature = "prop", derive(Arbitrary))]
struct Foo; as well... so that is good. cc @Nemo157 what do you think? does that work for you? PS: I would not name the feature |
Is there something I don't know here? I was deliberately using feature == optional crate so that there's less to wire up. |
@AltSysrq the problem is when you have a dependency that has its own optional It may pay to talk to the |
Oh so someone (crate "alpha") would do: name = "alpha"
[dependencies]
proptest = { version = "x.y", optional = true } and then someone else (crate "beta") would do: name = "beta"
[dependencies]
# For the direct stuff we want to derive:
proptest = { version = "x.y", optional = true }
[dependencies.alpha]
version = "x.y"
features = ?
#^ How do we make: proptest imply alpha/proptest? https://doc.rust-lang.org/cargo/reference/manifest.html#rules
So we cannot do: name = "beta"
[dependencies]
# For the direct stuff we want to derive:
proptest = { version = "x.y", optional = true }
[dependencies.alpha]
version = "x.y"
[features]
proptest = ["alpha/proptest"] |
Huh, that's pretty awkward. I'd be fine with doing |
@AltSysrq yeah haha; we've been running into 3 different Rust language / Cargo walls (limitations) in a very short span of time. =P I'll try to adapt the PR into the new proposal (but |
Just found this PR in book and there were 5 years since the last update. Is it alive? If not, maybe remove the mention from the book? |
Changes:
Formatting fix + rewording in
proptest-derive/Cargo.toml
.A default enabled cargo feature
no_cfg
is introduced inproptest-derive/Cargo.toml
.Unless
no_cfg
is active then#[cfg(test)]
will be put on implementations (generated by#[derive(Arbitrary)]
).This entails that you can get the
#[cfg(test)]
behavior withdefault-features = false
.#[inline]
is put onarbitrary_with
generated by#[derive(Arbitrary)]
. This change was suggested by eddyb; the idea being that we don't do ahead-of-time codegen of the implementations produced.Tests for the
no_cfg
behavior above; in particular, we setdefault-features = false
and ensure thatArbitrary
isn't provided.One drawback to this approach where cargo is used is that if one of the dependencies use
no_cfg
then all of them will; but I don't think this should be that much of a problem; I think it is better than the ergonomics hit you get by having to annotate eachderive(Arbitrary)
location instead.cc #102, @Nemo157, @Eh2406