Skip to content

Avoid using cfg with destination-crate feature in proc-macro derive #132

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

Closed

Conversation

BenWiederhake
Copy link
Contributor

Quoting cargo:

using a cfg inside a derive macro will use the cfgs from the
destination crate and not the ones from the defining crate

In these two instances, the cfg was simply used to avoid emitting dead code if the "complete" feature is not desired. By passing the "complete" feature down to the derive crate and evaluating if there, we achieve the same goal, without having to deal with suprisingly-valued and unexpected cfgs downstream.

Discovered while trying to integrate uutils-args into coreutils: https://github.com/uutils/coreutils/actions/runs/14420666926/job/40442804575?pr=7739

This is not my favourite approach.

Alternatively, we could just remove the feature-flag and make it part of the permanent API, as implemented in #131.

Quoting cargo:

    using a cfg inside a derive macro will use the cfgs from the
    destination crate and not the ones from the defining crate

In these two instances, the cfg was simply used to avoid emitting dead
code if the "complete" feature is not desired. By passing the "complete"
feature down to the derive crate and evaluating if there, we achieve the
same goal, without having to deal with suprisingly-valued and unexpected
cfgs downstream.

Alternatively, we could just remove the feature-flag and make it part of
the permanent API.
@tertsdiepraam
Copy link
Member

Closed in favor of #131. I agree with your judgment that #131 is the better option. Thanks!

@BenWiederhake BenWiederhake deleted the dev-avoid-cfg-in-derive branch April 15, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants